Embedded TCP/IP stack  4.7.0

◆ fnet_socket_connect()

fnet_return_t fnet_socket_connect ( fnet_socket_t  s,
struct fnet_sockaddr name,
fnet_size_t  namelen 
)

Establishes a connection with the specified socket.

Parameters
sDescriptor identifying an unconnected socket.
nameAddress (name) of the socket, with which the connection should be established.
namelenLength of the name.
Returns
This function returns:
See also
fnet_socket(), fnet_socket_bind()

For connection-oriented sockets (SOCK_STREAM), this function activates an active connection with the foreign host.

When the socket call completes successfully, the socket is ready to send and receive data. Any attempt to reconnect the active connection will fail with the error code FNET_ERR_ISCONN. For connection-oriented sockets, it is often not possible to complete the connection immediately. Until the connection attempt completes on a socket, all subsequent calls to fnet_socket_connect() on the same socket will fail with the error code FNET_ERR_INPROGRESS, or succeed with FNET_ERR_ISCONN when the connection completes successfully. Use the fnet_socket_getopt() function to determine the completion of the connection request by checking the SO_STATE to see if the socket is connected (SS_CONNECTED), is still connecting (SS_CONNECTING) or the connection has failed (SS_CLOSED).

For a connectionless socket (SOCK_DGRAM), the operation performed by fnet_socket_connect() is merely to establish a default destination address that can be used on subsequent fnet_socket_send() and fnet_socket_recv() calls. Any datagrams received from an address other than the destination address specified will be discarded. The default destination can be changed by simply calling the fnet_socket_connect() again, even if the socket is connected already. Any datagrams queued for receipt are discarded from the previous fnet_socket_connect(). For connectionless sockets, the name can indicate any valid address, including a broadcast address.

If the socket s is unbound, unique values are assigned to the local association by the stack, and the socket is marked as bound.


© 2005-2020 by Andrej Butok. http://fnet.sourceforge.net