[haiku-bugs] [Haiku] #13662: Subsequent connect() call shouldn't return EINPROGRESS (before the connection is established)

  • From: "korli" <trac@xxxxxxxxxxxx>
  • Date: Wed, 09 Aug 2017 06:41:20 -0000

#13662: Subsequent connect() call shouldn't return EINPROGRESS (before the
connection is established)
------------------------------------+------------------------------
 Reporter:  korli                   |        Owner:  axeld
     Type:  bug                     |       Status:  new
 Priority:  normal                  |    Milestone:  Unscheduled
Component:  Network & Internet/TCP  |      Version:  R1/Development
 Keywords:                          |   Blocked By:
 Blocking:                          |  Has a Patch:  0
 Platform:  All                     |
------------------------------------+------------------------------
 http://pubs.opengroup.org/onlinepubs/9699919799/functions/connect.html

If the connection cannot be established immediately and O_NONBLOCK is
 set for the file descriptor for the socket, connect() shall fail and set
 errno to [EINPROGRESS], but the connection request shall not be aborted,
 and the connection shall be established asynchronously. Subsequent calls
 to connect() for the same socket, before the connection is established,
 shall fail and set errno to [EALREADY].

 See issue [https://github.com/haikuports/haikuports/issues/1568 1568] at
 Haikuports for an example.

 The error code seems to originate from
 https://github.com/haiku/haiku/blob/master/src/add-
 ons/kernel/network/protocols/tcp/TCPEndpoint.cpp#L607

 {{{
         // Can only call connect() from CLOSED or LISTEN states
         // otherwise endpoint is considered already connected
         if (fState == LISTEN) {
                 // this socket is about to connect; remove pending
 connections in the backlog
                 gSocketModule->set_max_backlog(socket, 0);
         } else if (fState == ESTABLISHED) {
                 return EISCONN;
         } else if (fState != CLOSED)
                 return EINPROGRESS;

 }}}

 IMO the EINPROGRESS should be replaced with EALREADY.

--
Ticket URL: <https://dev.haiku-os.org/ticket/13662>
Haiku <https://dev.haiku-os.org>
The Haiku operating system.

Other related posts: