Non-blocking Sockets

Rich Webb rww at esl.ESL.COM
Wed Feb 7 22:15:15 AEST 1990


Howdy Wizards,
	Yet another socket question to brighten your day!  I am working
    on a network of Suns (OS4.0.3) and I am having some trouble using
    non-blocking sockets.  I am using select(2) to detect pending input
    or output capability on a large number of sockets simultaneously.
    I have most of this working: new input is detected, new sockets are
    established whenever anyone tries to connect to my "listening" port,
    and I am notified when I can write out data on a socket.  All of
    my sockets are marked as FNDELAY.

	My problem is when I am trying to connect(2) to a remote system.
    I create the socket (socket(2)), I call fcntl(2) with FNDELAY, then
    I call connect(2) with the socket and "server" loaded with the
    destination host address.  I get EINPROGRESS as expected, then add
    this socket to my list of write file descriptors that I select(2) for.
    I actually get notified correctly if the connection succeeds (I
    try to connect again on this socket and get EISCONN).  But select(2)
    also notifies me if the connection fails (almost immediately, no
    apparent timeout, trying to connect(2) again gives EINVAL).

	Shouldn't I be informed of the cause of the failed connection?
    How can I find out why it failed?  The machines are adjacent on a
    sparsely utilized Ethernet, so maybe TCP is determining that the
    destination machine/port pair is not active and so TCP closes the
    connection (if I do a blocking connect(2), I get ECONNREFUSED).
    Can I determine this type of failure directly, or must I infer it?
    Can I have the connect(2) request remain active for a certain period
    of time?

	Thanks for any input you can provide.  I looked through some
    TCP/IP networking books and the Introductory BSD 4.3 IPC Tutorial
    and the Advanced BSD 4.3 IPC Tutorial.  FNDELAY is mentioned, even
    in the context of connect(2) and select(2), but no mention is made
    of error detection and recovery.  ("And at these prices, I'm not
    surprised!")

	Anyway, I will summarize if there are any interesting responses.

		Thanks again.




-- 
Richard W. Webb
ESL Inc.  MS/302
495 Java Drive           (408) 738-2888 x5729
Sunnyvale, CA  94088     EMAIL: rww at esl.ESL.COM, ames!esl!rww



More information about the Comp.unix.wizards mailing list