View Single Post
Old Aug 26th, 2005, 8:05 PM   #46
L7Sqr
Hobbyist Programmer
 
Join Date: Jun 2005
Location: here
Posts: 137
Rep Power: 0 L7Sqr is an unknown quantity at this point
Using select:
assuming you have a valid return from accept stroed in cli, you will want to set up a watch on that file descriptor.
To do that you create a variable of type fd_set, call it read (since you will be reading from it).
Provided for you are macros/functions (they could be either, you dont care) for assigning cli to read.
Call in this order:
FD_ZERO (&read); /* clear the current contents of read */
FD_SET (cli, &read); /* add cli to the fd_set read */

/* alert select that it should watch for status change in the read fd_set 
 * the three NULLs indicate: 
 * no watch on a write fd_set, 
 * no watch on an exception fd_set, 
 * no timeout  (this is a blocking call)
 */
err = select (cli + 1, &read, NULL, NULL, NULL);
/* this can return errors, check for them */

if (!(FD_ISSET(cli, &read))) {
   /* do something appropriate here */
}

/* Ok, so now select let us know that there was a change in one of the fd_sets in read
 * and we have checked to see that it is the one we are looking for
 */

/* usually you would do something like:
 * nread = recv (cli, &msg, target_read, MSG_WAITALL); 
 * at this point 
 */

That is the function of select.
Although it can be used with the timeout feature to provide a fairly decent timer function.

In response to your chat program (IM, whatever) - google around for the Windows applications of threads (I provided some links earlier in the post.
If you still cant get it, and others here cant make it clear, I'll give a last ditch effort.
Try it yourself first though, I think you might suprise yourself.
__________________
"...and though our kids are blessed their parents let them shoulder all the blame."
- The Quiet Things That No One Ever Knows [BrandNew]

Last edited by L7Sqr; Aug 26th, 2005 at 8:19 PM.
L7Sqr is offline   Reply With Quote