sock/tcp.h¶
TCP sock definitions.
-
struct _sock_tl_ep
sock_tcp_ep_t¶ An end point for a TCP sock object.
-
struct sock_tcp
sock_tcp_t¶ Type for a TCP sock object.
Note
API implementors:
struct sock_tcpneeds to be defined by implementation-specificsock_types.h.
-
struct sock_tcp_queue
sock_tcp_queue_t¶ Type for a TCP listening queue.
Note
API implementors:
struct sock_tcp_queueneeds to be defined by implementation-specificsock_types.h.
-
int
sock_tcp_connect(sock/tcp.h::sock_tcp_t* sock, constsock/tcp.h::sock_tcp_ep_t* remote, uint16_t local_port, uint16_t flags)¶ Establishes a new TCP sock connection.
Parameters
Return values
- 0 on success.
- -EADDRINUSE, if
(flags & SOCK_FLAGS_REUSE_EP) == 0andlocal_portis already used elsewhere - -EAFNOSUPPORT, if
sock.h::_sock_tl_ep::familyofremoteis not supported. - -ECONNREFUSED, if no-one is listening on the
remoteend point. - -EINVAL, if
sock.h::_sock_tl_ep::addrofremoteis an invalid address. - -EINVAL, if
sock.h::_sock_tl_ep::netifofremoteis not a valid interface. - -ENETUNREACH, if network defined by
remoteis not reachable. - -ENOMEM, if system was not able to allocate sufficient memory to establish connection.
- -EPERM, if connections to
remoteare not permitted on the system (e.g. by firewall rules). - -ETIMEDOUT, if the connection attempt to
remotetimed out.
-
int
sock_tcp_listen(sock/tcp.h::sock_tcp_queue_t* queue, constsock/tcp.h::sock_tcp_ep_t* local,sock/tcp.h::sock_tcp_t* queue_array, unsigned queue_len, uint16_t flags)¶ Listen for an incoming connection request on
localend point.Parameters
queue: The resulting listening queue. local: Local end point to listen on. queue_array: Array of sock objects. queue_len: Length of queue_array.flags: Flags for the listening queue. See also . May be 0. Return values
- 0 on success.
- -EADDRINUSE, if
(flags & SOCK_FLAGS_REUSE_EP) == 0andlocalis already used elsewhere - -EAFNOSUPPORT, if
sock.h::_sock_tl_ep::familyoflocalis not supported. - -EINVAL, if
sock.h::_sock_tl_ep::netifoflocalis not a valid interface. - -ENOMEM, if no memory was available to listen on
queue.
-
void
sock_tcp_disconnect(sock/tcp.h::sock_tcp_t* sock)¶ Disconnects a TCP connection.
Parameters
sock: A TCP sock object.
-
void
sock_tcp_stop_listen(sock/tcp.h::sock_tcp_queue_t* queue)¶ Stops listening on TCP listening queue.
Parameters
queue: A TCP listening queue.
-
int
sock_tcp_get_local(sock/tcp.h::sock_tcp_t* sock,sock/tcp.h::sock_tcp_ep_t* ep)¶ Gets the local end point of a TCP sock object.
Parameters
sock: A TCP sock object. ep: The local end point. Return values
- 0 on success.
- -EADDRNOTAVAIL, when
sockhas no local end point.
-
int
sock_tcp_get_remote(sock/tcp.h::sock_tcp_t* sock,sock/tcp.h::sock_tcp_ep_t* ep)¶ Gets the remote end point of a TCP sock object.
Parameters
sock: A TCP sock object. ep: The remote end point. Return values
- 0 on success.
- -ENOTCONN, when
sockis not connected to a remote end point.
-
int
sock_tcp_queue_get_local(sock/tcp.h::sock_tcp_queue_t* queue,sock/tcp.h::sock_tcp_ep_t* ep)¶ Gets the local end point of a TCP sock queue object.
Parameters
queue: A TCP sock queue object. ep: The local end point. Return values
- 0 on success.
- -EADDRNOTAVAIL, when
queuehas no local end point.
-
int
sock_tcp_accept(sock/tcp.h::sock_tcp_queue_t* queue,sock/tcp.h::sock_tcp_t** sock, uint32_t timeout)¶ Receives and handles TCP connection requests from other peers.
Parameters
queue: A TCP listening queue. sock: A new TCP sock object for the established sock object. timeout: Timeout for accept in microseconds. If 0 and no data is available, the function returns immediately. May be sock.h::SOCK_NO_TIMEOUTfor no timeout (wait until data is available).Return values
- 0 on success.
- -EAGAIN, if
timeoutis0and no data is available. - -ECONNABORTED, if the connection to
sockhas been aborted while in this function - -EINVAL, if
queuewas not initialized usingsock/tcp.h::sock_tcp_listen(). - -ENOMEM, if system was not able to allocate sufficient memory to establish connection.
- -EPERM, if connections on local end point of
queueare not permitted on this system (e.g. by firewall rules). - -ETIMEDOUT, if the operation timed out internally.
-
msp430_types.h::ssize_tsock_tcp_read(sock/tcp.h::sock_tcp_t* sock, void * data,msp430_types.h::size_tmax_len, uint32_t timeout)¶ Reads data from an established TCP stream.
Parameters
sock: A TCP sock object. data: Pointer where the read data should be stored. max_len: Maximum space available at data. If read data exceedsmax_lenthe data is truncated and the remaining data can be retrieved later on.timeout: Timeout for receive in microseconds. If 0 and no data is available, the function returns immediately. May be sock.h::SOCK_NO_TIMEOUTfor no timeout (wait until data is available).Note
Function may block.
Return values
- The number of bytes read on success.
- 0, if no read data is available, but everything is in order.
- -EAGAIN, if
timeoutis0and no data is available. - -ECONNABORTED, if the connection is aborted while waiting for the next data.
- -ECONNRESET, if the connection was forcibly closed by remote end point of
sock. - -ENOTCONN, when
sockis not connected to a remote end point. - -ETIMEDOUT, if
timeoutexpired.
-
msp430_types.h::ssize_tsock_tcp_write(sock/tcp.h::sock_tcp_t* sock, const void * data,msp430_types.h::size_tlen)¶ Writes data to an established TCP stream.
Parameters
sock: A TCP sock object. data: Pointer to the data to be written to the stream. len: Maximum space available at data.Note
Function may block.
Return values
- The number of bytes written on success.
- -ECONNABORTED, if the connection is aborted while waiting for the next data.
- -ECONNRESET, if the connection was forcibly closed by remote end point of
sock. - -ENOMEM, if no memory was available to written
data. - -ENOTCONN, if
sockis not connected to a remote end point.