- /* initialize all needed variables */
+...
poll_set = (struct pollfd *) malloc(n * sizeof(struct pollfd));
max_fd = list_fd; /* maximum now is listening socket */
- for (i=0; i<n; i++) {
+ for (i=0; i<n; i++) { /* initialize poll set */
poll_set[i].fd = -1;
poll_set[i].events = POLLRDNORM;
}
- poll_set[max_fd].fd = list_fd;
- /* main loop, wait for connection and data inside a select */
- while (1) {
- while ( ((n = poll(poll_set, max_fd + 1, -1)) < 0)
- && (errno == EINTR)); /* wait for data or connection */
+ poll_set[max_fd].fd = list_fd;
+ while (1) { /* main loop, wait for connection and data inside a poll */
+ while ( ((n=poll(poll_set, max_fd + 1, -1)) < 0) && (errno == EINTR));
if (n < 0) { /* on real error exit */
PrintErr("poll error");
exit(1);
}
}
}
- exit(0); /* normal exit, never reached */
+...