/* * Handle poll(...) completion. * Return @true if any event was processed, * @false otherwise. */ bool rcmd_handle_pollfds(struct pollfd* pollfds) { struct pollfd* pollfd; int nfds = svc_max_pollfd; int k, fd; struct sockaddr_un addr; socklen_t addrlen = sizeof addr; bool res = false; /* any events on RPC connection sockets? */ for (k = 0; k < nfds; k++) { if (pollfds[k].revents && pollfds[k].fd != -1) res = true; } /* handle events on RPC connection sockets */ if (res) { debug_msg(40, "calling svc_getreq_poll"); svc_getreq_poll(pollfds, nfds); debug_msg(40, "finished svc_getreq_poll"); } /* handle events (if any) on the listener socket */ if (sock != -1) { pollfd = pollfds + nfds; if (pollfd->revents & pollfd->events) { res = true; debug_msg(12, "accepting RPC connection"); DO_RESTARTABLE(fd, accept(sock, (struct sockaddr*) &addr, &addrlen)); if (fd == -1) { error_perror("unable to accept RPC connection"); } else { debug_msg(12, "accepted RPC connection"); SVCXPRT* transp = svcunixfd_create(fd, 0, 0); if (transp == NULL) { error_msg("unable to accept RPC connection (svcunixfd_create failed)"); close(fd); } } } } return res; }
void svc_run (void) { int i; struct pollfd *my_pollfd = NULL; int last_max_pollfd = 0; for (;;) { int max_pollfd = svc_max_pollfd; if (max_pollfd == 0 && svc_pollfd == NULL) break; if (last_max_pollfd != max_pollfd) { struct pollfd *new_pollfd = realloc (my_pollfd, sizeof (struct pollfd) * max_pollfd); if (new_pollfd == NULL) { perror (_("svc_run: - out of memory")); break; } my_pollfd = new_pollfd; last_max_pollfd = max_pollfd; } for (i = 0; i < max_pollfd; ++i) { my_pollfd[i].fd = svc_pollfd[i].fd; my_pollfd[i].events = svc_pollfd[i].events; my_pollfd[i].revents = 0; } switch (i = __poll (my_pollfd, max_pollfd, -1)) { case -1: if (errno == EINTR) continue; perror (_("svc_run: - poll failed")); break; case 0: continue; default: svc_getreq_poll (my_pollfd, i); continue; } break; } free (my_pollfd); }
void svc_run (void) { int i; for (;;) { struct pollfd *my_pollfd; if (svc_max_pollfd == 0 && svc_pollfd == NULL) return; my_pollfd = malloc (sizeof (struct pollfd) * svc_max_pollfd); for (i = 0; i < svc_max_pollfd; ++i) { my_pollfd[i].fd = svc_pollfd[i].fd; my_pollfd[i].events = svc_pollfd[i].events; my_pollfd[i].revents = 0; } switch (i = poll (my_pollfd, svc_max_pollfd, -1)) { case -1: free (my_pollfd); if (errno == EINTR) continue; perror (_("svc_run: - poll failed")); return; case 0: free (my_pollfd); continue; default: svc_getreq_poll (my_pollfd, i); free (my_pollfd); } } }
static void my_svc_run(void) { struct pollfd *pfd = NULL, *newp; int nready, saved_max_pollfd = 0; for (;;) { if (svc_max_pollfd > saved_max_pollfd) { newp = realloc(pfd, sizeof(*pfd) * svc_max_pollfd); if (newp == NULL) { free(pfd); perror("svc_run: - realloc failed"); return; } pfd = newp; saved_max_pollfd = svc_max_pollfd; } memcpy(pfd, svc_pollfd, sizeof(*pfd) * svc_max_pollfd); nready = poll(pfd, svc_max_pollfd, 60 * 1000); switch (nready) { case -1: if (errno == EINTR) continue; perror("yppush: my_svc_run: poll failed"); free(pfd); return; case 0: fprintf(stderr, "yppush: Callback timed out.\n"); exit(0); default: svc_getreq_poll(pfd, nready); free(pfd); break; } } }