Click to See Complete Forum and Search --> : Make select() return
stolencoin
March 28th, 2010, 02:03 PM
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?
hoxsiew
March 28th, 2010, 09:40 PM
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.
stolencoin
March 28th, 2010, 10:03 PM
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() ?
hoxsiew
March 29th, 2010, 07:25 AM
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.
stolencoin
March 29th, 2010, 11:16 AM
Thanks hoxsiew, I'll try what you suggested.
sunnypalsingh
April 11th, 2010, 07:39 AM
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.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.