breaking out from socket select

Posted by kamziro on Stack Overflow See other posts from Stack Overflow or by kamziro
Published on 2010-03-21T10:37:32Z Indexed on 2010/03/21 10:41 UTC
Read the original article Hit count: 234

Filed under:
|
|

I have a loop which basically calls this every few seconds (after the timeout):

 while(true){

    if(finished)
       return;

    switch(select(FD_SETSIZE, &readfds, 0, 0, &tv)){
        case SOCKET_ERROR : report bad stuff etc; return;
        default : break;
    }

    // do stuff with the incoming connection
 }

So basically for every few seconds (which is specified by tv), it reactivates the listening.

This is run on thread B (not a main thread). There are times when I want to end this acceptor loop immediately from thread A (main thread), but seems like I have to wait until the time interval finishes..

Is there a way to disrupt the select function from another thread so thread B can quit instantly?

© Stack Overflow or respective owner

Related posts about sockets

Related posts about c