@@ -82,29 +82,29 @@ Socket Connection::local() const {
8282 return {host_.address (), local_port_};
8383}
8484
85- void Connection::read (ReadBuffer buffer, ReadCallback callback) {
85+ void Connection::read (ReadBuffer&& buffer, ReadCallback callback) {
8686 try {
87- state_->receive (*this , buffer);
87+ state_->receive (*this , std::forward<ReadBuffer>( buffer) );
8888 read_request.callback = callback;
8989 }
90- catch (TCPException err ) {
90+ catch (const TCPException& ) {
9191 callback (buffer.buffer , buffer.size ());
9292 }
9393}
9494
9595size_t Connection::receive (const uint8_t * data, size_t n, bool PUSH) {
9696 // printf("<Connection::receive> len=%u\n", n);
9797 // should not be called without an read request
98- assert (read_request.buffer .capacity ());
99- assert (n);
98+ Ensures (read_request.buffer .capacity ());
99+ Ensures (n);
100100 auto & buf = read_request.buffer ;
101101 size_t received{0 };
102102 while (n) {
103103 auto read = receive (buf, data+received, n);
104104 // nothing was read to buffer
105105 if (!buf.advance (read)) {
106106 // buffer should be full
107- assert (buf.full ());
107+ Expects (buf.full ());
108108 // signal the user
109109 debug2 (" <Connection::receive> Buffer full - signal user\n " );
110110 read_request.callback (buf.buffer , buf.size ());
@@ -115,7 +115,7 @@ size_t Connection::receive(const uint8_t* data, size_t n, bool PUSH) {
115115 received += read;
116116 }
117117 // n shouldnt be negative
118- assert (n == 0 );
118+ Expects (n == 0 );
119119
120120 // end of data, signal the user
121121 if (PUSH) {
@@ -145,7 +145,7 @@ void Connection::write(WriteBuffer buffer, WriteCallback callback) {
145145 writeq.advance (written);
146146 }
147147 }
148- catch (TCPException err ) {
148+ catch (const TCPException& ) {
149149 callback (0 );
150150 }
151151}
@@ -302,7 +302,7 @@ void Connection::open(bool active) {
302302 state_->open (*this , active);
303303 }
304304 // No remote host, or state isnt valid for opening.
305- catch (TCPException e) {
305+ catch (const TCPException& e) {
306306 debug (" <TCP::Connection::open> Cannot open Connection. \n " );
307307 signal_error (e);
308308 }
@@ -314,7 +314,7 @@ void Connection::close() {
314314 state_->close (*this );
315315 if (is_state (Closed::instance ()))
316316 signal_close ();
317- } catch (TCPException err) {
317+ } catch (const TCPException& err) {
318318 Ensures (on_error_);
319319 signal_error (err);
320320 }
@@ -342,7 +342,7 @@ void Connection::segment_arrived(Packet_ptr incoming) {
342342 try {
343343 parse_options (incoming);
344344 }
345- catch (TCPBadOptionException err) {
345+ catch (const TCPBadOptionException& err) {
346346 debug (" <TCP::Connection::receive> %s \n " , err.what ());
347347 drop (incoming, err.what ());
348348 return ;
0 commit comments