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_tcp
needs 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_queue
needs 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) == 0
andlocal_port
is already used elsewhere - -EAFNOSUPPORT, if
sock.h::_sock_tl_ep::family
ofremote
is not supported. - -ECONNREFUSED, if no-one is listening on the
remote
end point. - -EINVAL, if
sock.h::_sock_tl_ep::addr
ofremote
is an invalid address. - -EINVAL, if
sock.h::_sock_tl_ep::netif
ofremote
is not a valid interface. - -ENETUNREACH, if network defined by
remote
is not reachable. - -ENOMEM, if system was not able to allocate sufficient memory to establish connection.
- -EPERM, if connections to
remote
are not permitted on the system (e.g. by firewall rules). - -ETIMEDOUT, if the connection attempt to
remote
timed 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
local
end 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) == 0
andlocal
is already used elsewhere - -EAFNOSUPPORT, if
sock.h::_sock_tl_ep::family
oflocal
is not supported. - -EINVAL, if
sock.h::_sock_tl_ep::netif
oflocal
is 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
sock
has 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
sock
is 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
queue
has 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_TIMEOUT
for no timeout (wait until data is available).Return values
- 0 on success.
- -EAGAIN, if
timeout
is0
and no data is available. - -ECONNABORTED, if the connection to
sock
has been aborted while in this function - -EINVAL, if
queue
was 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
queue
are not permitted on this system (e.g. by firewall rules). - -ETIMEDOUT, if the operation timed out internally.
-
msp430_types.h::ssize_t
sock_tcp_read
(sock/tcp.h::sock_tcp_t
* sock, void * data,msp430_types.h::size_t
max_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_len
the 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_TIMEOUT
for 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
timeout
is0
and 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
sock
is not connected to a remote end point. - -ETIMEDOUT, if
timeout
expired.
-
msp430_types.h::ssize_t
sock_tcp_write
(sock/tcp.h::sock_tcp_t
* sock, const void * data,msp430_types.h::size_t
len)¶ 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
sock
is not connected to a remote end point.