Commit 4944f01207b00cf682b4ec804ee63c1a590feea5

Authored by Grzegorz Jabłoński
1 parent a2c4be7c

Error handling

Showing 1 changed file with 10 additions and 0 deletions
epoll4.c
@@ -118,6 +118,11 @@ void server_run() { @@ -118,6 +118,11 @@ void server_run() {
118 nfds = epoll_wait(epfd, events, MAX_EVENTS, -1); 118 nfds = epoll_wait(epfd, events, MAX_EVENTS, -1);
119 } while (nfds == -1 && errno == EINTR); 119 } while (nfds == -1 && errno == EINTR);
120 120
  121 + if (nfds == -1) {
  122 + perror("epoll_wait");
  123 + exit(1);
  124 + }
  125 +
121 for (i = 0; i < nfds; i++) { 126 for (i = 0; i < nfds; i++) {
122 if (events[i].data.fd == listen_sock) { 127 if (events[i].data.fd == listen_sock) {
123 /* handle new connection */ 128 /* handle new connection */
@@ -127,6 +132,11 @@ void server_run() { @@ -127,6 +132,11 @@ void server_run() {
127 accept(listen_sock, (struct sockaddr *)&cli_addr, &socklen); 132 accept(listen_sock, (struct sockaddr *)&cli_addr, &socklen);
128 } while (conn_sock == -1 && errno == EINTR); 133 } while (conn_sock == -1 && errno == EINTR);
129 134
  135 + if (conn_sock == -1) {
  136 + perror("accept");
  137 + exit(1);
  138 + }
  139 +
130 inet_ntop(AF_INET, (char *)&(cli_addr.sin_addr), buf, sizeof(buf)); 140 inet_ntop(AF_INET, (char *)&(cli_addr.sin_addr), buf, sizeof(buf));
131 printf("[+] connected with %s:%d\n", buf, ntohs(cli_addr.sin_port)); 141 printf("[+] connected with %s:%d\n", buf, ntohs(cli_addr.sin_port));
132 142