+ int num_active = epoll_wait(ep_fd, events, epoll_room_in_receiver, -1);
+ if (num_active == -1) {
+ if (errno == EINTR)
+ continue;
+ perror("epoll_wait");
+ exit(1);
+ }
+
+ for (i = 0; i < num_active; ++i) {
+ int sock = events[i].data.fd;
+ int ret;
+ if (sock == server_sock) {
+ struct sockaddr_in addr;
+ int sock;
+ socklen_t addr_len = sizeof(addr);
+
+ sock = accept(server_sock, (struct sockaddr *)&addr, &addr_len);
+ if (sock == -1) {
+ if (errno == EAGAIN || errno == EINTR) {
+ // another thread snatched it, ignore
+ continue;
+ } else {
+ perror("accept()");
+ exit(1);
+ }
+ }
+
+ // add it to the epoll set
+ ev.events = EPOLLIN | EPOLLHUP | EPOLLERR;
+ ev.data.fd = sock;