[complement-svn] SF.net SVN: complement: [1621] trunk/complement/explore/test/sockios
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2007-07-18 09:27:12
|
Revision: 1621 http://svn.sourceforge.net/complement/?rev=1621&view=rev Author: complement Date: 2007-07-18 02:27:10 -0700 (Wed, 18 Jul 2007) Log Message: ----------- fix listen interfaces tests Modified Paths: -------------- trunk/complement/explore/test/sockios/ConnectionProcessor.cc trunk/complement/explore/test/sockios/ConnectionProcessor.h trunk/complement/explore/test/sockios/sockios_test_suite.cc Modified: trunk/complement/explore/test/sockios/ConnectionProcessor.cc =================================================================== --- trunk/complement/explore/test/sockios/ConnectionProcessor.cc 2007-07-18 06:29:40 UTC (rev 1620) +++ trunk/complement/explore/test/sockios/ConnectionProcessor.cc 2007-07-18 09:27:10 UTC (rev 1621) @@ -56,6 +56,40 @@ // ****************** +trivial_sockios_test::trivial_sockios_test() : + hostaddr( findhost( hostname().c_str() ) ) // take primary host IP +{ + // Oh, this trick not work well: hostname may be assigned to 127.0.0.1 too... + // I need list of interfaces... + + list<net_iface> ifaces; + try { + get_ifaces( ifaces ); + } + catch ( runtime_error& err ) { + EXAM_ERROR_ASYNC( err.what() ); + } + + list<net_iface>::const_iterator i; + for ( i = ifaces.begin(); i != ifaces.end(); ++i ) { + if ( i->name == "eth0" ) { + hostaddr = i->addr.inet.sin_addr; + // hostaddr = i->addr.any; // .inet.sin_addr; + break; + } + } + EXAM_CHECK_ASYNC( i != ifaces.end() ); + + for ( i = ifaces.begin(); i != ifaces.end(); ++i ) { + if ( i->name == "lo" ) { + localaddr = i->addr.inet.sin_addr; + // hostaddr = i->addr.any; // .inet.sin_addr; + break; + } + } + EXAM_CHECK_ASYNC( i != ifaces.end() ); +} + int EXAM_IMPL(trivial_sockios_test::simple) { #ifndef __FIT_NO_POLL @@ -93,6 +127,62 @@ // ****************** +int EXAM_IMPL(trivial_sockios_test::listen_iface) +{ +#ifndef __FIT_NO_POLL + try { + // server not listen localhost, but listen ext interface: + sockmgr_stream_MP<ConnectionProcessor> srv( hostaddr, port ); // start server + + EXAM_CHECK( srv.is_open() ); + EXAM_CHECK( srv.good() ); + + { + EXAM_MESSAGE( "Client start" ); + + // std::sockstream sock( hostname(hostaddr.s_addr).c_str(), ::port ); + // std::sockstream sock( (*(sockaddr_in *)&hostaddr).sin_addr, ::port ); + std::sockstream sock( hostaddr, ::port ); + string srv_line; + + EXAM_CHECK( sock.good() ); + + sock << ::message << endl; + + EXAM_CHECK( sock.good() ); + + // sock.clear(); + getline( sock, srv_line ); + + EXAM_CHECK( sock.good() ); + + EXAM_CHECK( srv_line == ::message_rsp ); + + EXAM_MESSAGE( "Client close connection (client's end of life)" ); + // sock.close(); // no needs, that will done in sock destructor + } + + { + std::sockstream sock( localaddr, ::port ); + + EXAM_CHECK( !sock.is_open() ); + } + + srv.close(); // close server, so we don't wait server termination on next line + srv.wait(); // Wait for server stop to serve clients connections + } + catch ( std::domain_error& err ) { + EXAM_ERROR( "host not found by name" ); + } +#else + EXAM_ERROR( "poll-based sockmgr not implemented on this platform" ); +#endif + + return EXAM_RESULT; +} + +// ****************** + ConnectionProcessor2::ConnectionProcessor2( std::sockstream& s ) : count( 0 ) { Modified: trunk/complement/explore/test/sockios/ConnectionProcessor.h =================================================================== --- trunk/complement/explore/test/sockios/ConnectionProcessor.h 2007-07-18 06:29:40 UTC (rev 1620) +++ trunk/complement/explore/test/sockios/ConnectionProcessor.h 2007-07-18 09:27:10 UTC (rev 1621) @@ -36,7 +36,15 @@ class trivial_sockios_test { public: + trivial_sockios_test(); + int EXAM_DECL(simple); + int EXAM_DECL(listen_iface); + + private: + in_addr hostaddr; + // sockaddr hostaddr; + in_addr localaddr; }; class ConnectionProcessor2 // Modified: trunk/complement/explore/test/sockios/sockios_test_suite.cc =================================================================== --- trunk/complement/explore/test/sockios/sockios_test_suite.cc 2007-07-18 06:29:40 UTC (rev 1620) +++ trunk/complement/explore/test/sockios/sockios_test_suite.cc 2007-07-18 09:27:10 UTC (rev 1621) @@ -29,179 +29,6 @@ using namespace std; -int EXAM_IMPL(test_client_server_poll_nonlocal_ack) -{ -#ifndef __FIT_NO_POLL - try { - - // Oh, this trick not work well: hostname may be assigned to 127.0.0.1 too... - // I need list of interfaces... - - // take primary host IP: - in_addr hostaddr( findhost( hostname().c_str() ) ); - list<net_iface> ifaces; - try { - get_ifaces( ifaces ); - } - catch ( runtime_error& err ) { - EXAM_ERROR( err.what() ); - } - - list<net_iface>::const_iterator i; - for ( i = ifaces.begin(); i != ifaces.end(); ++i ) { - if ( i->name == "eth0" ) { - hostaddr = i->addr.inet.sin_addr; - break; - } - } - EXAM_CHECK( i != ifaces.end() ); - - // server not listen localhost, but listen ext interface: - sockmgr_stream_MP<ConnectionProcessor> srv( hostaddr, port ); // start server - - EXAM_CHECK( srv.is_open() ); - EXAM_CHECK( srv.good() ); - - { - EXAM_MESSAGE( "Client start" ); - - // in_addr hostaddr( findhost( hostname().c_str() ) ); - sockaddr hostaddr; - - list<net_iface> ifaces; - try { - get_ifaces( ifaces ); - } - catch ( runtime_error& err ) { - EXAM_ERROR( err.what() ); - } - - list<net_iface>::const_iterator i; - for ( i = ifaces.begin(); i != ifaces.end(); ++i ) { - if ( i->name == "eth0" ) { - hostaddr = i->addr.any; // .inet.sin_addr; - break; - } - } - EXAM_CHECK( i != ifaces.end() ); - - // std::sockstream sock( hostname(hostaddr.s_addr).c_str(), ::port ); - std::sockstream sock( (*(sockaddr_in *)&hostaddr).sin_addr, ::port ); - string srv_line; - - EXAM_CHECK( sock.good() ); - - sock << ::message << endl; - - EXAM_CHECK( sock.good() ); - - // sock.clear(); - getline( sock, srv_line ); - - EXAM_CHECK( sock.good() ); - - EXAM_CHECK( srv_line == ::message_rsp ); - - EXAM_MESSAGE( "Client close connection (client's end of life)" ); - // sock.close(); // no needs, that will done in sock destructor - } - - srv.close(); // close server, so we don't wait server termination on next line - srv.wait(); // Wait for server stop to serve clients connections - } - catch ( std::domain_error& err ) { - EXAM_ERROR( "host not found by name" ); - } -#else - EXAM_ERROR( "poll-based sockmgr not implemented on this platform" ); -#endif - - return EXAM_RESULT; -} - -int EXAM_IMPL(test_client_server_poll_nonlocal_nac) -{ -#ifndef __FIT_NO_POLL - try { - // take primary host IP: - in_addr hostaddr( findhost( hostname().c_str() ) ); - list<net_iface> ifaces; - try { - get_ifaces( ifaces ); - } - catch ( runtime_error& err ) { - EXAM_ERROR( err.what() ); - } - - list<net_iface>::const_iterator i; - for ( i = ifaces.begin(); i != ifaces.end(); ++i ) { - if ( i->name == "eth0" ) { - hostaddr = i->addr.inet.sin_addr; - break; - } - } - EXAM_CHECK( i != ifaces.end() ); - - // server not listen localhost, but listen ext interface: - sockmgr_stream_MP<ConnectionProcessor> srv( hostaddr, port ); // start server - - { - EXAM_MESSAGE( "Client start" ); - - // in_addr hostaddr( findhost( hostname().c_str() ) ); - sockaddr hostaddr; - - list<net_iface> ifaces; - try { - get_ifaces( ifaces ); - } - catch ( runtime_error& err ) { - EXAM_ERROR( err.what() ); - } - - list<net_iface>::const_iterator i; - for ( i = ifaces.begin(); i != ifaces.end(); ++i ) { - if ( i->name == "eth0" ) { - hostaddr = i->addr.any; // .inet.sin_addr; - break; - } - } - EXAM_CHECK( i != ifaces.end() ); - - // std::sockstream sock( hostname(hostaddr.s_addr).c_str(), ::port ); - std::sockstream sock( (*(sockaddr_in *)&hostaddr).sin_addr, ::port ); - string srv_line; - - EXAM_CHECK( sock.good() ); - - sock << ::message << endl; - - EXAM_CHECK( sock.good() ); - - // sock.clear(); - getline( sock, srv_line ); - - EXAM_CHECK( sock.good() ); - - EXAM_CHECK( srv_line == ::message_rsp ); - - EXAM_MESSAGE( "Client close connection (client's end of life)" ); - // sock.close(); // no needs, that will done in sock destructor - } - - srv.close(); // close server, so we don't wait server termination on next line - srv.wait(); // Wait for server stop to serve clients connections - } - catch ( std::domain_error& err ) { - EXAM_ERROR( "host not found by name" ); - } -#else - EXAM_ERROR( "poll-based sockmgr not implemented on this platform" ); -#endif - - return EXAM_RESULT; -} - int EXAM_IMPL(test_client_server_poll_local_ack) { #ifndef __FIT_NO_POLL @@ -381,8 +208,7 @@ // Old tests - t.add( test_client_server_poll_nonlocal_ack, "test_client_server_poll_nonlocal_ack" ); - t.add( test_client_server_poll_nonlocal_nac, "test_client_server_poll_nonlocal_nac" ); + t.add( &trivial_sockios_test::listen_iface, trivial_test, "listen_iface", tc[0] ); t.add( test_client_server_poll_local_ack, "test_client_server_poll_local_ack" ); t.add( test_mass_processing_poll, "test_mass_processing_poll" ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |