Sponge
CS144's user-space TCP library
|
A complete endpoint of a TCP connection. More...
#include <tcp_connection.hh>
Public Member Functions | |
TCPConnection (const TCPConfig &cfg) | |
Construct a new connection from a configuration. More... | |
"Input" interface for the writer | |
void | connect () |
Initiate a connection by sending a SYN segment. More... | |
size_t | write (const std::string &data) |
Write data to the outbound byte stream, and send it over TCP if possible. More... | |
size_t | remaining_outbound_capacity () const |
void | end_input_stream () |
Shut down the outbound byte stream (still allows reading incoming data) More... | |
"Output" interface for the reader | |
ByteStream & | inbound_stream () |
The inbound byte stream received from the peer. More... | |
Accessors used for testing | |
size_t | bytes_in_flight () const |
number of bytes sent and not yet acknowledged, counting SYN/FIN each as one byte More... | |
size_t | unassembled_bytes () const |
number of bytes not yet reassembled More... | |
size_t | time_since_last_segment_received () const |
Number of milliseconds since the last segment was received. More... | |
TCPState | state () const |
Methods for the owner or operating system to call | |
void | segment_received (const TCPSegment &seg) |
Called when a new segment has been received from the network. More... | |
void | tick (const size_t ms_since_last_tick) |
Called periodically when time elapses. More... | |
std::queue< TCPSegment > & | segments_out () |
TCPSegments that the TCPConnection has enqueued for transmission. More... | |
bool | active () const |
Is the connection still alive in any way? More... | |
construction and destruction | |
moving is allowed; copying is disallowed; default construction not possible | |
~TCPConnection () | |
destructor sends a RST if the connection is still open More... | |
TCPConnection ()=delete | |
TCPConnection (TCPConnection &&other)=default | |
TCPConnection & | operator= (TCPConnection &&other)=default |
TCPConnection (const TCPConnection &other)=delete | |
TCPConnection & | operator= (const TCPConnection &other)=delete |
Private Attributes | |
TCPConfig | _cfg |
bool | _linger_after_streams_finish {true} |
TCPReceiver | _receiver {_cfg.recv_capacity} |
std::queue< TCPSegment > | _segments_out {} |
outbound queue of segments that the TCPConnection wants sent More... | |
TCPSender | _sender {_cfg.send_capacity, _cfg.rt_timeout, _cfg.fixed_isn} |
A complete endpoint of a TCP connection.
Definition at line 10 of file tcp_connection.hh.
|
inlineexplicit |
Construct a new connection from a configuration.
Definition at line 84 of file tcp_connection.hh.
TCPConnection::~TCPConnection | ( | ) |
destructor sends a RST if the connection is still open
Definition at line 39 of file tcp_connection.cc.
|
delete |
|
default |
|
delete |
bool TCPConnection::active | ( | ) | const |
Is the connection still alive in any way?
true
if either stream is still running or if the TCPConnection is lingering after both streams have finished (e.g. to ACK retransmissions from the peer) Definition at line 25 of file tcp_connection.cc.
size_t TCPConnection::bytes_in_flight | ( | ) | const |
number of bytes sent and not yet acknowledged, counting SYN/FIN each as one byte
Definition at line 17 of file tcp_connection.cc.
void TCPConnection::connect | ( | ) |
Initiate a connection by sending a SYN segment.
Definition at line 37 of file tcp_connection.cc.
void TCPConnection::end_input_stream | ( | ) |
Shut down the outbound byte stream (still allows reading incoming data)
Definition at line 35 of file tcp_connection.cc.
|
inline |
The inbound byte stream received from the peer.
Definition at line 46 of file tcp_connection.hh.
|
delete |
|
default |
size_t TCPConnection::remaining_outbound_capacity | ( | ) | const |
bytes
that can be written right now. Definition at line 15 of file tcp_connection.cc.
void TCPConnection::segment_received | ( | const TCPSegment & | seg | ) |
Called when a new segment has been received from the network.
Definition at line 23 of file tcp_connection.cc.
|
inline |
TCPSegments that the TCPConnection has enqueued for transmission.
Definition at line 75 of file tcp_connection.hh.
|
inline |
Definition at line 59 of file tcp_connection.hh.
void TCPConnection::tick | ( | const size_t | ms_since_last_tick | ) |
Called periodically when time elapses.
[in] | ms_since_last_tick | number of milliseconds since the last call to this method |
Definition at line 33 of file tcp_connection.cc.
size_t TCPConnection::time_since_last_segment_received | ( | ) | const |
Number of milliseconds since the last segment was received.
summarize the state of the sender, receiver, and the connection
Definition at line 21 of file tcp_connection.cc.
size_t TCPConnection::unassembled_bytes | ( | ) | const |
number of bytes not yet reassembled
Definition at line 19 of file tcp_connection.cc.
size_t TCPConnection::write | ( | const std::string & | data | ) |
Write data to the outbound byte stream, and send it over TCP if possible.
data
that were actually written. Definition at line 27 of file tcp_connection.cc.
|
private |
Definition at line 12 of file tcp_connection.hh.
|
private |
Should the TCPConnection stay active (and keep ACKing) for 10 * _cfg.rt_timeout milliseconds after both streams have ended, in case the remote TCPConnection doesn't know we've received its whole stream?
Definition at line 22 of file tcp_connection.hh.
|
private |
Definition at line 13 of file tcp_connection.hh.
|
private |
outbound queue of segments that the TCPConnection wants sent
Definition at line 17 of file tcp_connection.hh.
|
private |
Definition at line 14 of file tcp_connection.hh.