[complement-svn] SF.net SVN: complement: [1310] trunk/explore
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2006-10-10 18:14:10
|
Revision: 1310 http://svn.sourceforge.net/complement/?rev=1310&view=rev Author: complement Date: 2006-10-10 11:13:50 -0700 (Tue, 10 Oct 2006) Log Message: ----------- remove SessionMgr---it not used anyway. This functionality should be reimplemented in different manner. Modified Paths: -------------- trunk/explore/include/stem/EvManager.h trunk/explore/include/stem/EventHandler.h trunk/explore/include/stem/NetTransport.h trunk/explore/lib/stem/ChangeLog trunk/explore/lib/stem/EvManager.cc trunk/explore/lib/stem/NetTransport.cc trunk/explore/lib/stem/_EventHandler.cc trunk/explore/test/libstem/unit/Makefile.inc trunk/explore/test/libstem/unit/unit_test.cc Added Paths: ----------- trunk/explore/test/libstem/unit/Echo.cc trunk/explore/test/libstem/unit/Echo.h Modified: trunk/explore/include/stem/EvManager.h =================================================================== --- trunk/explore/include/stem/EvManager.h 2006-10-10 18:04:29 UTC (rev 1309) +++ trunk/explore/include/stem/EvManager.h 2006-10-10 18:13:50 UTC (rev 1310) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/09/30 09:42:35 ptr> +// -*- C++ -*- Time-stamp: <06/10/10 18:11:49 ptr> /* * Copyright (c) 1995-1999, 2002, 2003, 2005, 2006 @@ -134,7 +134,6 @@ return unsafe_annotate( id ); } - __FIT_DECLSPEC key_type sid( addr_type object_id ) const; __FIT_DECLSPEC NetTransport_base *transport( addr_type object_id ) const; void push( const Event& e ) Modified: trunk/explore/include/stem/EventHandler.h =================================================================== --- trunk/explore/include/stem/EventHandler.h 2006-10-10 18:04:29 UTC (rev 1309) +++ trunk/explore/include/stem/EventHandler.h 2006-10-10 18:13:50 UTC (rev 1310) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/06/28 15:08:43 ptr> +// -*- C++ -*- Time-stamp: <06/10/10 18:12:54 ptr> /* * Copyright (c) 1995-1999, 2002, 2003, 2005, 2006 @@ -601,7 +601,6 @@ __FIT_DECLSPEC const string& who_is( addr_type k ) const; __FIT_DECLSPEC bool is_avail( addr_type id ) const; - __FIT_DECLSPEC key_type sid( addr_type k ) const; static EvManager *manager() { return _mgr; } __FIT_DECLSPEC void Send( const Event& e ); Modified: trunk/explore/include/stem/NetTransport.h =================================================================== --- trunk/explore/include/stem/NetTransport.h 2006-10-10 18:04:29 UTC (rev 1309) +++ trunk/explore/include/stem/NetTransport.h 2006-10-10 18:13:50 UTC (rev 1310) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/10/06 19:39:22 ptr> +// -*- C++ -*- Time-stamp: <06/10/10 18:09:19 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 @@ -56,7 +56,6 @@ NetTransport_base() : _count( 0 ), - _sid( badkey ), net( 0 ), _net_ns( badaddr ) { } @@ -64,7 +63,6 @@ NetTransport_base( const char *info ) : EventHandler( info ), _count( 0 ), - _sid( badkey ), net( 0 ), _net_ns( badaddr ) { } @@ -85,54 +83,19 @@ __FIT_DECLSPEC addr_type make_map( addr_type k, const char *name ); - EvSessionManager::key_type sid() const - { return _sid; } - addr_type ns() const { return _net_ns; } - static stem::SessionInfo session_info( const EvSessionManager::key_type& k ) - { - smgr.lock(); - stem::SessionInfo si( smgr[k] ); - smgr.unlock(); - return si; - } - - static void session_control( const EvSessionManager::key_type& k, - const stem::addr_type& a ) - { - smgr.lock(); - smgr[k]._control = a; - smgr.unlock(); - } - - static std::string session_host( const EvSessionManager::key_type& k ) - { - smgr.lock(); - std::string h( smgr[k]._host ); - smgr.unlock(); - return h; - } - - static void erase_session( const EvSessionManager::key_type& k ) - { smgr.erase( k ); } - protected: - void establish_session( std::sockstream& s ) throw (std::domain_error); - void mark_session_onoff( bool ); addr_type rar_map( addr_type k, const std::string& name ); bool pop( Event& ); - void disconnect(); std::sockstream *net; - EvSessionManager::key_type _sid; uint32_t _count; // indeed rar can be inside connect(), but SunPro's CC 5.0 // to be very huffy about it. heap_type rar; // reverce address resolution table addr_type _net_ns; // reflection of address of remote name service - static __FIT_DECLSPEC EvSessionManager smgr; }; class NetTransport : @@ -179,7 +142,7 @@ public: NetTransportMP( std::sockstream& s ) : NetTransport_base( "stem::NetTransportMP" ) - { this->connect( s ); } + { net = &s; } __FIT_DECLSPEC void connect( std::sockstream& ); Modified: trunk/explore/lib/stem/ChangeLog =================================================================== --- trunk/explore/lib/stem/ChangeLog 2006-10-10 18:04:29 UTC (rev 1309) +++ trunk/explore/lib/stem/ChangeLog 2006-10-10 18:13:50 UTC (rev 1310) @@ -1,3 +1,11 @@ +2006-10-10 Petr Ovtchenkov <pt...@is...> + + * NetTransport.h, EventHandler.h, EvManager.h: remove + SessionMgr---it not used anyway. This functionality + should be reimplemented in different manner. + + * _EventHandler.cc, NetTransport.cc, EvManager.cc: ditto. + 2006-10-06 Petr Ovtchenkov <pt...@is...> * NetTransport.h, NetTransport.cc: move make_map Modified: trunk/explore/lib/stem/EvManager.cc =================================================================== --- trunk/explore/lib/stem/EvManager.cc 2006-10-10 18:04:29 UTC (rev 1309) +++ trunk/explore/lib/stem/EvManager.cc 2006-10-10 18:13:50 UTC (rev 1310) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/09/30 09:43:12 ptr> +// -*- C++ -*- Time-stamp: <06/10/10 18:11:29 ptr> /* * @@ -228,18 +228,6 @@ } } -// return session id of object with address 'id' if this is external -// object; otherwise return -1; -__FIT_DECLSPEC key_type EvManager::sid( addr_type id ) const -{ - MT_REENTRANT( _lock_heap, _x1 ); - heap_type::const_iterator i = heap.find( id ); - if ( i == heap.end() || (*i).second.remote == 0 ) { - return badkey; - } - return (*i).second.remote->channel->sid(); -} - __FIT_DECLSPEC NetTransport_base *EvManager::transport( addr_type id ) const { MT_REENTRANT( _lock_heap, _x1 ); Modified: trunk/explore/lib/stem/NetTransport.cc =================================================================== --- trunk/explore/lib/stem/NetTransport.cc 2006-10-10 18:04:29 UTC (rev 1309) +++ trunk/explore/lib/stem/NetTransport.cc 2006-10-10 18:13:50 UTC (rev 1310) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/10/06 19:40:42 ptr> +// -*- C++ -*- Time-stamp: <06/10/10 18:15:52 ptr> /* * @@ -90,42 +90,6 @@ } } -__FIT_DECLSPEC EvSessionManager NetTransport_base::smgr; - -void NetTransport_base::disconnect() -{ - if ( _sid == badkey ) { - _count = 0; - return; - } - try { - smgr.lock(); - if ( smgr.unsafe_is_avail( _sid ) ) { - SessionInfo& info = smgr[_sid]; - info.disconnect(); -// cerr << "EvManager::disconnect: " << _sid << endl; - if ( info._control != badaddr ) { - Event_base<key_type> ev_disconnect( EV_EDS_DISCONNECT, _sid ); - ev_disconnect.dest( info._control ); - _sid = badkey; - _count = 0; - smgr.unlock(); -// cerr << "EvManager::disconnect, info._control: " << info._control << endl; - Send( Event_convert<key_type>()(ev_disconnect) ); -// cerr << "===== Pass" << endl; - return; // required: smgr.unlock() done. - } - smgr.unsafe_erase( _sid ); - } - _sid = badkey; - _count = 0; - smgr.unlock(); - } - catch ( ... ) { - smgr.unlock(); - } -} - __FIT_DECLSPEC NetTransport_base::~NetTransport_base() { NetTransport_base::close(); @@ -136,7 +100,6 @@ // cerr << __FILE__ << ":" << __LINE__ << endl; if ( net != 0 ) { manager()->Remove( this ); - disconnect(); rar.clear(); net->close(); // cerr << __FILE__ << ":" << __LINE__ << endl; @@ -144,32 +107,6 @@ } } -__FIT_DECLSPEC -void NetTransport_base::establish_session( std::sockstream& s ) throw (std::domain_error) -{ - smgr.lock(); - _sid = smgr.unsafe_create(); - if ( _sid == badkey ) { - smgr.unlock(); - throw std::domain_error( "bad session id" ); - } - smgr[_sid]._host = hostname( s.rdbuf()->inet_addr() ); - smgr[_sid]._port = s.rdbuf()->port(); - smgr.unlock(); -} - -void NetTransport_base::mark_session_onoff( bool f ) -{ - smgr.lock(); - if ( smgr.unsafe_is_avail( _sid ) ) { - if ( f ) - smgr[ _sid ].connect(); - else - smgr[ _sid ].disconnect(); - } - smgr.unlock(); -} - const string __ns_at( "ns@" ); const string __at( "@" ); @@ -196,7 +133,6 @@ MT_IO_REENTRANT( *net ) if ( !net->read( (char *)buf, sizeof(uint32_t) ).good() ) { - // cerr << __FILE__ << ":" << __LINE__ << endl; return false; } // cerr << __FILE__ << ":" << __LINE__ << endl; @@ -247,21 +183,6 @@ #endif } - if ( _sid != badkey ) { - smgr.lock(); - if ( smgr.unsafe_is_avail( _sid ) ) { - SessionInfo& sess = smgr[_sid]; - sess.inc_from( 8 * sizeof(uint32_t) + str.size() ); - if ( sess._un_from != _x_count ) { - cerr << "EDS Incoming event(s) lost, or missrange event: " << sess._un_from - << ", " << _x_count << " (Session: " << _sid << ") --- "; - cerr << endl; - sess._un_from = _x_count; // Retransmit? - } - } - smgr.unlock(); - } - return net->good(); } @@ -270,7 +191,7 @@ bool NetTransport_base::push( const Event& _rs ) { // _STLP_ASSERT( net != 0 ); - if ( _sid == badkey || !net->good() ) { + if ( !net->good() ) { return false; } uint32_t buf[8]; @@ -296,26 +217,13 @@ ostream_iterator<char,char,char_traits<char> >(*net) ); net->flush(); - if ( _sid != badkey && net->good() ) { - smgr.lock(); - if ( smgr.unsafe_is_avail( _sid ) ) { - SessionInfo& sess = smgr[_sid]; - sess.inc_to( 8 * sizeof(uint32_t) + _rs.value().size() ); - if ( sess._un_to != _count ) { - cerr << "Outgoing event(s) lost, or missrange event: " << sess._un_to - << ", " << _count << " (Session " << _sid << ")" << endl; - // kill( getpid(), SIGQUIT ); - } - } - smgr.unlock(); - } else { + if ( !net->good() ) { throw ios_base::failure( "net not good" ); } } catch ( ios_base::failure& ) { if ( net != 0 ) { // clear connection: required by non-Solaris OS - disconnect(); // for MP connection policy - rar.clear(); + rar.clear(); // for MP connection policy net->close(); } } @@ -348,7 +256,6 @@ _at_hostname = __at + _hostname; try { - establish_session( s ); _net_ns = rar_map( ns_addr, __ns_at + _hostname ); } catch ( std::domain_error& ex ) { @@ -372,8 +279,6 @@ } catch ( ... ) { s.close(); - // disconnect(); - // throw; } // cerr << "Disconnected" << endl; } @@ -419,7 +324,6 @@ if ( net->good() ) { _net_ns = rar_map( ns_addr, __ns_at + hostname ); addr_type zero_object = rar_map( 0, __at + hostname ); - _sid = smgr.create(); _thr.launch( _loop, this, 0, PTHREAD_STACK_MIN * 2 ); // start thread here return zero_object; } @@ -472,21 +376,12 @@ void NetTransportMP::connect( sockstream& s ) { const string& _hostname = hostname( s.rdbuf()->inet_addr() ); - bool sock_dgr = (s.rdbuf()->stype() == std::sock_base::sock_stream) ? false : true; + // bool sock_dgr = (s.rdbuf()->stype() == std::sock_base::sock_stream) ? false : true; Event ev; // cerr << "Connected: " << _hostname << endl; try { - if ( _sid == badkey ) { - establish_session( s ); - net = &s; - } else if ( sock_dgr /* && _sid != badkey */ ) { - mark_session_onoff( true ); - } - // indeed here need more check: data of event - // and another: message can be break, and other datagram can be - // in the middle of message... if ( pop( ev ) ) { ev.src( rar_map( ev.src(), __at + _hostname ) ); // substitute my local id manager()->push( ev ); @@ -494,9 +389,6 @@ if ( !s.good() ) { throw ios_base::failure( "sockstream not good" ); } - if ( sock_dgr && _sid != badkey ) { - mark_session_onoff( false ); - } } catch ( ... ) { this->close(); // clear connection Modified: trunk/explore/lib/stem/_EventHandler.cc =================================================================== --- trunk/explore/lib/stem/_EventHandler.cc 2006-10-10 18:04:29 UTC (rev 1309) +++ trunk/explore/lib/stem/_EventHandler.cc 2006-10-10 18:13:50 UTC (rev 1310) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/09/30 09:44:46 ptr> +// -*- C++ -*- Time-stamp: <06/10/10 18:12:26 ptr> /* * Copyright (c) 1995-1999, 2002, 2003, 2005, 2006 @@ -71,12 +71,6 @@ } __FIT_DECLSPEC -key_type EventHandler::sid( addr_type k ) const -{ - return _mgr->sid( k ); -} - -__FIT_DECLSPEC void EventHandler::Send( const Event& e ) { e.src( _id ); Added: trunk/explore/test/libstem/unit/Echo.cc =================================================================== --- trunk/explore/test/libstem/unit/Echo.cc (rev 0) +++ trunk/explore/test/libstem/unit/Echo.cc 2006-10-10 18:13:50 UTC (rev 1310) @@ -0,0 +1,98 @@ +// -*- C++ -*- Time-stamp: <06/10/10 22:07:21 ptr> + +/* + * Copyright (c) 2006 + * Petr Ovtchenkov + * + * Licensed under the Academic Free License version 3.0 + * + */ + +#include "Echo.h" + +#include <stem/NetTransport.h> +#include <stem/EvManager.h> + +#include <boost/test/unit_test.hpp> + +using namespace boost::unit_test_framework; + +using namespace stem; + +StEMecho::StEMecho() +{ +} + +StEMecho::StEMecho( addr_type id ) : + EventHandler( id ) +{ +} + +StEMecho::StEMecho( addr_type id, const char *info ) : + EventHandler( id, info ) +{ +} + +void StEMecho::echo( const Event& ev ) +{ + Event eev( ev.code() ); + eev.value() = ev.value(); + + eev.dest( ev.src() ); + + Send( eev ); +} + +void StEMecho::regme( const stem::Event& ev ) +{ + stem::NetTransport_base *b = manager()->transport( ev.src() ); + if ( b != 0 ) { + b->make_map( ev.src(), (ev.value() /* + who_is( ev.src() ) */ ).c_str() ); + } +} + +DEFINE_RESPONSE_TABLE( StEMecho ) + EV_EDS( 0, NODE_EV_ECHO, echo ) + EV_EDS( 0, 0x5001, regme ) +END_RESPONSE_TABLE + +EchoClient::EchoClient() : + EventHandler(), + mess( "echo string" ) +{ + cnd.set( false ); +} + +EchoClient::EchoClient( stem::addr_type id ) : + EventHandler( id ), + mess( "echo string" ) +{ + cnd.set( false ); +} + +EchoClient::EchoClient( stem::addr_type id, const char *info ) : + EventHandler( id, info ), + mess( "echo string" ) +{ + cnd.set( false ); +} + +EchoClient::~EchoClient() +{ + // cnd.wait(); +} + +void EchoClient::handler1( const stem::Event& ev ) +{ + BOOST_CHECK( ev.value() == mess ); + cnd.set(true); +} + +void EchoClient::wait() +{ + cnd.try_wait(); +} + +DEFINE_RESPONSE_TABLE( EchoClient ) + EV_EDS(0,NODE_EV_ECHO,handler1) +END_RESPONSE_TABLE Added: trunk/explore/test/libstem/unit/Echo.h =================================================================== --- trunk/explore/test/libstem/unit/Echo.h (rev 0) +++ trunk/explore/test/libstem/unit/Echo.h 2006-10-10 18:13:50 UTC (rev 1310) @@ -0,0 +1,58 @@ +// -*- C++ -*- Time-stamp: <06/10/10 15:42:36 ptr> + +/* + * Copyright (c) 2006 + * Petr Ovtchenkov + * + * Licensed under the Academic Free License version 3.0 + * + */ + +#ifndef __Echo_h +#define __Echo_h + +#include <string> +#include <mt/xmt.h> +#include <stem/EventHandler.h> +// #include <stem/Names.h> +// #include <list> + +class StEMecho : + public stem::EventHandler +{ + public: + StEMecho(); + StEMecho( stem::addr_type id ); + StEMecho( stem::addr_type id, const char * ); + + void echo( const stem::Event& ); + void regme( const stem::Event& ); + + private: + DECLARE_RESPONSE_TABLE( StEMecho, stem::EventHandler ); +}; + +class EchoClient : + public stem::EventHandler +{ + public: + EchoClient(); + EchoClient( stem::addr_type id ); + EchoClient( stem::addr_type id, const char *info ); + ~EchoClient(); + + void handler1( const stem::Event& ); + + void wait(); + + const std::string mess; + + private: + xmt::Condition cnd; + + DECLARE_RESPONSE_TABLE( EchoClient, stem::EventHandler ); +}; + +#define NODE_EV_ECHO 0x903 + +#endif // __Echo_h Modified: trunk/explore/test/libstem/unit/Makefile.inc =================================================================== --- trunk/explore/test/libstem/unit/Makefile.inc 2006-10-10 18:04:29 UTC (rev 1309) +++ trunk/explore/test/libstem/unit/Makefile.inc 2006-10-10 18:13:50 UTC (rev 1310) @@ -1,7 +1,7 @@ -# -*- makefile -*- Time-stamp: <06/09/29 22:09:31 ptr> +# -*- makefile -*- Time-stamp: <06/10/10 15:22:33 ptr> PRGNAME = stem_ut SRC_CC = unit_test.cc \ Node.cc \ - NameService.cc - + NameService.cc \ + Echo.cc Modified: trunk/explore/test/libstem/unit/unit_test.cc =================================================================== --- trunk/explore/test/libstem/unit/unit_test.cc 2006-10-10 18:04:29 UTC (rev 1309) +++ trunk/explore/test/libstem/unit/unit_test.cc 2006-10-10 18:13:50 UTC (rev 1310) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/10/04 11:18:42 ptr> +// -*- C++ -*- Time-stamp: <06/10/10 16:49:12 ptr> /* * Copyright (c) 2002, 2003, 2006 @@ -25,6 +25,10 @@ #include <dlfcn.h> +#include "Echo.h" +#include <stem/NetTransport.h> +#include <sockios/sockmgr.h> + using namespace std; struct stem_test @@ -37,6 +41,8 @@ void ns(); void ns1(); + void echo(); + static xmt::Thread::ret_code thr1( void * ); static xmt::Thread::ret_code thr1new( void * ); }; @@ -302,6 +308,41 @@ BOOST_CHECK( nm.lst1.empty() ); } +void stem_test::echo() +{ + try { + sockmgr_stream_MP<stem::NetTransport> srv( 6995 ); + stem::NetTransportMgr mgr; + + StEMecho echo( 0, "echo service"); // <= zero! + + stem::addr_type zero = mgr.open( "localhost", 6995 ); + + BOOST_CHECK( zero != stem::badaddr ); + BOOST_CHECK( zero != 0 ); + + EchoClient node; + + EDS::Event ev( NODE_EV_ECHO ); + + ev.dest( zero ); + ev.value() = node.mess; + + node.Send( ev ); + + node.wait(); + + mgr.close(); + // mgr.join(); + + srv.close(); + srv.wait(); + } + catch ( ... ) { + } + // cerr << "Fine\n"; +} + struct stem_test_suite : public test_suite { @@ -321,6 +362,7 @@ test_case *dl_tc = BOOST_CLASS_TEST_CASE( &stem_test::dl, instance ); test_case *ns_tc = BOOST_CLASS_TEST_CASE( &stem_test::ns, instance ); test_case *ns1_tc = BOOST_CLASS_TEST_CASE( &stem_test::ns1, instance ); + test_case *echo_tc = BOOST_CLASS_TEST_CASE( &stem_test::echo, instance ); basic2_tc->depends_on( basic1_tc ); basic1n_tc->depends_on( basic1_tc ); @@ -330,6 +372,8 @@ ns_tc->depends_on( basic1_tc ); ns1_tc->depends_on( basic1_tc ); + echo_tc->depends_on( basic2_tc ); + add( basic1_tc ); add( basic2_tc ); add( basic1n_tc ); @@ -337,6 +381,8 @@ add( dl_tc ); add( ns_tc ); add( ns1_tc ); + + add( echo_tc ); } test_suite *init_unit_test_suite( int argc, char **argv ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |