![]() |
|
|||||||
|
|
Thread Tools | Search this Thread | Rate Thread |
|
#1
|
|||
|
|||
select() fds_write and exception source code example neededhi......
Need tutorial or source code example based on how to use fds_write and fds_exception in select() function... Thanks |
|
#2
|
|||
|
|||
Re: select() fds_write and exception source code example neededQuote:
If man select() doesn't give enough information, then you can look here: Beej's network info site. (Actually that would be my first choice. I downloaded the latest version of the pdf file --- November, 2005 --- and I wouldn't even think of starting a networking project without it.) Look up select() and its parameters. If you write some code that doesn't seem to do what you want, you can post it here and describe what you are trying to do and describe what you don't understand about why it doesn't. Regards, Dave |
|
#3
|
|||
|
|||
Re: select() fds_write and exception source code example neededQuote:
Thank for reply........ I need know how to use fds_write and fds_exception in select()... The tutorial only show fds_read........... |
|
#4
|
|||
|
|||
Re: select() fds_write and exception source code example neededQuote:
So: I respectfully suggest that you write a program that calls select() with a non-NULL value for &readfds. Test it. Actually writing and testing a program (even if the fancy part id copied directly from some place else) is the best way (in my opinion) to learn. If you can't use the information you get from actually using select() with readfsd to figure out how to use writefsd, show us what you have so far. Maybe someone can help. Beej has done the "heavy lifting" (What a great effort: Thank you Beej!!!). Now it's your turn. Regards, Dave |
|
#5
|
|||
|
|||
Re: select() fds_write and exception source code example neededwell then:
CPP / C++ / C Code:
will the code above work? if yes, how to invoke fds_write and fds_exception so I'm able to see the end result... Thanks Last edited by LuciWiz : 22-Jun-2006 at 14:00.
Reason: Please insert your C code between [c] & [/c] tags
|
|
#6
|
|||
|
|||
Re: select() fds_write and exception source code example neededQuote:
Assuming that "listen" is the fd of the socket and that "write" and "exception" are fd_sets that have been associated with that socket (with FD_ZERO AND FD_SET), then the expression in the first if statement has a non-zero value ("true") if that socket can accept a "write" without blocking. The expression in the second if statement has a non-zero value if that socket has experienced an exception. Quote:
I don't know what those functions are. Regards, Dave Last edited by davekw7x : 22-Jun-2006 at 14:04.
|
|
#7
|
|||
|
|||
Re: select() fds_write and exception source code example neededQuote:
Thank for reply.... Code:
I mean anyway to test or invoke those fd_set *writefds and fd_set *exceptfds............. cause is hard to know the program is working the correct way........ another thing according to Beej's Guide to Network Programming Using Internet Sockets here: http://beej.us/guide/bgnet/output/htmlsingle/bgnet.html#select Code:
that mean we checking through " i " of sockets? Thanks |
|
#8
|
|||
|
|||
Re: select() fds_write and exception source code example neededQuote:
Quote:
Now here's the big loop: repeat 1, 2, 3 forever: 1. Does a select() and sees if there is anything to be read from any of the ports in the list of fd's(by using FD_ISSET). 2. If there is, it checks to see if this port is the "listener" port (which indicates a telnet message). If it is, then FD_SET tells it whether it is a new user (by returning a new fd that is bigger than anything in the list). New clients are added the the list by FD_SET. 3. If FD_ISSET reports something other than the "listener" port, it must be from a client, so instructions are executed to get the message from the fd who reported data available and then another loop sends the message to all of the other client fd's in the list. Voila: a chat server for telnet clients! Any message typed by a connected client is broadcast to all of the connectees. (A few more details by Beej indicate how a request for connection from a new client is detected and how the server knows when a client has closed a connection. The server maintains the list of fd's with FD_SET and FD_CLEAR.) Regards, Dave |
|
#9
|
|||
|
|||
Re: select() fds_write and exception source code example neededwell, basically I want select() to throw either write or exception file descriptor...
which means enable the program to test either: 1) if(FD_ISSET(listen, &write)) 2) if(FD_ISSET(listen, &exception)) so anyway? Thanks |
|
#10
|
|||
|
|||
Re: select() fds_write and exception source code example neededQuote:
Use of the word "exception" in this context implies one of a small number of "exceptional" events (out-of-band data received on the port, or some such thing). Note that if a telnet client quits, this does not generate an exception on its port. This is not an exceptional event; it is a normal telnet command. If you actually compile and run the Beej example you will see that the "hang up" condition is detected when the read() command returns zero bytes. (Have you done that? You really need to compile and execute ---and, I would hope, understand--- something that works before you try to go beyond the example.) I'll try to spell things out to the best of my understanding. When you call select: CPP / C++ / C Code:
it sets status bits whose states can be interrogated by FD_ISSET. Any or all of the arguments &readset, &writeset, &exceptset can be NULL (so you won't be testing that condition for any of the fd's in that set). Beej's example, as you have noted, only needs readset. If you have more than one non-null argument, then you must have different fd_sets each fd_set is created like this CPP / C++ / C Code:
and each of the fd_sets has certain fd's as members. Members are added to an fs_set with FD_SET: CPP / C++ / C Code:
If "listen" is an fd that has been added to readset (with FD_SET(listen, &readset)) Then if you execute the above select() function, you can tell whether a read from the "listen" fd can proceed without blocking. CPP / C++ / C Code:
If "listen" is an fd that has been added to writeset (with FD_SET(listen, &writeset)) Then if you execute the above select() function, you can tell whether a write to the "listen" fd can proceed without blocking: CPP / C++ / C Code:
If "listen" is an fd that has been added to exceptset (with FD_SET(listen, &exceptset)) Then if you execute the above select() function, you can tell whether there was an exceptional event on "listen" fd: CPP / C++ / C Code:
Regards, Dave |
Recent GIDBlog
Halfway done! by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The