gnrc/tcp.h¶
GNRC TCP API.
-
int
gnrc_tcp_init
(void)¶ Initialize TCP.
Return values
- PID of TCP thread on success -1 if TCB is already running. -EINVAL, if priority is greater than or equal SCHED_PRIO_LEVELS -EOVERFLOW, if there are too many threads running.
-
void
gnrc_tcp_tcb_init
(tcb.h::gnrc_tcp_tcb_t
* tcb)¶ Initialize Transmission Control Block (TCB)
Parameters
tcb: TCB that should be initialized.
-
int
gnrc_tcp_open_active
(tcb.h::gnrc_tcp_tcb_t
* tcb, uint8_t address_family, char * target_addr, uint16_t target_port, uint16_t local_port)¶ Opens a connection actively.
Note
Blocks until a connection has been established or an error occured.
Parameters
tcb: TCB holding the connection information. address_family: Address family of target_addr
.target_addr: Pointer to target address. target_port: Target port number. local_port: If zero or PORT_UNSPEC, the connections source port is randomly chosen. If local_port is non-zero the local_port is used as source port. Return values
- Zero on success. -EAFNOSUPPORT if
address_family
is not supported. -EINVAL ifaddress_family
is not the same the address_family use by the TCB. ortarget_addr
is invalid. -EISCONN if TCB is already in use. -ENOMEM if the receive buffer for the TCB could not be allocated. -EADDRINUSE iflocal_port
is already used by another connection. -ETIMEDOUT if the connection could not be opened. -ECONNREFUSED if the connection was resetted by the peer.
- Zero on success. -EAFNOSUPPORT if
-
int
gnrc_tcp_open_passive
(tcb.h::gnrc_tcp_tcb_t
* tcb, uint8_t address_family, const char * local_addr, uint16_t local_port)¶ Opens a connection passively, by waiting for an incomming request.
Note
Blocks until a connection has been established (incomming connection request to
local_port
) or an error occured.Parameters
tcb: TCB holding the connection information. address_family: Address family of local_addr
. If local_addr == NULL, address_family is ignored.local_addr: If not NULL the connection is bound to local_addr
. If NULL a connection request to all local ip addresses is valied.local_port: Port number to listen on. Return values
- Zero on success. -EAFNOSUPPORT if local_addr != NULL and
address_family
is not supported. -EINVAL ifaddress_family
is not the same the address_family used in TCB. ortarget_addr
is invalid. -EISCONN if TCB is already in use. -ENOMEM if the receive buffer for the TCB could not be allocated. Hint: Increase “GNRC_TCP_RCV_BUFFERS”.
- Zero on success. -EAFNOSUPPORT if local_addr != NULL and
-
msp430_types.h::ssize_t
gnrc_tcp_send
(tcb.h::gnrc_tcp_tcb_t
* tcb, const void * data, constmsp430_types.h::size_t
len, const uint32_t user_timeout_duration_us)¶ Transmit data to connected peer.
Note
Blocks until up to
len
bytes were transmitted or an error occured.Parameters
tcb: TCB holding the connection information. data: Pointer to the data that should be transmitted. len: Number of bytes that should be transmitted. user_timeout_duration_us: If not zero and there was not data transmitted the function returns after user_timeout_duration_us. If zero, no timeout will be triggered. Return values
- The number of successfully transmitted bytes. -ENOTCONN if connection is not established. -ECONNRESET if connection was resetted by the peer. -ECONNABORTED if the connection was aborted. -ETIMEDOUT if
user_timeout_duration_us
expired.
- The number of successfully transmitted bytes. -ENOTCONN if connection is not established. -ECONNRESET if connection was resetted by the peer. -ECONNABORTED if the connection was aborted. -ETIMEDOUT if
-
msp430_types.h::ssize_t
gnrc_tcp_recv
(tcb.h::gnrc_tcp_tcb_t
* tcb, void * data, constmsp430_types.h::size_t
max_len, const uint32_t user_timeout_duration_us)¶ Receive Data from the peer.
Note
Function blocks if user_timeout_duration_us is not zero.
Parameters
tcb: TCB holding the connection information. data: Pointer to the buffer where the received data should be copied into. max_len: Maximum amount to bytes that should be read into data
.user_timeout_duration_us: Timeout for receive in microseconds. If zero and no data is available, the function returns immediately. If not zero the function blocks until data is available or user_timeout_duration_us
microseconds passed.Return values
- The number of bytes read into
data
. -ENOTCONN if connection is not established. -EAGAIN if user_timeout_duration_us is zero and no data is available. -ECONNRESET if connection was resetted by the peer. -ECONNABORTED if the connection was aborted. -ETIMEDOUT ifuser_timeout_duration_us
expired.
- The number of bytes read into
-
void
gnrc_tcp_close
(tcb.h::gnrc_tcp_tcb_t
* tcb)¶ Close a TCP connection.
Parameters
tcb: TCB holding the connection information.
-
void
gnrc_tcp_abort
(tcb.h::gnrc_tcp_tcb_t
* tcb)¶ Abort a TCP connection.
Parameters
tcb: TCB holding the connection information.
-
int
gnrc_tcp_calc_csum
(constinclude/net/gnrc/pkt.h::gnrc_pktsnip_t
* hdr, constinclude/net/gnrc/pkt.h::gnrc_pktsnip_t
* pseudo_hdr)¶ Calculate and set checksum in TCP header.
Parameters
hdr: Gnrc_pktsnip that contains TCP header. pseudo_hdr: Gnrc_pktsnip that contains network layer header. Return values
- Zero on succeed. -EFAULT if
hdr
or pseudo_hdr were NULL -EBADMSG ifhdr
is not of type GNRC_NETTYPE_TCP -ENOENT ifpseudo_hdr
protocol is unsupported.
- Zero on succeed. -EFAULT if
-
include/net/gnrc/pkt.h::gnrc_pktsnip_t
*gnrc_tcp_hdr_build
(include/net/gnrc/pkt.h::gnrc_pktsnip_t
* payload, uint16_t src, uint16_t dst)¶ Adds a TCP header to a given payload.
Parameters
payload: Payload that follows the TCP header. src: Source port number. dst: Destination port number. Return values
- Not NULL on success. NULL if TCP header was not allocated.