Always use non-blocking sockets for recvmsg()
This commit is contained in:
@@ -435,14 +435,12 @@ string Connection::recv( void )
|
|||||||
for ( std::deque< Socket >::const_iterator it = socks.begin();
|
for ( std::deque< Socket >::const_iterator it = socks.begin();
|
||||||
it != socks.end();
|
it != socks.end();
|
||||||
it++ ) {
|
it++ ) {
|
||||||
bool islast = (it + 1) == socks.end();
|
|
||||||
string payload;
|
string payload;
|
||||||
try {
|
try {
|
||||||
payload = recv_one( it->fd(), !islast );
|
payload = recv_one( it->fd());
|
||||||
} catch ( NetworkException & e ) {
|
} catch ( NetworkException & e ) {
|
||||||
if ( (e.the_errno == EAGAIN)
|
if ( (e.the_errno == EAGAIN)
|
||||||
|| (e.the_errno == EWOULDBLOCK) ) {
|
|| (e.the_errno == EWOULDBLOCK) ) {
|
||||||
assert( !islast );
|
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
throw;
|
throw;
|
||||||
@@ -456,7 +454,7 @@ string Connection::recv( void )
|
|||||||
throw NetworkException( "No packet received" );
|
throw NetworkException( "No packet received" );
|
||||||
}
|
}
|
||||||
|
|
||||||
string Connection::recv_one( int sock_to_recv, bool nonblocking )
|
string Connection::recv_one( int sock_to_recv )
|
||||||
{
|
{
|
||||||
/* receive source address, ECN, and payload in msghdr structure */
|
/* receive source address, ECN, and payload in msghdr structure */
|
||||||
Addr packet_remote_addr;
|
Addr packet_remote_addr;
|
||||||
@@ -483,7 +481,7 @@ string Connection::recv_one( int sock_to_recv, bool nonblocking )
|
|||||||
/* receive flags */
|
/* receive flags */
|
||||||
header.msg_flags = 0;
|
header.msg_flags = 0;
|
||||||
|
|
||||||
ssize_t received_len = recvmsg( sock_to_recv, &header, nonblocking ? MSG_DONTWAIT : 0 );
|
ssize_t received_len = recvmsg( sock_to_recv, &header, MSG_DONTWAIT );
|
||||||
|
|
||||||
if ( received_len < 0 ) {
|
if ( received_len < 0 ) {
|
||||||
throw NetworkException( "recvmsg", errno );
|
throw NetworkException( "recvmsg", errno );
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ namespace Network {
|
|||||||
|
|
||||||
void prune_sockets( void );
|
void prune_sockets( void );
|
||||||
|
|
||||||
string recv_one( int sock_to_recv, bool nonblocking );
|
string recv_one( int sock_to_recv );
|
||||||
|
|
||||||
void set_MTU( int family );
|
void set_MTU( int family );
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user