Sponge
CS144's user-space TCP library
Public Member Functions | Private Attributes | List of all members
TCPOverUDPSocketAdapter Class Reference

A FD adaptor that reads and writes TCP segments in UDP payloads. More...

#include <fd_adapter.hh>

Inheritance diagram for TCPOverUDPSocketAdapter:
Inheritance graph
[legend]

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< TCPSegmentread ()
 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 FdAdapterConfigconfig () const
 Get the current configuration. More...
 
FdAdapterConfigconfig_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
FdAdapterConfigconfig_mutable ()
 

Detailed Description

A FD adaptor that reads and writes TCP segments in UDP payloads.

Definition at line 46 of file fd_adapter.hh.

Constructor & Destructor Documentation

◆ TCPOverUDPSocketAdapter()

TCPOverUDPSocketAdapter::TCPOverUDPSocketAdapter ( UDPSocket &&  sock)
inlineexplicit

Construct from a UDPSocket sliced into a FileDescriptor.

Definition at line 52 of file fd_adapter.hh.

Member Function Documentation

◆ operator const UDPSocket &()

TCPOverUDPSocketAdapter::operator const UDPSocket & ( ) const
inline

Access the underlying UDP socket.

Definition at line 64 of file fd_adapter.hh.

◆ operator UDPSocket &()

TCPOverUDPSocketAdapter::operator UDPSocket & ( )
inline

Access the underlying UDP socket.

Definition at line 61 of file fd_adapter.hh.

◆ read()

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.

Returns
a std::optional<TCPSegment> that is empty if the segment was invalid or unrelated

Definition at line 21 of file fd_adapter.cc.

◆ write()

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.

Parameters
[in]segis the TCP segment to write

Definition at line 50 of file fd_adapter.cc.

Member Data Documentation

◆ _sock

UDPSocket TCPOverUDPSocketAdapter::_sock
private

Definition at line 48 of file fd_adapter.hh.


The documentation for this class was generated from the following files: