IFiberSocketConnection.connect_

Establishes a non-blocking socket connection according to the POSIX specification for connect():

"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. ...

When the connection has been established asynchronously, select() and poll() shall indicate that the file descriptor for the socket is ready for writing."

Calls connect_syscall, which should forward to connect() to establish a connection. If connect_syscall returns false, errno is evaluated to obtain the connection status. If it is EINPROGRESS (or EINTR, see below) the fiber is suspended so that this method returns when the socket is ready for writing or throws when a connection error was detected.

class IFiberSocketConnection
protected
connect_
(
lazy bool connect_syscall
,
bool force
)
out (status) { assert (this.connected_); assert (status); }

Parameters

connect_syscall bool

should call connect() and return true if connect() returns 0 or false otherwise

force bool

false: don't call connect_syscall if currently connected to the same address and port; true: always call connect_syscall

Return Value

- ConnectionStatus.Connected if the connection was newly established, either because connect_syscall returned true or after the socket became ready for writing, - ConnectionStatus.Connected | ConnectionStatus.Already if connect() failed with EISCONN.

Throws

- SocketError (IOException) if connect_syscall fails with an error other than EINPROGRESS/EINTR or EISCONN or if a socket error was detected, - IOWarning if the remote hung up.

Out: The socket is connected, the returned status is never Disconnected.

Note: The POSIX specification says about connect() failing with EINTR:

"If connect() is interrupted by a signal that is caught while blocked waiting to establish a connection, connect() shall fail and set errno to EINTR, but the connection request shall not be aborted, and the connection shall be established asynchronously."

It remains unclear whether a nonblocking connect() can also fail with EINTR or not. Assuming that, if it is possible, it has the same meaning as for blocking connect(), we handle EINTR in the same way as EINPROGRESS. TODO: Remove handling of EINTR or this note when this is clarified.

Meta