Explain the select function call in socket programming?
vijayr 26-October-2007 05:22:07 PM

Comments


www.faqs.org/faqs/unix-faq/socket
Posted by crouse


www.hiraeth.com/alan/tutorials/courses/tcpip.html - 13k -
Posted by waqasahmad


* int status = select(nfds, &readfds, &writefds, &exceptfds, &timeout);
- status: # of ready objects, -1 if error
- nfds: 1 + largest file descriptor to check
- readfds: list of descriptors to check if read-ready
- writefds: list of descriptors to check if write-ready
- exceptfds: list of descriptors to check if an exception is registered
- timeout: time after which select returns, even if nothing ready - can be 0 or ¥
(point timeout parameter to NULL for ¥)


* Recall select uses a structure, struct fd_set
- it is just a bit-vector
- if bit i is set in [readfds, writefds, exceptfds], select will check if file descriptor (i.e. socket) i is ready for [reading, writing, exception]
* Before calling select:
- FD_ZERO(&fdvar): clears the structure
- FD_SET(i, &fdvar): to check file desc. i
* After calling select:
- int FD_ISSET(i, &fdvar): boolean returns TRUE iff i is “ready”

Posted by peter186



Posted: 26-October-2007 05:40:40 PM By: peter186

* int status = select(nfds, &readfds, &writefds, &exceptfds, &timeout);
- status: # of ready objects, -1 if error
- nfds: 1 + largest file descriptor to check
- readfds: list of descriptors to check if read-ready
- writefds: list of descriptors to check if write-ready
- exceptfds: list of descriptors to check if an exception is registered
- timeout: time after which select returns, even if nothing ready - can be 0 or ¥
(point timeout parameter to NULL for ¥)


* Recall select uses a structure, struct fd_set
- it is just a bit-vector
- if bit i is set in [readfds, writefds, exceptfds], select will check if file descriptor (i.e. socket) i is ready for [reading, writing, exception]
* Before calling select:
- FD_ZERO(&fdvar): clears the structure
- FD_SET(i, &fdvar): to check file desc. i
* After calling select:
- int FD_ISSET(i, &fdvar): boolean returns TRUE iff i is “ready”

Posted: 31-December-2008 12:08:16 AM By: waqasahmad

www.hiraeth.com/alan/tutorials/courses/tcpip.html - 13k -

Posted: 16-March-2009 04:54:48 AM By: crouse

www.faqs.org/faqs/unix-faq/socket