0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-30 09:06:21 +01:00

SERVER-109 reinstate sendmsg

This commit is contained in:
Aaron 2010-05-17 10:02:02 -07:00
parent a1ecb4c448
commit 14114b403e
2 changed files with 33 additions and 63 deletions

View File

@ -462,24 +462,23 @@ namespace mongo {
}
send( (char*)toSend.singleData(), toSend.header()->len, "say" );
// vector< pair< char *, int > > all = toSend.allData();
// vector< struct iovec > d( all.size() );
// for( unsigned i = 0; i < all.size(); ++i ) {
// d[ i ].iov_base = all[ i ].first;
// d[ i ].iov_len = all[ i ].second;
// }
// struct msghdr meta;
// memset( &meta, 0, sizeof( meta ) );
// meta.msg_iov = &d[ 0 ];
// meta.msg_iovlen = d.size();
// send( meta, "say" );
send( toSend.allData(), "say" );
}
// sends all data or throws an exception
void MessagingPort::send( const char * data , int len, const char *context ){
while( len > 0 ) {
int ret = ::send( sock , data , len , portSendFlags );
void MessagingPort::send( const vector< pair< char *, int > > &data, const char *context ){
vector< struct iovec > d( data.size() );
for( unsigned i = 0; i < data.size(); ++i ) {
d[ i ].iov_base = data[ i ].first;
d[ i ].iov_len = data[ i ].second;
}
struct msghdr meta;
memset( &meta, 0, sizeof( meta ) );
meta.msg_iov = &d[ 0 ];
meta.msg_iovlen = d.size();
while( meta.msg_iovlen > 0 ) {
int ret = ::sendmsg( sock , &meta , portSendFlags );
if ( ret == -1 ) {
if ( errno != EAGAIN || _timeout == 0 ) {
log(_logLevel) << "MessagingPort " << context << " send() " << errnoWithDescription() << ' ' << farEnd.toString() << endl;
@ -491,56 +490,22 @@ namespace mongo {
}
}
} else {
assert( ret <= len );
len -= ret;
data += ret;
struct iovec *& i = meta.msg_iov;
while( ret > 0 ) {
if ( i->iov_len > unsigned( ret ) ) {
i->iov_len -= ret;
i->iov_base = (char*)(i->iov_base) + ret;
ret = 0;
} else {
ret -= i->iov_len;
++i;
--(meta.msg_iovlen);
}
}
}
}
}
// void MessagingPort::send( const char * data , int len, const char *context ){
// struct iovec d;
// d.iov_base = const_cast< char * >( data );
// d.iov_len = len;
// struct msghdr meta;
// memset( &meta, 0, sizeof( meta ) );
// meta.msg_iov = &d;
// meta.msg_iovlen = 1;
// send( meta, context );
// }
//
// // sends all data or throws an exception
// // the meta argument may be modified
// void MessagingPort::send( struct msghdr &meta, const char *context ){
// while( meta.msg_iovlen > 0 ) {
// int ret = ::sendmsg( sock , &meta , portSendFlags );
// if ( ret == -1 ) {
// if ( errno != EAGAIN || _timeout == 0 ) {
// log(_logLevel) << "MessagingPort " << context << " send() " << errnoWithDescription() << ' ' << farEnd.toString() << endl;
// throw SocketException();
// } else {
// if ( !serverAlive( farEnd.toString() ) ) {
// log(_logLevel) << "MessagingPort " << context << " send() remote dead " << farEnd.toString() << endl;
// throw SocketException();
// }
// }
// } else {
// struct iovec *& i = meta.msg_iov;
// while( ret > 0 ) {
// if ( i->iov_len > unsigned( ret ) ) {
// i->iov_len -= ret;
// i->iov_base += ret;
// ret = 0;
// } else {
// ret -= i->iov_len;
// ++i;
// --(meta.msg_iovlen);
// }
// }
// }
// }
// }
void MessagingPort::recv( char * buf , int len ){
while( len > 0 ) {
int ret = ::recv( sock , buf , len , portRecvFlags );

View File

@ -89,8 +89,13 @@ namespace mongo {
virtual HostAndPort remote() const;
// send len or throw SocketException
void send( const char * data , int len, const char *context );
// void send( struct msghdr &meta, const char *context );
void send( const char * data , int len, const char *context ) {
vector< pair< char *, int > > temp;
temp.push_back( make_pair( const_cast< char * >( data ), len ) );
send( temp, context );
}
void send( const vector< pair< char *, int > > &data, const char *context );
// recv len or throw SocketException
void recv( char * data , int len );