5.7 KiB
5.7 KiB
FemtoTCP
Stack architecture
- No dynamic allocation (pre-allocated sockets and buffers)
- Four-steps main loop function
- Callback-based socket interface (allows implementing blocking BSD calls)
Data structures
-
Two types of circular buffers (fixed size):
- "fifo" : contains entire frames, including a descriptor.
- "queue" : contains pure data, indexed by byte. Used for TCP receive buffer only.
-
One binary heap for timers
FemtoTCP fifo
+---------------------------------------------------------------------------------------------------------------------------+
| +-----+---+----+-----+------------------+-----+---+----+-----+------------------+ |
| | De | E | IP | TCP | Payload | De | E | IP | TCP | Payload | |
| | sc | T | | | | sc | T | | | | |
|* FREE SPACE * | ri | H | | | | ri | H | | | | * FREE SPACE* |
| | pt | | | | | pt | | | | | |
| | or | | | | | or | | | | | |
| +-----+---+----+-----+------------------+-----+---+----+-----+------------------+ |
+---------------------------------------------------------------------------------------------------------------------------+
^ ^
| |
| |
| |
|Tail Head|
FemtoTCP queue
+--------------+--------------------------------------------+---------------------------------------------------------------+
| |*------------------------------------------*| |
| || || |
| || || |
|* FREE SPACE *|| DATA PAYLOAD || * FREE SPACE * |
| || || |
| || || |
| |*------------------------------------------*| |
+--------------+--------------------------------------------+---------------------------------------------------------------+
^ ^
| |
| |
| |
|Tail Head|
Sockets
TCP socket
+-------------+
|Main loop TX |
+-------------+
^
+----------------------------------+ |
| | +------+
| TCP Socket | |
| | |
| | |
| | |
| +-----------------------+
| +---------------+ | |
>DATA OUT==>>|socket send() |-->| TX buffer (fifo) |
| +---------------+ | |
| +-----------------------+
| |
| |
| |
| +-----------------------+
| +-------------+ | |
<DATA IN<<====|socket recv()|<---| RX buffer (queue) |
| +-------------+ | |
| +-----------------------+
+----------------------------------+ ^
|
|
|
+--------------+
| tcp_recv() |
+--------------+