home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.protocols.tcp-ip
- Path: sparky!uunet!ftpbox!mothost!panther!panther3.panther.mot.com!ronf
- From: ronf@panther3.panther.mot.com (Ron Feigen)
- Subject: Re: Should connect() block after setting NDELAY?
- Message-ID: <1992Nov5.233523.7346@panther.mot.com>
- Sender: usenet@panther.mot.com
- Nntp-Posting-Host: panther3.panther.mot.com
- Organization: Motorola Panther Project, Chandler, AZ
- References: <dank.720994781@blacks>
- Date: Thu, 5 Nov 1992 23:35:23 GMT
- Lines: 77
-
- In article <dank.720994781@blacks> dank@blacks.jpl.nasa.gov (Daniel R. Kegel) writes:
- >
- >Hi all,
- >I'm writing an application that opens sockets to many servers in parallel
- >before sending out a query to each server (also in parallel). It sets
- >the sockets into nonblocking mode before the connect() as follows:
- > int flags;
- > #ifdef USE_FIONBIO
- > flags=1;
- > netioctl(qp->fds, FIONBIO, (char *)&flags);
- > #else
- > flags = fcntl(qp->fds, F_GETFL, 0);
- > #ifdef USE_O_NDELAY
- > flags |= O_NDELAY;
- > #else
- > flags |= FNDELAY;
- > #endif
- > fcntl(qp->fds, F_SETFL, &flags);
- > #endif
- >The problem is, under SunOS 4.1.1, connect() then blocks until a
- >accept, reject, or defer response comes back from the server.
- >This can take several seconds if the Internet is being slow.
- >The local Sun guy was able to see this in the source code, but does not
- >consider it a bug. What do you all think- is it reasonable for connect()
- >to block for several seconds when the socket is supposedly in nonblocking
- >mode?
- >- Dan Kegel (dank@blacks.jpl.nasa.gov)
-
- I use this chunk of code (SunOs 4.1) and have no problem blocking
-
- if ((d_ptr->fid = socket(AF_INET,SOCK_STREAM,0)) < 0) /* make socket */
- {
- err_log(WARNING, ERRNO, "Making dbs socket");
- continue;
- }
-
-
- if (fcntl( d_ptr->fid, F_SETFL, FNDELAY) == -1)
- {
- err_log(WARNING, ERRNO, "can't set socket to non blocking");
- close(d_ptr->fid);
- continue;
- }
-
- if (fcntl( d_ptr->fid, F_SETFD, 1) == -1)
- {
- err_log(WARNING, ERRNO, "can't set socket to close on exec");
- close(d_ptr->fid);
- continue;
- }
-
- if(connect(d_ptr->fid,(struct sockaddr *)&sock,sizeof(sock)) == 0)
- {
- /* connected */
- FD_SET(d_ptr->fid, write_fds);
- d_ptr->status = CONNECTED;
- break;
- }
-
-
- if ( errno == EINPROGRESS )
- {
- FD_SET(d_ptr->fid, connect_fds);
- d_ptr->status = CONNECT_PENDING;
- break;
- }
-
- .
- .
- .
-
-
- --
-
- >
- Ron Feigen
- ronf@panther.mot.com
-