2626#include " tcp_errors.hpp"
2727#include " write_queue.hpp"
2828#include < delegate>
29+ #include < util/timer.hpp>
2930
3031namespace net {
3132 class TCP ;
@@ -282,7 +283,7 @@ class Connection : public std::enable_shared_from_this<Connection> {
282283 virtual size_t send (Connection&, WriteBuffer&);
283284
284285 /* * Read from a Connection [RECEIVE] */
285- virtual void receive (Connection&, ReadBuffer&);
286+ virtual void receive (Connection&, ReadBuffer&& );
286287
287288 /* * Close a Connection [CLOSE] */
288289 virtual void close (Connection&);
@@ -477,20 +478,11 @@ class Connection : public std::enable_shared_from_this<Connection> {
477478 /* * State if connection is in TCP write queue or not. */
478479 bool queued_;
479480
480- /* * When time-wait timer was started. Used in start_time_wait_timeout */
481- uint64_t time_wait_started;
482-
483481 /* * Retransmission timer */
484- struct {
485- uint32_t id;
486- bool active = false ;
487- } rtx_timer;
482+ Timer rtx_timer;
488483
489484 /* * Time Wait timeout timer */
490- struct {
491- uint32_t id;
492- bool active = false ;
493- } timewait_timer;
485+ Timer timewait_timer;
494486
495487 /* * Number of retransmission attempts on the packet first in RT-queue */
496488 size_t rtx_attempt_ = 0 ;
@@ -550,8 +542,7 @@ class Connection : public std::enable_shared_from_this<Connection> {
550542 Buffer is cleared for data after every reset.
551543 */
552544 void read (size_t n, ReadCallback callback) {
553- ReadBuffer buffer = {new_shared_buffer (n), n};
554- read (buffer, callback);
545+ read ({new_shared_buffer (n), n}, callback);
555546 }
556547
557548 /*
@@ -561,13 +552,13 @@ class Connection : public std::enable_shared_from_this<Connection> {
561552 void read (buffer_t buffer, size_t n, ReadCallback callback)
562553 { read ({buffer, n}, callback); }
563554
564- void read (ReadBuffer buffer, ReadCallback callback);
555+ void read (ReadBuffer&& buffer, ReadCallback callback);
565556
566557 /*
567558 Assign the read request (read buffer)
568559 */
569- void receive (ReadBuffer& buffer)
570- { read_request. buffer = {buffer}; }
560+ void receive (ReadBuffer&& buffer)
561+ { read_request = {buffer}; }
571562
572563 /*
573564 Receive data into the current read requests buffer.
@@ -853,20 +844,20 @@ class Connection : public std::enable_shared_from_this<Connection> {
853844 /*
854845 Start retransmission timer.
855846 */
856- void rtx_start ();
847+ void rtx_start ()
848+ { rtx_timer.start (rttm.rto_ms ()); }
857849
858850 /*
859851 Stop retransmission timer.
860852 */
861- void rtx_stop ();
853+ void rtx_stop ()
854+ { rtx_timer.stop (); }
862855
863856 /*
864857 Restart retransmission timer.
865858 */
866- void rtx_reset () {
867- rtx_stop ();
868- rtx_start ();
869- }
859+ void rtx_reset ()
860+ { rtx_timer.restart (rttm.rto_ms ()); }
870861
871862 /*
872863 Retransmission timeout limit reached
@@ -887,8 +878,7 @@ class Connection : public std::enable_shared_from_this<Connection> {
887878 /*
888879 When retransmission times out.
889880 */
890- void rtx_timeout (uint32_t );
891-
881+ void rtx_timeout ();
892882
893883 /* * Start the timewait timeout for 2*MSL */
894884 void timewait_start ();
@@ -900,7 +890,7 @@ class Connection : public std::enable_shared_from_this<Connection> {
900890 void timewait_restart ();
901891
902892 /* * When timewait timer times out */
903- void timewait_timeout (uint32_t );
893+ void timewait_timeout ();
904894
905895 /*
906896 Tell the host (TCP) to delete this connection.
0 commit comments