breaking out from socket select

前端 未结 4 1873
暖寄归人
暖寄归人 2020-12-04 02:00

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

 while(true){

    if(finished)
       return;

    switch(select(FD_SETSIZE,         


        
4条回答
  •  有刺的猬
    2020-12-04 02:24

    Yes, you create a connected pair of sockets. Then thread B writes to one side of socket and thread A adds the other side socket to select. So once B writes to socket A exits select, do not forget to read this byte from socket.

    This is the most standard and common way to interrupt selects.

    Notes:

    Under Unix, use socketpair to create a pair of sockets, under windows it is little bit tricky but googling for Windows socketpair would give you samples of code.

提交回复
热议问题