blob: 70bbcc560fa44abda0d29cea872799ccbfb56167 [file] [log] [blame]
Willy Tarreau6996e152007-04-30 14:37:43 +02001Normally, we should use getsockopt(fd, SOL_SOCKET, SO_ERROR) on a pending
2connect() to detect whether the connection correctly established or not.
3
4Unfortunately, getsockopt() does not report the status of a pending connection,
5which means that it returns 0 if the connection is still pending. This has to
6be expected, because as the name implies it, it only returns errors.
7
8With the speculative I/O, a new problem was introduced : if we pretend the
9socket was indicated as ready and we go to the socket's write() function,
10a pending connection will then inevitably be identified as established.
11
12In fact, there are solutions to this issue :
13
14 - send() returns -EAGAIN if it cannot write, so that as long as there are
15 pending data in the buffer, we'll be informed about the status of the
16 connection
17
18 - connect() on an already pending connection will return -1 with errno set to
19 one of the following values :
20 - EALREADY : connection already in progress
21 - EISCONN : connection already established
22 - anything else will indicate an error.
23
24=> So instead of using getsockopt() on a pending connection with no data, we
25 will switch to connect(). This implies that the connection address must be
26 known within the socket's write() function.
27
28