@@ -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.
@@ -790,6 +782,7 @@ class Connection : public std::enable_shared_from_this<Connection> {
790782 /* *
791783 * @brief Open the connection.
792784 * Active determines whether the connection is active or passive.
785+ * May throw if no remote host, or state isnt valid for opening.
793786 *
794787 * @param[in] active Whether its an active (outgoing) or passive (listening)
795788 */
@@ -845,7 +838,6 @@ class Connection : public std::enable_shared_from_this<Connection> {
845838 /* * Callbacks */
846839 ConnectCallback on_connect_;
847840 DisconnectCallback on_disconnect_;
848- ErrorCallback on_error_;
849841 PacketDroppedCallback on_packet_dropped_;
850842 RtxTimeoutCallback on_rtx_timeout_;
851843 CloseCallback on_close_;
@@ -1000,15 +992,15 @@ class Connection : public std::enable_shared_from_this<Connection> {
1000992 /*
1001993 Invoke/signal the diffrent TCP events.
1002994 */
1003- void signal_connect ()
1004- { if (on_connect_) on_connect_ (shared_from_this ()); }
995+ void signal_connect (const bool success = true )
996+ {
997+ if (on_connect_)
998+ (success) ? on_connect_ (shared_from_this ()) : on_connect_ (nullptr );
999+ }
10051000
10061001 void signal_disconnect (Disconnect::Reason&& reason)
10071002 { on_disconnect_ (shared_from_this (), Disconnect{reason}); }
10081003
1009- void signal_error (TCPException error)
1010- { if (on_error_) on_error_ (std::forward<TCPException>(error)); }
1011-
10121004 void signal_packet_dropped (const Packet& packet, Drop_reason reason)
10131005 { if (on_packet_dropped_) on_packet_dropped_ (packet, reason); }
10141006
@@ -1266,7 +1258,7 @@ class Connection : public std::enable_shared_from_this<Connection> {
12661258 Retransmission timeout limit reached
12671259 */
12681260 bool rto_limit_reached () const
1269- { return rtx_attempt_ >= 15 or syn_rtx_ >= 5 ; };
1261+ { return rtx_attempt_ >= 14 or syn_rtx_ >= 4 ; };
12701262
12711263 /*
12721264 Remove all packets acknowledge by ACK in retransmission queue
0 commit comments