[complement-svn] SF.net SVN: complement: [1417] trunk/complement/explore
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2006-11-28 10:05:22
|
Revision: 1417 http://svn.sourceforge.net/complement/?rev=1417&view=rev Author: complement Date: 2006-11-28 02:05:20 -0800 (Tue, 28 Nov 2006) Log Message: ----------- delete Connect object after detect of channel closing, not near reuse point Modified Paths: -------------- trunk/complement/explore/include/sockios/sockmgr.cc trunk/complement/explore/test/libsockios/unit/unit_test.cc Modified: trunk/complement/explore/include/sockios/sockmgr.cc =================================================================== --- trunk/complement/explore/include/sockios/sockmgr.cc 2006-11-28 10:03:31 UTC (rev 1416) +++ trunk/complement/explore/include/sockios/sockmgr.cc 2006-11-28 10:05:20 UTC (rev 1417) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/27 17:13:31 ptr> +// -*- C++ -*- Time-stamp: <06/11/28 01:31:14 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 @@ -112,6 +112,8 @@ if ( (*i)->s->rdbuf()->fd() == -1 ) { (*i)->s->close(); (*i)->_proc->close(); + delete (*i)->_proc; + (*i)->_proc = 0; } } } else if ( j->revents & POLLERR /* | POLLHUP | POLLNVAL */ ) { @@ -121,6 +123,8 @@ j = _pfd.begin() + (d - 1); (*i)->s->close(); (*i)->_proc->close(); + delete (*i)->_proc; + (*i)->_proc = 0; } else { // Check that other side close socket: // on Linux and (?) Solaris I see normal POLLIN event, and see error @@ -136,6 +140,8 @@ j = _pfd.begin() + (d - 1); (*i)->s->close(); (*i)->_proc->close(); + delete (*i)->_proc; + (*i)->_proc = 0; } else { // normal data available for reading _dlock.lock(); _conn_pool.push_back( *i ); @@ -230,7 +236,7 @@ } else { // we can reuse old cl_new = *i; cl_new->s->open( _sd, addr.any ); - delete cl_new->_proc; // may be new ( cl_new->_proc ) Connect( *cl_new->s ); + // delete cl_new->_proc; // may be new ( cl_new->_proc ) Connect( *cl_new->s ); cl_new->_proc = new Connect( *cl_new->s ); if ( cl_new->s->rdbuf()->in_avail() > 0 ) { // this is the case when user read from sockstream @@ -362,8 +368,10 @@ (*i)->s->close(); (*i)->_proc->close(); } + delete (*i)->s; + (*i)->s = 0; delete (*i)->_proc; - delete (*i)->s; + (*i)->_proc = 0; } ::close( me->_cfd ); ::close( me->_pfd[1].fd ); @@ -388,8 +396,10 @@ (*i)->s->close(); (*i)->_proc->close(); } + delete (*i)->s; + (*i)->s = 0; delete (*i)->_proc; - delete (*i)->s; + (*i)->_proc = 0; } ::close( me->_cfd ); ::close( me->_pfd[1].fd ); @@ -434,6 +444,8 @@ if ( !stream->good() ) { stream->close(); c->_proc->close(); + delete c->_proc; + c->_proc = 0; } else if ( stream->is_open() ) { if ( stream->rdbuf()->in_avail() > 0 ) { // socket has buffered data, push it back to queue @@ -449,6 +461,8 @@ } else { stream->close(); c->_proc->close(); + delete c->_proc; + c->_proc = 0; } } } @@ -607,6 +621,8 @@ if ( (*i)->s->rdbuf()->fd() == -1 ) { (*i)->s->close(); (*i)->_proc->close(); + delete (*i)->_proc; + (*i)->_proc = 0; } } continue; @@ -615,6 +631,8 @@ // decrement of _fdmax may be here // --_fdcount; (*i)->s->close(); (*i)->_proc->close(); + delete (*i)->_proc; + (*i)->_proc = 0; continue; } else { // Check that other side close socket: @@ -629,6 +647,8 @@ // decrement of _fdmax may be here // --_fdcount; (*i)->s->close(); (*i)->_proc->close(); + delete (*i)->_proc; + (*i)->_proc = 0; continue; } } @@ -711,7 +731,7 @@ } else { // we can reuse old cl_new = *i; cl_new->s->open( _sd, addr.any ); - delete cl_new->_proc; // may be new ( cl_new->_proc ) Connect( *cl_new->s ); + // delete cl_new->_proc; // may be new ( cl_new->_proc ) Connect( *cl_new->s ); cl_new->_proc = new Connect( *cl_new->s ); } @@ -828,6 +848,8 @@ if ( !s->s->good() ) { s->s->close(); s->_proc->close(); + delete s->_proc; + s->_proc = 0; } } } @@ -840,6 +862,10 @@ (*i)->s->close(); (*i)->_proc->close(); } + delete (*i)->s; + (*i)->s = 0; + delete (*i)->_proc; + (*i)->_proc = 0; } me->close(); me->_c_lock.unlock(); @@ -855,6 +881,10 @@ (*i)->s->close(); (*i)->_proc->close(); } + delete (*i)->s; + (*i)->s = 0; + delete (*i)->_proc; + (*i)->_proc = 0; } me->close(); me->_c_lock.unlock(); Modified: trunk/complement/explore/test/libsockios/unit/unit_test.cc =================================================================== --- trunk/complement/explore/test/libsockios/unit/unit_test.cc 2006-11-28 10:03:31 UTC (rev 1416) +++ trunk/complement/explore/test/libsockios/unit/unit_test.cc 2006-11-28 10:05:20 UTC (rev 1417) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/10/10 21:00:28 ptr> +// -*- C++ -*- Time-stamp: <06/11/28 10:07:49 ptr> /* * @@ -355,6 +355,8 @@ void hostaddr_test1(); void hostaddr_test2(); void hostaddr_test3(); + + void ctor_dtor(); }; void sockios_test::hostname_test() @@ -463,6 +465,88 @@ #endif } +class Cnt +{ + public: + Cnt( sockstream& ) + { xmt::Locker lk(lock); ++cnt; } + + ~Cnt() + { xmt::Locker lk(lock); --cnt; } + + void connect( sockstream& ) + { } + + void close() + { } + + static xmt::Mutex lock; + static int cnt; +}; + +xmt::Mutex Cnt::lock; +int Cnt::cnt = 0; + +void sockios_test::ctor_dtor() +{ + // Check, that naumber of ctors of Cnt is the same as number of called dtors + // i.e. all created Cnt freed. + // due to async nature of communication, no way to check Cnt::cnt + // before server stop. + { + sockmgr_stream_MP<Cnt> srv( port ); + + { + sockstream s1( "localhost", port ); + + BOOST_CHECK( s1.good() ); + BOOST_CHECK( s1.is_open() ); + + s1 << "1234" << endl; + + BOOST_CHECK( s1.good() ); + BOOST_CHECK( s1.is_open() ); + } + + srv.close(); + srv.wait(); + + Cnt::lock.lock(); + BOOST_CHECK( Cnt::cnt == 0 ); + Cnt::lock.unlock(); + + } + { + sockmgr_stream_MP<Cnt> srv( port ); + + { + sockstream s1( "localhost", port ); + sockstream s2( "localhost", port ); + + BOOST_CHECK( s1.good() ); + BOOST_CHECK( s1.is_open() ); + BOOST_CHECK( s2.good() ); + BOOST_CHECK( s2.is_open() ); + + s1 << "1234" << endl; + s2 << "1234" << endl; + + BOOST_CHECK( s1.good() ); + BOOST_CHECK( s1.is_open() ); + BOOST_CHECK( s2.good() ); + BOOST_CHECK( s2.is_open() ); + } + + srv.close(); + srv.wait(); + + Cnt::lock.lock(); + BOOST_CHECK( Cnt::cnt == 0 ); + Cnt::lock.unlock(); + + } +} + struct sockios_test_suite : public test_suite { @@ -479,6 +563,7 @@ test_case *hostaddr1_tc = BOOST_CLASS_TEST_CASE( &sockios_test::hostaddr_test1, instance ); test_case *hostaddr2_tc = BOOST_CLASS_TEST_CASE( &sockios_test::hostaddr_test2, instance ); test_case *hostaddr3_tc = BOOST_CLASS_TEST_CASE( &sockios_test::hostaddr_test3, instance ); + test_case *ctor_dtor_tc = BOOST_CLASS_TEST_CASE( &sockios_test::ctor_dtor, instance ); // hostaddr2_tc->depends_on( hostaddr1_tc ); @@ -488,6 +573,7 @@ add( hostaddr1_tc ); add( hostaddr2_tc ); add( hostaddr3_tc ); + add( ctor_dtor_tc ); } test_suite *init_unit_test_suite( int argc, char **argv ) @@ -504,17 +590,17 @@ // ts->add( BOOST_TEST_CASE( &hostaddr_test3 ) ); ts->add( BOOST_TEST_CASE( &test_client_server_poll ) ); - ts->add( BOOST_TEST_CASE( &test_client_server_select ) ); + // ts->add( BOOST_TEST_CASE( &test_client_server_select ) ); ts->add( BOOST_TEST_CASE( &test_client_server_poll_nonlocal_ack ) ); ts->add( BOOST_TEST_CASE( &test_client_server_poll_nonlocal_nac ) ); ts->add( BOOST_TEST_CASE( &test_client_server_poll_local_ack ) ); - ts->add( BOOST_TEST_CASE( &test_client_server_select_nonlocal_ack ) ); - ts->add( BOOST_TEST_CASE( &test_client_server_select_nonlocal_nac ) ); + // ts->add( BOOST_TEST_CASE( &test_client_server_select_nonlocal_ack ) ); + // ts->add( BOOST_TEST_CASE( &test_client_server_select_nonlocal_nac ) ); - ts->add( BOOST_TEST_CASE( &test_client_server_select_local_ack ) ); + // ts->add( BOOST_TEST_CASE( &test_client_server_select_local_ack ) ); ts->add( BOOST_TEST_CASE( &test_mass_processing_poll ) ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |