Date: Sat, 18 Mar 95 21:17:25 EST From: rpt@miles.sso.loral.com (Richard Toren) To: freebsd-hackers@FreeBSD.org Subject: Async 'connect's Message-ID: <9503190217.AA07453@miles.sso.loral.com>
next in thread | raw e-mail | index | archive | help
(News poster may have incomplete return mail address) Gentlemen, I am trying to program a fully non-blocking socket 'connect' function for a daemon. I can't block waiting for a timeout that may take > 60 seconds. Unfortunately, I can not find the answer to the following two questions in any manpage, Commers TCP books, nor Stevens. I am hoping a developer of socket interfaces can provide some guidance. 1> A connect with F_NDELAY is dropped into a select, the connect then fails (timeout, rejected, whatever). What will the select report back? On which side of the descriptor? 2> Assuming the select returns after a timeout with the connect sill in progress. Is there any danger in closing the socket, even though is is neither open nor closed? There is abbreviated code (error checking etc. removed): (... setup sock_addr's) s = socket(PF_INET, SOCK_STREAM, ppe->p_proto); bind(s ,(struct sockaddr*)&sin, sizeof(sin)) fcntl(s, F_SETFL, FNDELAY) if ((rc = connect(s, (struct sockaddr*)& remoteAddr, sizeof(struct sockaddr_in))) != 0) { /* rc = -1, errno = EINPROGRESS */ FD_SET (s, &readmask); FD_SET (s, &writemask); FD_SET (s, &exceptmask); nfound = select (maxfd, &readmask, &writemask, &exceptmask, NULL /*&select_delay*/); At this point, if the connect failed I find 'nfound' == 2 with both the read and write masks for 's' set. A read on 's' fails with an appropriate errno (Connection timed out). If the connect is good, 'nfound' == 1 with only the write mask set. Is this a standard behavior? Is the fact that nfound==2 significant or a tipoff? Is it set as part of an RFC? Through trying different systems at work, I have found this to be consistant on OSF/1 v3, SunOS 4.1.3, SunOS 5.3, FreeBSD 2.0R Is this portable, am I just lucky so far, or is there some ancient baseline of Socket code that everyone starts from that worked this way? Why is no 'exception' noted with a failed service? Rip Toren rpt@miles.sso.loral.com
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?9503190217.AA07453>