| 71 | } |
| 72 | |
| 73 | void iter() { |
| 74 | int res; |
| 75 | fd_set fdr; |
| 76 | fd_set fdw; |
| 77 | |
| 78 | // see if there are any connections to accept / write to |
| 79 | FD_ZERO(&fdr); |
| 80 | FD_ZERO(&fdw); |
| 81 | FD_SET(serverfd, &fdr); |
| 82 | if (clientfd) FD_SET(clientfd, &fdw); |
| 83 | res = select(64, &fdr, &fdw, NULL, NULL); |
| 84 | if (res == -1) { |
| 85 | perror("select failed"); |
| 86 | exit(EXIT_SUCCESS); |
| 87 | } |
| 88 | |
| 89 | if (FD_ISSET(serverfd, &fdr)) { |
| 90 | printf("accepted someone\n"); |
| 91 | clientfd = accept(serverfd, NULL, NULL); |
| 92 | assert(clientfd != -1); |
| 93 | } |
| 94 | |
| 95 | if (FD_ISSET(clientfd, &fdw)) { |
| 96 | do_send(clientfd); |
| 97 | cleanup_client(); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | int main() { |
| 102 | struct sockaddr_in addr; |