diff options
Diffstat (limited to 'vxi11_svc.c')
-rw-r--r-- | vxi11_svc.c | 55 |
1 files changed, 53 insertions, 2 deletions
diff --git a/vxi11_svc.c b/vxi11_svc.c index edc4212..e5c4b38 100644 --- a/vxi11_svc.c +++ b/vxi11_svc.c @@ -1,12 +1,18 @@ +#define _GNU_SOURCE + #include "vxi11.h" +#include "vxi11_server.h" #include <stdio.h> #include <stdlib.h> #include <rpc/pmap_clnt.h> #include <string.h> #include <memory.h> +#include <poll.h> #include <sys/socket.h> #include <netinet/in.h> +#define VXI11_DEFAULT_TIMEOUT 1000 + #ifndef SIG_PF #define SIG_PF void(*)(int) #endif @@ -223,6 +229,51 @@ void vxi_main() { exit(1); } - svc_run(); - fprintf(stderr, "%s", "svc_run returned"); + int i, j; + struct pollfd *my_pollfd = NULL; + int last_max_pollfd = 0; + + while (1) { + 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) { + 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 | POLLRDHUP; // add the "socket is dead" event + my_pollfd[i].revents = 0; + } + + j = poll(my_pollfd, max_pollfd, VXI11_DEFAULT_TIMEOUT); + + for (i = 0; i < max_pollfd; i++) { + if (my_pollfd[i].revents & POLLRDHUP) + vxi11_deadsocketcallback(my_pollfd[i].fd); + } + + switch (j) { + case -1: + break; + case 0: + continue; + default: + svc_getreq_poll(my_pollfd, i); + continue; + } + break; + } + + //svc_run(); + //fprintf(stderr, "%s", "svc_run returned"); } |