Sponge
CS144's user-space TCP library
tcp_connection.cc
Go to the documentation of this file.
1 #include "tcp_connection.hh"
2 
3 #include <iostream>
4 
5 // Dummy implementation of a TCP connection
6 
7 // For Lab 4, please replace with a real implementation that passes the
8 // automated checks run by `make check`.
9 
10 template <typename... Targs>
11 void DUMMY_CODE(Targs &&... /* unused */) {}
12 
13 using namespace std;
14 
15 size_t TCPConnection::remaining_outbound_capacity() const { return {}; }
16 
17 size_t TCPConnection::bytes_in_flight() const { return {}; }
18 
19 size_t TCPConnection::unassembled_bytes() const { return {}; }
20 
22 
24 
25 bool TCPConnection::active() const { return {}; }
26 
27 size_t TCPConnection::write(const string &data) {
28  DUMMY_CODE(data);
29  return {};
30 }
31 
33 void TCPConnection::tick(const size_t ms_since_last_tick) { DUMMY_CODE(ms_since_last_tick); }
34 
36 
38 
40  try {
41  if (active()) {
42  cerr << "Warning: Unclean shutdown of TCPConnection\n";
43 
44  // Your code here: need to send a RST segment to the peer
45  }
46  } catch (const exception &e) {
47  std::cerr << "Exception destructing TCP FSM: " << e.what() << std::endl;
48  }
49 }
TCPConnection::connect
void connect()
Initiate a connection by sending a SYN segment.
Definition: tcp_connection.cc:37
TCPConnection::unassembled_bytes
size_t unassembled_bytes() const
number of bytes not yet reassembled
Definition: tcp_connection.cc:19
TCPConnection::time_since_last_segment_received
size_t time_since_last_segment_received() const
Number of milliseconds since the last segment was received.
Definition: tcp_connection.cc:21
DUMMY_CODE
void DUMMY_CODE(Targs &&...)
Definition: tcp_connection.cc:11
std::exception
TCPConnection::end_input_stream
void end_input_stream()
Shut down the outbound byte stream (still allows reading incoming data)
Definition: tcp_connection.cc:35
tcp_connection.hh
TCPConnection::remaining_outbound_capacity
size_t remaining_outbound_capacity() const
Definition: tcp_connection.cc:15
TCPConnection::bytes_in_flight
size_t bytes_in_flight() const
number of bytes sent and not yet acknowledged, counting SYN/FIN each as one byte
Definition: tcp_connection.cc:17
TCPConnection::active
bool active() const
Is the connection still alive in any way?
Definition: tcp_connection.cc:25
TCPConnection::segment_received
void segment_received(const TCPSegment &seg)
Called when a new segment has been received from the network.
Definition: tcp_connection.cc:23
std::cerr
TCPConnection::~TCPConnection
~TCPConnection()
destructor sends a RST if the connection is still open
Definition: tcp_connection.cc:39
std::endl
T endl(T... args)
TCPConnection::write
size_t write(const std::string &data)
Write data to the outbound byte stream, and send it over TCP if possible.
Definition: tcp_connection.cc:27
std
TCPConnection::tick
void tick(const size_t ms_since_last_tick)
Called periodically when time elapses.
Definition: tcp_connection.cc:33
TCPSegment
TCP segment
Definition: tcp_segment.hh:10
std::exception::what
T what(T... args)