nmux: hacking around select
This commit is contained in:
parent
da13229456
commit
2f633f1f29
1 changed files with 5 additions and 1 deletions
6
nmux.cpp
6
nmux.cpp
|
@ -181,12 +181,15 @@ int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
if(NMUX_DEBUG) fprintf(stderr, "mainfor: selecting...");
|
if(NMUX_DEBUG) fprintf(stderr, "mainfor: selecting...");
|
||||||
//Let's wait until there is any new data to read, or any new connection!
|
//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(NMUX_DEBUG) fprintf(stderr, "selected.\n");
|
||||||
|
|
||||||
|
if(select_num == -1) error_exit("mainfor select() error");
|
||||||
|
|
||||||
//Is there a new client connection?
|
//Is there a new client connection?
|
||||||
if( (new_socket = accept(listen_socket, (struct sockaddr*)&addr_cli, &addr_cli_len)) != -1)
|
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);
|
if(NMUX_DEBUG) fprintf(stderr, "mainfor: accepted (socket = %d).\n", new_socket);
|
||||||
//Close all finished clients
|
//Close all finished clients
|
||||||
for(int i=0;i<clients.size();i++)
|
for(int i=0;i<clients.size();i++)
|
||||||
|
@ -221,6 +224,7 @@ int main(int argc, char* argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!select_num) continue;
|
||||||
if(index_in_current_write_buffer >= bufsize)
|
if(index_in_current_write_buffer >= bufsize)
|
||||||
{
|
{
|
||||||
if(NMUX_DEBUG) fprintf(stderr, "mainfor: gwbing...");
|
if(NMUX_DEBUG) fprintf(stderr, "mainfor: gwbing...");
|
||||||
|
|
Loading…
Reference in a new issue