Hi All
I want to use select() socket function with NULL timeout so that it will wait indefinitely. In such case, is there a way to make select() return? Can I add two file descriptors to select, one for network events and the other one, say, user defined events? And if yes, is there a way to set this user fd so that select() returns?
What is it you are attempting to do? select() will block until one of up to three conditions are met when using the fd_set parameters for read, write, or error; or after the timeout set in timeval has elapsed.
What is it you are attempting to do?
Nothing very fancy, I'm afraid. I want to do something like WSAWaitForMultipleEvents() (with infinite timeout) Win32 API call sort of trick with select(). I want to set fd1 and fd2 for, say, read file descriptor while fd1 would be a socket (return value of a socket() call) to get the network events and fd2 would be in my control.
Or, int other words. I know select() returns when one of the file descriptors is set by a network event. The question is, may I set this file desriptor explicitly from another thread when the original thread blocks on select() ?
What is it you are attempting to do?
Nothing very fancy, I'm afraid. I want to do something like WSAWaitForMultipleEvents() (with infinite timeout) Win32 API call sort of trick with select(). I want to set fd1 and fd2 for, say, read file descriptor while fd1 would be a socket (return value of a socket() call) to get the network events and fd2 would be in my control.
Or, int other words. I know select() returns when one of the file descriptors is set by a network event. The question is, may I set this file desriptor explicitly from another thread when the original thread blocks on select() ?
If you want your other thread which is in your control to make select call return, you can also send a signal.
Appreciate others by rating good posts
"Only buy something that you'd be perfectly happy to hold if the market shut down for 10 years." - Warren Buffett
I suppose the other thread could close or shutdown the socket which would flag the error fd_set and break out of the select() block.
I generally run an infinite loop with a reasonable timeout for the select() timeval ("reasonable" requires some experimenting), then break out of the loop once all data have been read or written.
Bookmarks