|
| void | tcp_init (void) |
| | set up TCP (from net_init): the timer.
|
| void | tcp_receive (netif_t *netif, const ipv4_header_t *ip, const uint8_t *segment, uint32_t length) |
| | a received segment (net_lock held).
|
| tcp_conn_t * | tcp_connect (uint32_t local, uint16_t local_port, uint32_t remote, uint16_t remote_port) |
| | start a connection: send a SYN (net_lock held).
|
| tcp_conn_t * | tcp_listen (uint32_t local, uint16_t local_port, uint32_t backlog) |
| | a listener on a port (net_lock held).
|
| tcp_conn_t * | tcp_accept (tcp_conn_t *listener) |
| | take the next connection from a listener's queue (net_lock held).
|
| uint32_t | tcp_write (tcp_conn_t *conn, const uint8_t *data, uint32_t length) |
| | put data into the send buffer and send what the windows allow (net_lock held).
|
| uint32_t | tcp_read (tcp_conn_t *conn, uint8_t *out, uint32_t length, bool peek) |
| | take data from the receive buffer (net_lock held).
|
| void | tcp_shutdown_write (tcp_conn_t *conn) |
| | no more data from the user: send FIN after the data (net_lock held).
|
| void | tcp_release (tcp_conn_t *conn) |
| | the socket lets the connection go (net_lock held): a listener resets the connections in its queue; a connection with data the user did not read is reset; any other is closed with FIN.
|
| uint32_t | tcp_send_room (const tcp_conn_t *conn) |
| | the room in the send buffer.
|
| bool | tcp_can_send (const tcp_conn_t *conn) |
| | true in the states where the user can send data.
|
| void | tcp_timer (uint64_t now) |
| | the timers, each tick (net_lock is taken here).
|
TCP (RFC 9293): reliable byte streams between ports.
a connection (tcp_conn_t) keeps the state of one end: the sequence numbers, a send buffer and a receive buffer, and the timers. the socket code (tcp_socket.c) puts data in and takes data out; this code sends and receives the segments.
what it does:
- the three-way handshake, both ways; a listener with a queue of connections to accept.
- retransmission with a timeout from the measured round-trip time (RFC 6298), backing off to TCP_MAX_RETRIES; fast retransmit after three duplicate acks.
- slow start and congestion avoidance (RFC 5681).
- the receive window (no window scaling, so at most 64 KiB); a probe when the peer's window is zero.
- the MSS option.
- close with FIN (TIME_WAIT for TCP_TIME_WAIT_MS), reset with RST. what it does not do (yet): segments that come out of order are dropped (the sender sends them again), no selective acks, no timestamps, no keepalive, no urgent data. acks are sent at once (no delayed acks), and small writes go at once (no Nagle).
locking: all of it runs with net_lock held. a connection is freed only by tcp_timer (closed and with no socket), never while the stack works on it, so a send that loops back through lo cannot free the connection under its caller.