Commit 0fa57cc345bccf4ca409945e7bcdbd807c7f2de4

Authored by Grzegorz Jabłoński
1 parent 7fac6064

More EINTR checking

Showing 1 changed file with 11 additions and 3 deletions
epoll4.c
... ... @@ -116,11 +116,18 @@ void server_run() {
116 116  
117 117 socklen = sizeof(cli_addr);
118 118 for (;;) {
119   - nfds = epoll_wait(epfd, events, MAX_EVENTS, -1);
  119 + do {
  120 + nfds = epoll_wait(epfd, events, MAX_EVENTS, -1);
  121 + } while (nfds == -1 && errno == EINTR);
  122 +
120 123 for (i = 0; i < nfds; i++) {
121 124 if (events[i].data.fd == listen_sock) {
122 125 /* handle new connection */
123   - conn_sock = accept(listen_sock, (struct sockaddr *)&cli_addr, &socklen);
  126 +
  127 + do {
  128 + conn_sock =
  129 + accept(listen_sock, (struct sockaddr *)&cli_addr, &socklen);
  130 + } while (conn_sock == -1 && errno == EINTR);
124 131  
125 132 inet_ntop(AF_INET, (char *)&(cli_addr.sin_addr), buf, sizeof(buf));
126 133 printf("[+] connected with %s:%d\n", buf, ntohs(cli_addr.sin_port));
... ... @@ -142,7 +149,8 @@ void server_run() {
142 149 printf("[+] data: %s\n", buf);
143 150 n = 0;
144 151 while (n != strlen(buf)) {
145   - int rv = send(events[i].data.fd, buf + n, strlen(buf) - n, MSG_NOSIGNAL);
  152 + int rv = send(events[i].data.fd, buf + n, strlen(buf) - n,
  153 + MSG_NOSIGNAL);
146 154 if (rv == -1 && (errno == EAGAIN || errno == EWOULDBLOCK))
147 155 continue; // FIXME: busy waiting - should wait using epoll
148 156 if (rv == -1)
... ...