home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / protocol / tcpip / 5074 < prev    next >
Encoding:
Text File  |  1992-11-07  |  2.4 KB  |  90 lines

  1. Newsgroups: comp.protocols.tcp-ip
  2. Path: sparky!uunet!ftpbox!mothost!panther!panther3.panther.mot.com!ronf
  3. From: ronf@panther3.panther.mot.com (Ron Feigen)
  4. Subject: Re: Should connect() block after setting NDELAY?
  5. Message-ID: <1992Nov5.233523.7346@panther.mot.com>
  6. Sender: usenet@panther.mot.com
  7. Nntp-Posting-Host: panther3.panther.mot.com
  8. Organization: Motorola Panther Project, Chandler, AZ
  9. References: <dank.720994781@blacks>
  10. Date: Thu, 5 Nov 1992 23:35:23 GMT
  11. Lines: 77
  12.  
  13. In article <dank.720994781@blacks> dank@blacks.jpl.nasa.gov (Daniel R. Kegel) writes:
  14. >
  15. >Hi all,
  16. >I'm writing an application that opens sockets to many servers in parallel
  17. >before sending out a query to each server (also in parallel).  It sets
  18. >the sockets into nonblocking mode before the connect() as follows:
  19. >    int flags;
  20. >    #ifdef USE_FIONBIO
  21. >    flags=1;
  22. >    netioctl(qp->fds, FIONBIO, (char *)&flags);
  23. >    #else
  24. >    flags = fcntl(qp->fds, F_GETFL, 0);
  25. >    #ifdef USE_O_NDELAY
  26. >    flags |= O_NDELAY;
  27. >    #else
  28. >    flags |= FNDELAY;
  29. >    #endif
  30. >    fcntl(qp->fds, F_SETFL, &flags);
  31. >    #endif
  32. >The problem is, under SunOS 4.1.1, connect() then blocks until a 
  33. >accept, reject, or defer response comes back from the server.
  34. >This can take several seconds if the Internet is being slow.
  35. >The local Sun guy was able to see this in the source code, but does not
  36. >consider it a bug.  What do you all think- is it reasonable for connect()
  37. >to block for several seconds when the socket is supposedly in nonblocking
  38. >mode?
  39. >- Dan Kegel (dank@blacks.jpl.nasa.gov)
  40.  
  41. I use this chunk of code (SunOs 4.1) and have no problem blocking
  42.  
  43.     if ((d_ptr->fid = socket(AF_INET,SOCK_STREAM,0)) < 0)   /* make socket */
  44.     {
  45.       err_log(WARNING, ERRNO, "Making dbs socket");
  46.       continue;
  47.     }   
  48.  
  49.  
  50.     if (fcntl( d_ptr->fid, F_SETFL, FNDELAY) == -1)
  51.     {
  52.       err_log(WARNING, ERRNO, "can't set socket to non blocking");
  53.       close(d_ptr->fid);
  54.       continue;
  55.     }   
  56.  
  57.     if (fcntl( d_ptr->fid, F_SETFD, 1) == -1)
  58.     {
  59.       err_log(WARNING, ERRNO, "can't set socket to close on exec");
  60.       close(d_ptr->fid);
  61.       continue;
  62.     }   
  63.  
  64.     if(connect(d_ptr->fid,(struct sockaddr *)&sock,sizeof(sock)) == 0)
  65.     {
  66.             /* connected */
  67.       FD_SET(d_ptr->fid, write_fds);
  68.       d_ptr->status = CONNECTED;
  69.       break;
  70.     }   
  71.  
  72.  
  73.     if ( errno == EINPROGRESS )
  74.     {
  75.       FD_SET(d_ptr->fid, connect_fds);
  76.       d_ptr->status = CONNECT_PENDING;
  77.       break;
  78.     }   
  79.  
  80.         .
  81.         .
  82.         .
  83.  
  84.  
  85. -- 
  86.  
  87. >
  88. Ron Feigen
  89. ronf@panther.mot.com
  90.