If the listening socket signaled there is a new connection ready to * be accepted, we accept(2) it and return -1 on error or the new client * socket on success. */
| 112 | * be accepted, we accept(2) it and return -1 on error or the new client |
| 113 | * socket on success. */ |
| 114 | int acceptClient(int server_socket) { |
| 115 | int s; |
| 116 | |
| 117 | while(1) { |
| 118 | struct sockaddr_in sa; |
| 119 | socklen_t slen = sizeof(sa); |
| 120 | s = accept(server_socket,(struct sockaddr*)&sa,&slen); |
| 121 | if (s == -1) { |
| 122 | if (errno == EINTR) |
| 123 | continue; /* Try again. */ |
| 124 | else |
| 125 | return -1; |
| 126 | } |
| 127 | break; |
| 128 | } |
| 129 | return s; |
| 130 | } |
| 131 | |
| 132 | /* We also define an allocator that always crashes on out of memory: you |
| 133 | * will discover that in most programs designed to run for a long time, that |