Socket Programming making use of "select()" and "writefds"
Hello Linux professionals,
Most of the Unix socket tutorial available out there, which I found regrading the select() function emphasis on readfds (read file description set) and they did not mention much about writefds (write file description set) and exceptfds (exception file description set). So here is my question: What makes select() function to return a "write" file description set value?, basically it means that the select() function will enter a description set value into writefds variable. I did find some tutorials: http://rhoden.id.au/doc/sockets2.html http://olympus.het.brown.edu/cgi-bin...l?2+select_tut based on the tutorials and from my point of understanding, usually the "writefds" is triggered by the programmer rather than "select()" function. This means that the programmer have to manually trigger the "writefds" rather than the OS or "select()" function triggering the "writefds". So, is there any simple program in C programming language, such chat, telnet, web server or etc, that utilize "select()" and "writefds" that can help me to understand better about logic or structure of "selec()" function and "writefds"? Thanks |
I have a little difficulty understanding you post but...
What makes select() function to return a "write" file description set value?, basically it means that the select() function will enter a description set value into writefds variable. writefds is simply a socket which can be written to. So if you had 10 handles and five needed to be written to you may enter the five into a fdset, check them getting the number which can be written to and a set back. Then you would check each of the five handles with the set, if its present then write to the socket. This means that the programmer have to manually trigger the "writefds" rather than the OS or "select()" function triggering the "writefds". I'm not sure I fully understand you, it really doesn't make much sense to check all sockets to see if they are writeable unless you have data to write to the socket. Personally I have not had much need to use the write functionality of select |
Well do you guys have any working examples that teaches me how to utilize the select() function with writefds?
|
I just wanted to post this page.
http://linux.die.net/man/2/select_tut It looks as if they used FD_ISSET to check if select has done anything with the fd sets presented. Code:
for (i > 0; i < fdmax+1; i++) // Iterate through all available sockets |
I think your question can be re-phrased as 'What makes a socket have some readiness for writing?'. In most cases, such as sockets open for writing to IP connections, you can write arbitrarily, and the buffering in the network stack will prevent 'overflow' or any condition that would prevent more data from being written. Some devices may have a limit to how much data can be written before they become 'full'.
I cannot think of any example of such a case, but I feel certain that something must exist. I can give an analogous description, though: message queues. These have a finite size, and once full, cannot accept any more data. The analogy breaks down in that one does not use sockets to write or read them; they have their own API for access. Another analogy would be the Tx buffer in a UART (serial port hardware). Most UARTs have a finite number of bytes which they are capable of queuing for transmission, sometimes only one or two. They signal the controlling software that they can accept more data when the Tx buffer is either non-full or is empty. Again, the analogy breaks down, as the device driver handles buffering for userspace applications. In my experience, it is not uncommon for userspace applications to completely ignore the use of select() to signal readiness to write to sockets. select() is used to manage handling of asynchronous input, and output is simply done whenever the need arises. --- rod. |
Quote:
select for "write" should be the same as that for "read":
Kevin Barry |
Quote:
Kevin Barry |
I wonder if johncsl82 still needs it after 4 years ;)
Might be useful for others in future :) |
Quote:
Kevin Barry PS Maybe johncsl82 has been diligently waiting, like the child-robot in the movie A.I. |
Quote:
|
ta0kira: Your answer was not in vain, it helped me clear up the meaning of writefds. Furthermore is this post the top result on Google when searching for "select writefds", so I don't think I am the only one searching for this and benefitting of a nice explanation.
|
All times are GMT -5. The time now is 07:23 PM. |