Sponge
CS144's user-space TCP library
|
A FD adaptor that reads and writes TCP segments in UDP payloads. More...
#include <fd_adapter.hh>
Public Member Functions | |
TCPOverUDPSocketAdapter (UDPSocket &&sock) | |
Construct from a UDPSocket sliced into a FileDescriptor. More... | |
operator const UDPSocket & () const | |
Access the underlying UDP socket. More... | |
operator UDPSocket & () | |
Access the underlying UDP socket. More... | |
std::optional< TCPSegment > | read () |
Attempts to read and return a TCP segment related to the current connection from a UDP payload. More... | |
void | write (TCPSegment &seg) |
Writes a TCP segment into a UDP payload. More... | |
Public Member Functions inherited from FdAdapterBase | |
const FdAdapterConfig & | config () const |
Get the current configuration. More... | |
FdAdapterConfig & | config_mut () |
Get the current configuration (mutable) More... | |
bool | listening () const |
Get the listening flag. More... | |
void | set_listening (const bool l) |
Set the listening flag. More... | |
void | tick (const size_t) |
Called periodically when time elapses. More... | |
Private Attributes | |
UDPSocket | _sock |
Additional Inherited Members | |
Protected Member Functions inherited from FdAdapterBase | |
FdAdapterConfig & | config_mutable () |
A FD adaptor that reads and writes TCP segments in UDP payloads.
Definition at line 46 of file fd_adapter.hh.
|
inlineexplicit |
Construct from a UDPSocket sliced into a FileDescriptor.
Definition at line 52 of file fd_adapter.hh.
|
inline |
Access the underlying UDP socket.
Definition at line 64 of file fd_adapter.hh.
|
inline |
Access the underlying UDP socket.
Definition at line 61 of file fd_adapter.hh.
optional< TCPSegment > TCPOverUDPSocketAdapter::read | ( | ) |
Attempts to read and return a TCP segment related to the current connection from a UDP payload.
This function first attempts to parse a TCP segment from the next UDP payload recv()d from the socket.
If this succeeds, it then checks that the received segment is related to the current connection. When a TCP connection has been established, this means checking that the source and destination ports in the TCP header are correct.
If the TCP FSM is listening (i.e., TCPOverUDPSocketAdapter::_listen is true
) and the TCP segment read from the wire includes a SYN, this function clears the _listen
flag and calls calls connect() on the underlying UDP socket, with the result that future outgoing segments go to the sender of the SYN segment.
Definition at line 21 of file fd_adapter.cc.
void TCPOverUDPSocketAdapter::write | ( | TCPSegment & | seg | ) |
Writes a TCP segment into a UDP payload.
Serialize a TCP segment and send it as the payload of a UDP datagram.
[in] | seg | is the TCP segment to write |
Definition at line 50 of file fd_adapter.cc.
|
private |
Definition at line 48 of file fd_adapter.hh.