From 2f633f1f29620fcfa3b4dadc2f391abf4dee619b Mon Sep 17 00:00:00 2001 From: ha7ilm Date: Thu, 12 Jan 2017 23:32:45 +0100 Subject: [PATCH] nmux: hacking around select --- nmux.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/nmux.cpp b/nmux.cpp index 4588cb9..b0a369c 100644 --- a/nmux.cpp +++ b/nmux.cpp @@ -181,12 +181,15 @@ int main(int argc, char* argv[]) { if(NMUX_DEBUG) fprintf(stderr, "mainfor: selecting..."); //Let's wait until there is any new data to read, or any new connection! - select(highfd, &select_fds, NULL, NULL, NULL); + int select_num = select(highfd, &select_fds, NULL, NULL, NULL); if(NMUX_DEBUG) fprintf(stderr, "selected.\n"); + if(select_num == -1) error_exit("mainfor select() error"); + //Is there a new client connection? if( (new_socket = accept(listen_socket, (struct sockaddr*)&addr_cli, &addr_cli_len)) != -1) { + select_num--; if(NMUX_DEBUG) fprintf(stderr, "mainfor: accepted (socket = %d).\n", new_socket); //Close all finished clients for(int i=0;i= bufsize) { if(NMUX_DEBUG) fprintf(stderr, "mainfor: gwbing...");