From: Guilherme Maciel Ferreira Date: Sat, 13 Aug 2011 00:42:05 +0000 (-0300) Subject: Surrounded the receive by a try..catch, so prepare to receive another packet only... X-Git-Tag: v1.1^2~23 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=b23911dd295e94ab851e36a16cf2950a030eadfd;p=pingcheck Surrounded the receive by a try..catch, so prepare to receive another packet only if the reply isn't a RST --- diff --git a/src/tcp/tcppinger.cpp b/src/tcp/tcppinger.cpp index ca22f07..b5247d5 100644 --- a/src/tcp/tcppinger.cpp +++ b/src/tcp/tcppinger.cpp @@ -292,35 +292,45 @@ void TcpPinger::handle_receive_tcp_segment( const size_t &bytes_transferred ) // can extract it using a std::istream object. ReplyBuffer.commit( bytes_transferred ); - istream is( &ReplyBuffer ); - if ( !is ) + try { - GlobalLogger.error() << "Error: can't handle ReplyBuffer" << endl; - return; - } + istream is( &ReplyBuffer ); + if ( !is ) + { + GlobalLogger.error() << "Error: can't handle ReplyBuffer" << endl; + return; + } - Ipv4Header ipv4_header; - TcpHeader tcp_header; - is >> ipv4_header >> tcp_header; + Ipv4Header ipv4_header; + TcpHeader tcp_header; + is >> ipv4_header >> tcp_header; - // filter out only the TCP reset (RST) replies. Note that the sequence - // number from RST does not match the sent ACK's sequence number. - if ( is && - tcp_header.reset() && - ipv4_header.get_source_address() == DestinationEndpoint.address() ) - { - ReceivedReply = true; + // filter out only the TCP reset (RST) replies. Note that the sequence + // number from RST does not match the sent ACK's sequence number. + if ( is && + tcp_header.reset() && + ipv4_header.get_source_address() == DestinationEndpoint.address() ) + { + ReceivedReply = true; - print_rst_reply( ipv4_header, tcp_header ); + print_rst_reply( ipv4_header, tcp_header ); - set_ping_status( PingStatus_SuccessReply ); + set_ping_status( PingStatus_SuccessReply ); - TcpSegmentReceiveTimer.cancel(); + TcpSegmentReceiveTimer.cancel(); + } + // Unknown TCP reply, start another receive till timeout + else + { + start_receive(); + } + } + catch ( ... ) + { + GlobalLogger.notice() << "Warning: exception during ICMP parse. " + << "Starting another receive till timeout." << endl; + start_receive(); } - - // TODO need to be in the catch or else? - // TODO why does the ping fail? Does the callback receive false? - start_receive(); } /**