Hacker News new | ask | show | jobs
by alexgartrell 5812 days ago
I think the answer is actually pretty straightforward. It's trivial to go from a serial to a threaded server. It's way harder to write an event-based server using poll or select.

Serially:

  int handle_connection(int fd) {
    ...
  }

  int loop() {
    ...
    while(1) {
      fd = accept(listener);
      handle_connection(fd);
    }
  }
Threaded:

  int handle_connection(int fd) {
    ...
  }

  int loop() {
    ...
    while(1) {
      fd = accept(listener);
      thread_start(handle_connection, fd);
    }
  }
1 comments

No its not. Using your contrived limited example its even less code.

Evented:

  int handle_connection(int fd) {
    ...
  }

  int doaccept() {
      put_on_event_loop(accept(listener));
  }