connect

Utility function to connect a socket that is managed by a TaskSelectTransceiver.

Calls socket_connect once. If it returns false, evaluates errno and waits for establishing the connection to complete if needed, suspending the task.

When calling socket_connect the I/O device which was passed to the constructor of tst is passed to it via the socket parameter. socket_connect should call the POSIX connect function, passing socket.fileHandle, and return true on success or false on failure, corresponding to connect returning 0 or -1, respectively.

If socket_connect returns true then this method does nothing but returning 0. Otherwise, if socket_connect returns false then it does one of the following actions depending on errno: - EINPROGRESS, EALREADY, EINTR: Wait for establishing the connection to complete, then return errno. - EISCONN, 0: Return errno (and do nothing else). - All other codes: Throw IOError.

The Socket type must to be chosen so that the I/O device passed to the constructor can be cast to it.

int
connect
(
Socket : IODevice
)
(,
scope bool delegate
(
Socket socket
)
socket_connect
)

Parameters

tst TaskSelectTransceiver

the TaskSelectTransceiver instance that manages the socket to connect

socket_connect bool delegate
(
Socket socket
)

calls POSIX connect

Return Value

Type: int

- 0 if socket_connect returned true, - or the initial errno code otherwise, if the socket is now connected.

Throws

IOError if socket_connect returned false and errno indicated that the socket connection cannot be established.

Meta