Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 30 Mar 1997 18:28:57 BST
From:      Michael Searle <searle@longacre.demon.co.uk>
To:        questions@freebsd.org
Subject:   Problem with select()
Message-ID:  <m731106DD@longacre.demon.co.uk>

next in thread | raw e-mail | index | archive | help
Please could someone point me in the right direction here? As far as I can
see I'm doing as the accept() and select() man pages say, and the same as
the ftp client does.

I'm writing an Internet server, with a blocking socket. In two places
though, I need to do a non-blocking read from it as it is reading from other
clients at the same time. In the first, it is checking for a new client, so
I am selecting on read (to check whether I can call accept() without
blocking.) The other is similar, but the sockets are already open - it's
just a normal select on read.

Without the select, it works OK, but blocks until a client connects - as
expected. With it, the select never returns 1 so it never gets to being able
to accept the client. These are the relevant bits of code:

struct fd_set sel;
struct fd_set ready;
struct timeval timezero;
<snip>
timezero.tv_sec = 0; timezero.tv_usec = 0;
<snip>
serverFd = socket(AF_INET, SOCK_STREAM, DEFAULT_PROTOCOL);
<snip>
FD_ZERO(&sel);
FD_SET(serverFd, &sel);
<snip>
bind (serverFd, serverSockAddrPtr, serverLen);
listen (serverFd, 2);
<snip>
while (1) {
<snip>
   if (select(1, &sel, (struct fd_set *) 0, (struct fd_set *) 0, &timezero) == 1) {
     fprintf(stderr,"select OK\n");
      newFd = accept (serverFd, clientSockAddrPtr, &clientLen);
      fprintf(stderr,"accept OK\n");
<snip>
for(y=0;y<nextclient;y++) {
   FD_ZERO(&ready);
   FD_SET(clientFd[y], &ready);
   if (select(1, &ready, (struct fd_set *) 0, (struct fd_set *) 0, &timezero) == 1) {
      <snip>
      }
   }

Thanks, Michael.



-- 
Michael Searle - searle@longacre.demon.co.uk



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?m731106DD>