-
March 28th, 2010, 02:03 PM
#1
Make select() return
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?
-
March 28th, 2010, 09:40 PM
#2
Re: Make select() return
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.
-
March 28th, 2010, 10:03 PM
#3
Re: Make select() return
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() ?
-
April 11th, 2010, 07:39 AM
#4
Re: Make select() return
Originally Posted by stolencoin
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
-
March 29th, 2010, 07:25 AM
#5
Re: Make select() return
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.
-
March 29th, 2010, 11:16 AM
#6
Re: Make select() return
Thanks hoxsiew, I'll try what you suggested.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|