You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@activemq.apache.org by Motl <mo...@orcsoftware.com> on 2007/04/23 14:56:07 UTC

SocketInputStream::read

>From SocketInputSream.cpp:

    int len = ::recv(socket, (char*)buffer, (int)bufferSize, 0);
    
    // Check for a closed socket.
    if( len == 0 ){
        throw IOException( __FILE__, __LINE__, 
            "activemq::io::SocketInputStream::read - The connection is
broken" );
    }
    
    // Check for error.
    if( len == -1 ){
        
        // Otherwise, this was a bad error - throw an exception.
        throw IOException( __FILE__, __LINE__, 
                "activemq::io::SocketInputStream::read - %s",
SocketError::getErrorString().c_str() );
    }

It's really worth to replace the condition check with smth like this:

while( errno == EINTR)
{
      int len = ::recv(socket, (char*)buffer, (int)bufferSize, 0);
    
    if( len == 0 ){
    ...
    }
    
    if( len == -1 ){
    ...
    }

}

The abov is needed to avoid the situation when blocking read() call was
failed due to interruption by a signal.

-- 
View this message in context: http://www.nabble.com/SocketInputStream%3A%3Aread-tf3631398s2354.html#a10139680
Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.


RE: SocketInputStream::read

Posted by "Mittler, Nathan" <na...@sensis.com>.
Great - thanks! 

> -----Original Message-----
> From: Motl [mailto:motl@orcsoftware.com] 
> Sent: Monday, April 23, 2007 9:55 AM
> To: dev@activemq.apache.org
> Subject: RE: SocketInputStream::read
> 
> 
> Done.
> 
> https://issues.apache.org/activemq/browse/AMQCPP-107
> 
> 
> Mittler, Nathan wrote:
> > 
> > Would you mind capturing this in a JIRA issue? 
> > 
> >> -----Original Message-----
> >> From: Motl [mailto:motl@orcsoftware.com]
> >> Sent: Monday, April 23, 2007 8:56 AM
> >> To: dev@activemq.apache.org
> >> Subject: SocketInputStream::read
> >> 
> >> 
> >> From SocketInputSream.cpp:
> >> 
> >>     int len = ::recv(socket, (char*)buffer, (int)bufferSize, 0);
> >>     
> >>     // Check for a closed socket.
> >>     if( len == 0 ){
> >>         throw IOException( __FILE__, __LINE__, 
> >>             "activemq::io::SocketInputStream::read - The 
> connection 
> >> is broken" );
> >>     }
> >>     
> >>     // Check for error.
> >>     if( len == -1 ){
> >>         
> >>         // Otherwise, this was a bad error - throw an exception.
> >>         throw IOException( __FILE__, __LINE__, 
> >>                 "activemq::io::SocketInputStream::read - %s",
> >> SocketError::getErrorString().c_str() );
> >>     }
> >> 
> >> It's really worth to replace the condition check with smth 
> like this:
> >> 
> >> while( errno == EINTR)
> >> {
> >>       int len = ::recv(socket, (char*)buffer, (int)bufferSize, 0);
> >>     
> >>     if( len == 0 ){
> >>     ...
> >>     }
> >>     
> >>     if( len == -1 ){
> >>     ...
> >>     }
> >> 
> >> }
> >> 
> >> The abov is needed to avoid the situation when blocking
> >> read() call was failed due to interruption by a signal.
> >> 
> >> --
> >> View this message in context: 
> >> http://www.nabble.com/SocketInputStream%3A%3Aread-tf3631398s23
> >> 54.html#a10139680
> >> Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.
> >> 
> >> 
> > 
> > 
> 
> --
> View this message in context: 
> http://www.nabble.com/SocketInputStream%3A%3Aread-tf3631398s23
> 54.html#a10140655
> Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.
> 
> 

RE: SocketInputStream::read

Posted by Motl <mo...@orcsoftware.com>.
Done.

https://issues.apache.org/activemq/browse/AMQCPP-107


Mittler, Nathan wrote:
> 
> Would you mind capturing this in a JIRA issue? 
> 
>> -----Original Message-----
>> From: Motl [mailto:motl@orcsoftware.com] 
>> Sent: Monday, April 23, 2007 8:56 AM
>> To: dev@activemq.apache.org
>> Subject: SocketInputStream::read
>> 
>> 
>> From SocketInputSream.cpp:
>> 
>>     int len = ::recv(socket, (char*)buffer, (int)bufferSize, 0);
>>     
>>     // Check for a closed socket.
>>     if( len == 0 ){
>>         throw IOException( __FILE__, __LINE__, 
>>             "activemq::io::SocketInputStream::read - The 
>> connection is broken" );
>>     }
>>     
>>     // Check for error.
>>     if( len == -1 ){
>>         
>>         // Otherwise, this was a bad error - throw an exception.
>>         throw IOException( __FILE__, __LINE__, 
>>                 "activemq::io::SocketInputStream::read - %s",
>> SocketError::getErrorString().c_str() );
>>     }
>> 
>> It's really worth to replace the condition check with smth like this:
>> 
>> while( errno == EINTR)
>> {
>>       int len = ::recv(socket, (char*)buffer, (int)bufferSize, 0);
>>     
>>     if( len == 0 ){
>>     ...
>>     }
>>     
>>     if( len == -1 ){
>>     ...
>>     }
>> 
>> }
>> 
>> The abov is needed to avoid the situation when blocking 
>> read() call was failed due to interruption by a signal.
>> 
>> --
>> View this message in context: 
>> http://www.nabble.com/SocketInputStream%3A%3Aread-tf3631398s23
>> 54.html#a10139680
>> Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/SocketInputStream%3A%3Aread-tf3631398s2354.html#a10140655
Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.


RE: SocketInputStream::read

Posted by "Mittler, Nathan" <na...@sensis.com>.
Would you mind capturing this in a JIRA issue? 

> -----Original Message-----
> From: Motl [mailto:motl@orcsoftware.com] 
> Sent: Monday, April 23, 2007 8:56 AM
> To: dev@activemq.apache.org
> Subject: SocketInputStream::read
> 
> 
> From SocketInputSream.cpp:
> 
>     int len = ::recv(socket, (char*)buffer, (int)bufferSize, 0);
>     
>     // Check for a closed socket.
>     if( len == 0 ){
>         throw IOException( __FILE__, __LINE__, 
>             "activemq::io::SocketInputStream::read - The 
> connection is broken" );
>     }
>     
>     // Check for error.
>     if( len == -1 ){
>         
>         // Otherwise, this was a bad error - throw an exception.
>         throw IOException( __FILE__, __LINE__, 
>                 "activemq::io::SocketInputStream::read - %s",
> SocketError::getErrorString().c_str() );
>     }
> 
> It's really worth to replace the condition check with smth like this:
> 
> while( errno == EINTR)
> {
>       int len = ::recv(socket, (char*)buffer, (int)bufferSize, 0);
>     
>     if( len == 0 ){
>     ...
>     }
>     
>     if( len == -1 ){
>     ...
>     }
> 
> }
> 
> The abov is needed to avoid the situation when blocking 
> read() call was failed due to interruption by a signal.
> 
> --
> View this message in context: 
> http://www.nabble.com/SocketInputStream%3A%3Aread-tf3631398s23
> 54.html#a10139680
> Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.
> 
>