@@ -65,12 +65,13 @@ class Connection : public std::enable_shared_from_this<Connection> {
6565 using WriteBuffer = Write_queue::WriteBuffer;
6666
6767public:
68- /* * Called with the connection itself when it's been established. */
68+ /* * Called with the connection itself when it's been established. May be a nullptr if the connection failed. */
6969 using ConnectCallback = delegate<void (Connection_ptr self)>;
7070 /* *
7171 * @brief Event when a connection has been established.
7272 * This event lets you know when to start using the connection,
7373 * and should always be assigned.
74+ * NOTE: The Connection_ptr will be a nullptr when an outgoing connection failed.
7475 *
7576 * @param[in] callback The callback
7677 *
@@ -137,18 +138,6 @@ class Connection : public std::enable_shared_from_this<Connection> {
137138 */
138139 inline Connection& on_write (WriteCallback callback);
139140
140- /* * Called with the error encountered. */
141- using ErrorCallback = delegate<void (const TCPException& err)>;
142- /* *
143- * @brief Event when a connection has experienced an error of any kind.
144- * Pretty useless in it's current form, and only useful for printing.
145- *
146- * @param[in] callback The callback
147- *
148- * @return This connection
149- */
150- inline Connection& on_error (ErrorCallback callback);
151-
152141 /* * Called with the packet that got dropped and the reason why. */
153142 using PacketDroppedCallback = delegate<void (const Packet&, Drop_reason)>;
154143 /* *
@@ -231,7 +220,10 @@ class Connection : public std::enable_shared_from_this<Connection> {
231220 */
232221 Stream (Connection_ptr conn)
233222 : tcp{std::move (conn)}
234- {}
223+ {
224+ // stream for a nullptr makes no sense
225+ Expects (tcp != nullptr );
226+ }
235227
236228 /* *
237229 * @brief Event when the stream is connected/established/ready to use.
@@ -788,6 +780,7 @@ class Connection : public std::enable_shared_from_this<Connection> {
788780 /* *
789781 * @brief Open the connection.
790782 * Active determines whether the connection is active or passive.
783+ * May throw if no remote host, or state isnt valid for opening.
791784 *
792785 * @param[in] active Whether its an active (outgoing) or passive (listening)
793786 */
@@ -843,7 +836,6 @@ class Connection : public std::enable_shared_from_this<Connection> {
843836 /* * Callbacks */
844837 ConnectCallback on_connect_;
845838 DisconnectCallback on_disconnect_;
846- ErrorCallback on_error_;
847839 PacketDroppedCallback on_packet_dropped_;
848840 RtxTimeoutCallback on_rtx_timeout_;
849841 CloseCallback on_close_;
@@ -998,15 +990,15 @@ class Connection : public std::enable_shared_from_this<Connection> {
998990 /*
999991 Invoke/signal the diffrent TCP events.
1000992 */
1001- void signal_connect ()
1002- { if (on_connect_) on_connect_ (shared_from_this ()); }
993+ void signal_connect (const bool success = true )
994+ {
995+ if (on_connect_)
996+ (success) ? on_connect_ (shared_from_this ()) : on_connect_ (nullptr );
997+ }
1003998
1004999 void signal_disconnect (Disconnect::Reason&& reason)
10051000 { on_disconnect_ (shared_from_this (), Disconnect{reason}); }
10061001
1007- void signal_error (TCPException error)
1008- { if (on_error_) on_error_ (std::forward<TCPException>(error)); }
1009-
10101002 void signal_packet_dropped (const Packet& packet, Drop_reason reason)
10111003 { if (on_packet_dropped_) on_packet_dropped_ (packet, reason); }
10121004
@@ -1264,7 +1256,7 @@ class Connection : public std::enable_shared_from_this<Connection> {
12641256 Retransmission timeout limit reached
12651257 */
12661258 bool rto_limit_reached () const
1267- { return rtx_attempt_ >= 15 or syn_rtx_ >= 5 ; };
1259+ { return rtx_attempt_ >= 14 or syn_rtx_ >= 4 ; };
12681260
12691261 /*
12701262 Remove all packets acknowledge by ACK in retransmission queue
0 commit comments