Results 1 to 5 of 5
Hi all, when using the select can anyone tell what the writefds used for....
- 03-23-2010 #1Just Joined!
- Join Date
- Oct 2009
- Posts
- 85
select call, writefd
Hi all, when using the select can anyone tell what the writefds used for.
- 03-23-2010 #2
Nope, this is too cryptic. You're going to have to give us a little more information if you want help.
Is this an SQL select? What are you trying to achieve?Linux user #126863 - see http://linuxcounter.net/
- 03-23-2010 #3Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
From the select(2) man page:
Code:Three independent sets of file descriptors are watched. Those listed in readfds will be watched to see if characters become available for reading (more precisely, to see if a read will not block; in particular, a file descriptor is also ready on end-of-file), those in writefds will be watched to see if a write will not block, and those in exceptfds will be watched for exceptions. On exit, the sets are mod- ified in place to indicate which file descriptors actually changed status. Each of the three file descriptor sets may be specified as NULL if no file descriptors are to be watched for the corresponding class of events.Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 03-24-2010 #4Just Joined!
- Join Date
- Oct 2009
- Posts
- 85
thanks for the reply Rubberman, I have gone through this.. but my intention is to make a function for non-blocking connect call in socket i.e., I want to connect to a socket at an IP, if the IP address is not present and if I connect , my aplication is blocked at the connect call for some time(say 30secs). But I dont want it to happen like this. I want to check only say 2secs and give me an error message.
Can I do this stuff like this :
1. Change the socket to non-blocking
2. Connect to the IP Address
3. Then check the socket with select, by adding this fd in the write fds.
Please can you help with this problem, this will be of grt help to me.
- 03-24-2010 #5Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
1. You can set an itimer w/ 2 second timeout before attempting to connect, then check the return from connect call to see if you got an EINTR errno.
2. You can do what you suggested. According to the connect() man page, what you suggest is acceptable and should work. From the connect(2) man page for a connect() call on a non-blocking socked which returns errno == EINPROGRESS:
As for help doing this, reading the appropriate man pages should get you sorted out. Also, if you are going to do a lot of client/server programming, you should probably invest in Comer and Stevens Internetworking with TCP/IP, Vol. III, the BSD Socket Version.Code:EINPROGRESS The socket is non-blocking and the connection cannot be completed immedi- ately. It is possible to select(2) or poll(2) for completion by selecting the socket for writing. After select(2) indicates writability, use getsock- opt(2) to read the SO_ERROR option at level SOL_SOCKET to determine whether connect() completed successfully (SO_ERROR is zero) or unsuccessfully (SO_ERROR is one of the usual error codes listed here, explaining the rea- son for the failure).Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!


Reply With Quote