Method _Stdio.Fd()->connect()


Method connect

int(-1..1) connect(string(8bit) dest_addr, int dest_port)
int(-1..1) connect(string(8bit) dest_addr, int dest_port, string(8bit) src_addr, int src_port)
string(8bit)|int(-1..0) connect(string(8bit) dest_addr, int dest_port, string(8bit)|void src_addr, int|void src_port, string(8bit) data)

Description

Open a TCP/IP connection to the specified destination.

In nonblocking mode, success is indicated with the write-callback, and failure with the close-callback or the read_oob-callback.

If the data argument is included the socket will use TCP_FAST_OPEN if available, if not the data will not be sent. In the data case the function either returns the data that has not been sent (only one packet can be sent with this option) or 0 if the connection failed immediately.

Returns

Returns one of

string(8bit)

data that did not fit into the initial connection packet. Note that the connection may not have been established yet.

int(0)

Returns 0 on (synchronous) connection failure.

int(1)

Returns 1 if there was no data to send.

int(-1)

Returns -1 if the connection has not yet been established. Use eg poke() or query_address() to wait or check for when the connection completes.

Note

Note that in versions of Pike prior to 9.0 1 was returned also in the not yet established case.

Note that -1 may be returned also for sockets in blocking mode if the connect(3N) system call was interrupted.

See also

open_socket(), poke()