Skip to content

Commit 7826494

Browse files
tcp: Connection no longer setup default callbacks, but check if there is before calling
1 parent ab1a679 commit 7826494

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

api/net/tcp/connection.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -665,19 +665,19 @@ class Connection : public std::enable_shared_from_this<Connection> {
665665
Invoke/signal the diffrent TCP events.
666666
*/
667667
void signal_connect()
668-
{ on_connect_(shared_from_this()); }
668+
{ if(on_connect_) on_connect_(shared_from_this()); }
669669

670670
void signal_disconnect(Disconnect::Reason&& reason)
671671
{ on_disconnect_(shared_from_this(), Disconnect{reason}); }
672672

673673
void signal_error(TCPException error)
674-
{ on_error_(std::forward<TCPException>(error)); }
674+
{ if(on_error_) on_error_(std::forward<TCPException>(error)); }
675675

676676
void signal_packet_dropped(const Packet& packet, const std::string& reason)
677-
{ on_packet_dropped_(packet, reason); }
677+
{ if(on_packet_dropped_) on_packet_dropped_(packet, reason); }
678678

679679
void signal_rtx_timeout()
680-
{ on_rtx_timeout_(rtx_attempt_+1, rttm.RTO); }
680+
{ if(on_rtx_timeout_) on_rtx_timeout_(rtx_attempt_+1, rttm.RTO); }
681681

682682
/*
683683
Drop a packet. Used for debug/callback.

src/net/tcp/connection.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ Connection::Connection(TCP& host, port_t local_port, Socket remote) :
4141
cb(),
4242
read_request(),
4343
writeq(),
44+
on_disconnect_({this, &Connection::default_on_disconnect}),
4445
bytes_rx_(0), bytes_tx_(0),
4546
queued_(false),
4647
rtx_timer({this, &Connection::rtx_timeout}),
4748
timewait_timer({this, &Connection::timewait_timeout})
4849
{
4950
setup_congestion_control();
50-
setup_default_callbacks();
5151
debug("<Connection> %s created\n", to_string().c_str());
5252
}
5353

@@ -816,7 +816,7 @@ void Connection::signal_close() {
816816
debug("<Connection::signal_close> It's time to delete this connection. \n");
817817

818818
// call user callback
819-
on_close_();
819+
if(on_close_) on_close_();
820820

821821
// clean up all copies, delegates and timers
822822
clean_up();
@@ -833,7 +833,7 @@ void Connection::clean_up() {
833833
auto shared = shared_from_this();
834834
// clean up all other copies
835835
// either in TCP::listeners_ (open) or Listener::syn_queue_ (half-open)
836-
_on_cleanup_(shared);
836+
if(_on_cleanup_) _on_cleanup_(shared);
837837

838838
on_connect_.reset();
839839
on_disconnect_.reset(),

0 commit comments

Comments
 (0)