@@ -45,9 +45,8 @@ bool McbpConnection::unregisterEvent() {
4545 cb_assert (socketDescriptor != INVALID_SOCKET);
4646
4747 if (event_del (&event) == -1 ) {
48- log_system_error (EXTENSION_LOG_WARNING,
49- NULL ,
50- " Failed to remove connection to libevent: %s" );
48+ LOG_WARNING (" Failed to remove connection to libevent: {}" ,
49+ cb_strerror ());
5150 return false ;
5251 }
5352
@@ -80,8 +79,7 @@ bool McbpConnection::registerEvent() {
8079 ev_insert_time = mc_time_get_current_time ();
8180
8281 if (event_add (&event, tp) == -1 ) {
83- log_system_error (EXTENSION_LOG_WARNING, nullptr ,
84- " Failed to add connection to libevent: %s" );
82+ LOG_WARNING (" Failed to add connection to libevent: {}" , cb_strerror ());
8583 return false ;
8684 }
8785
@@ -269,7 +267,7 @@ int McbpConnection::sslPreConnection() {
269267 }
270268 }
271269 if (disconnect) {
272- set_econnreset ();
270+ cb::net:: set_econnreset ();
273271 if (!certResult.second .empty ()) {
274272 LOG_WARNING (
275273 " {}: SslPreConnection: disconnection client due to"
@@ -282,7 +280,7 @@ int McbpConnection::sslPreConnection() {
282280 } else {
283281 if (ssl.getError (r) == SSL_ERROR_WANT_READ) {
284282 ssl.drainBioSendPipe (socketDescriptor);
285- set_ewouldblock ();
283+ cb::net:: set_ewouldblock ();
286284 return -1 ;
287285 } else {
288286 try {
@@ -300,7 +298,7 @@ int McbpConnection::sslPreConnection() {
300298 // unable to print error message; continue.
301299 }
302300
303- set_econnreset ();
301+ cb::net:: set_econnreset ();
304302 return -1 ;
305303 }
306304 }
@@ -318,7 +316,7 @@ int McbpConnection::recv(char* dest, size_t nbytes) {
318316 ssl.drainBioRecvPipe (socketDescriptor);
319317
320318 if (ssl.hasError ()) {
321- set_econnreset ();
319+ cb::net:: set_econnreset ();
322320 return -1 ;
323321 }
324322
@@ -343,8 +341,8 @@ int McbpConnection::recv(char* dest, size_t nbytes) {
343341 return res;
344342}
345343
346- int McbpConnection::sendmsg (struct msghdr * m) {
347- int res = 0 ;
344+ ssize_t McbpConnection::sendmsg (struct msghdr * m) {
345+ ssize_t res = 0 ;
348346 if (ssl.isEnabled ()) {
349347 for (int ii = 0 ; ii < int (m->msg_iovlen ); ++ii) {
350348 int n = sslWrite (reinterpret_cast <char *>(m->msg_iov [ii].iov_base ),
@@ -362,7 +360,7 @@ int McbpConnection::sendmsg(struct msghdr* m) {
362360 ssl.drainBioSendPipe (socketDescriptor);
363361 return res;
364362 } else {
365- res = int (:: sendmsg (socketDescriptor, m, 0 ) );
363+ res = cb::net:: sendmsg (socketDescriptor, m, 0 );
366364 if (res > 0 ) {
367365 totalSend += res;
368366 }
@@ -436,7 +434,7 @@ McbpConnection::TransmitResult McbpConnection::transmit() {
436434 struct msghdr * m = &msglist[msgcurr];
437435
438436 res = sendmsg (m);
439- auto error = GetLastNetworkError ();
437+ auto error = cb::net::get_socket_error ();
440438 if (res > 0 ) {
441439 get_thread_stats (this )->bytes_written += res;
442440
@@ -463,7 +461,7 @@ McbpConnection::TransmitResult McbpConnection::transmit() {
463461 return TransmitResult::Incomplete;
464462 }
465463
466- if (res == -1 && is_blocking (error)) {
464+ if (res == -1 && cb::net:: is_blocking (error)) {
467465 if (!updateEvent (EV_WRITE | EV_PERSIST)) {
468466 setState (McbpStateMachine::State::closing);
469467 return TransmitResult::HardError;
@@ -474,12 +472,12 @@ McbpConnection::TransmitResult McbpConnection::transmit() {
474472 // if res == 0 or res == -1 and error is not EAGAIN or EWOULDBLOCK,
475473 // we have a real error, on which we close the connection
476474 if (res == -1 ) {
477- if (is_closed_conn (error)) {
475+ if (cb::net:: is_closed_conn (error)) {
478476 LOG_INFO (" {}: Failed to send data; peer closed the connection" ,
479477 getId ());
480478 } else {
481- log_socket_error (EXTENSION_LOG_WARNING, this ,
482- " Failed to write, and not due to blocking: %s " );
479+ LOG_WARNING ( " Failed to write, and not due to blocking: {} " ,
480+ cb_strerror (error) );
483481 }
484482 } else {
485483 // sendmsg should return the number of bytes written, but we
@@ -544,8 +542,8 @@ McbpConnection::TryReadResult McbpConnection::tryReadNetwork() {
544542 return TryReadResult::SocketClosed;
545543 }
546544
547- const auto error = GetLastNetworkError ();
548- if (is_blocking (error)) {
545+ const auto error = cb::net::get_socket_error ();
546+ if (cb::net:: is_blocking (error)) {
549547 return TryReadResult::NoDataReceived;
550548 }
551549
@@ -570,7 +568,7 @@ int McbpConnection::sslRead(char* dest, size_t nbytes) {
570568 int n;
571569 ssl.drainBioRecvPipe (socketDescriptor);
572570 if (ssl.hasError ()) {
573- set_econnreset ();
571+ cb::net:: set_econnreset ();
574572 return -1 ;
575573 }
576574 n = ssl.read (dest + ret, (int )(nbytes - ret));
@@ -593,7 +591,7 @@ int McbpConnection::sslRead(char* dest, size_t nbytes) {
593591 /* nothing in our recv buf, return what we have */
594592 return ret;
595593 } else {
596- set_ewouldblock ();
594+ cb::net:: set_ewouldblock ();
597595 return -1 ;
598596 }
599597 break ;
@@ -610,7 +608,7 @@ int McbpConnection::sslRead(char* dest, size_t nbytes) {
610608 LOG_WARNING (" {}: ERROR: SSL_read returned -1 with error {}" ,
611609 getId (),
612610 error);
613- set_econnreset ();
611+ cb::net:: set_econnreset ();
614612 return -1 ;
615613 }
616614 }
@@ -630,7 +628,7 @@ int McbpConnection::sslWrite(const char* src, size_t nbytes) {
630628
631629 ssl.drainBioSendPipe (socketDescriptor);
632630 if (ssl.hasError ()) {
633- set_econnreset ();
631+ cb::net:: set_econnreset ();
634632 return -1 ;
635633 }
636634
@@ -652,7 +650,7 @@ int McbpConnection::sslWrite(const char* src, size_t nbytes) {
652650 int error = ssl.getError (n);
653651 switch (error) {
654652 case SSL_ERROR_WANT_WRITE:
655- set_ewouldblock ();
653+ cb::net:: set_ewouldblock ();
656654 return -1 ;
657655
658656 default :
@@ -664,7 +662,7 @@ int McbpConnection::sslWrite(const char* src, size_t nbytes) {
664662 " {}: ERROR: SSL_write returned -1 with error {}" ,
665663 getId (),
666664 error);
667- set_econnreset ();
665+ cb::net:: set_econnreset ();
668666 return -1 ;
669667 }
670668 }
0 commit comments