[SERVER-10445] _bytesIn in Sock can get decremented Created: 06/Aug/13  Updated: 14/Apr/16  Resolved: 03/Aug/15

Status: Closed
Project: Core Server
Component/s: Networking
Affects Version/s: 2.5.1
Fix Version/s: None

Type: Bug Priority: Trivial - P5
Reporter: Randolph Tan Assignee: Calvin Chan
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Operating System: ALL
Participants:

 Description   

_recv can return -1 so it can decrement the value of _bytesIn. It is currently only being used for metrics.

    int Socket::unsafe_recv( char *buf, int max ) {
        int x = _recv( buf , max );
        _bytesIn += x;
        return x;
    }



 Comments   
Comment by Calvin Chan [ 03/Aug/15 ]

int Socket::_recv(char* buf, int max) {
int ret;
#ifdef MONGO_CONFIG_SSL
if (_sslConnection.get()) {
return _sslManager->SSL_read(_sslConnection.get(), buf, max);
#endif
int ret = ::recv(_fd, buf, max, portRecvFlags);
if (ret <= 0) {
handleRecvError(ret, max); // If no throw return and call _recv again
return 0;

The only case in which _recv will return a negative integer is if SSL_read returns a negative integer. SSL_read throws an exception if that is the case, so this works as designed

Generated at Thu Feb 08 03:23:11 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.