complement-svn Mailing List for Complement (Page 23)
Status: Pre-Alpha
Brought to you by:
complement
You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(61) |
Nov
(76) |
Dec
(39) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
(33) |
Feb
(41) |
Mar
(16) |
Apr
|
May
(22) |
Jun
(14) |
Jul
(64) |
Aug
(60) |
Sep
(35) |
Oct
(34) |
Nov
(10) |
Dec
(5) |
2008 |
Jan
(4) |
Feb
(24) |
Mar
(10) |
Apr
(30) |
May
(15) |
Jun
(50) |
Jul
(20) |
Aug
(7) |
Sep
(8) |
Oct
(10) |
Nov
|
Dec
|
From: <com...@us...> - 2006-12-01 09:25:07
|
Revision: 1428 http://svn.sourceforge.net/complement/?rev=1428&view=rev Author: complement Date: 2006-12-01 01:24:17 -0800 (Fri, 01 Dec 2006) Log Message: ----------- clean Removed Paths: ------------- tags/sockios_1_8_1/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2006-11-30 19:54:49
|
Revision: 1427 http://svn.sourceforge.net/complement/?rev=1427&view=rev Author: complement Date: 2006-11-30 11:54:45 -0800 (Thu, 30 Nov 2006) Log Message: ----------- * Event.h: code clean; change specialization of Event_base to avoid wrong code or bogus workarounds if whole class specialization happens; * EventSpec.h: removed, due to reasons above; * Event.h, EventHandler.h: add _flags member to event, in particular to detect errors during conversions and network conversions; * NetTransport.cc: pass _flags; taken unused field for this; * _SessionMgr.cc, _EvSession.cc: removed; * SessionMgr.h, EvSession.h: ditto. * EventHandler.h: add classname() function, allow find real name of class in the _Dispatch [well, the name of last class with DECLARE_RESPONSE_TABLE]; very useful for debug; * EvManager.h, EvManager.cc, NetTransport.cc: add possibility to trace events in EvManager; library version 4.3.0 Modified Paths: -------------- trunk/complement/explore/include/stem/EvManager.h trunk/complement/explore/include/stem/Event.h trunk/complement/explore/include/stem/EventHandler.h trunk/complement/explore/lib/stem/ChangeLog trunk/complement/explore/lib/stem/EvManager.cc trunk/complement/explore/lib/stem/Makefile trunk/complement/explore/lib/stem/Makefile.inc trunk/complement/explore/lib/stem/Names.cc trunk/complement/explore/lib/stem/NetTransport.cc trunk/complement/explore/test/libstem/unit/unit_test.cc Removed Paths: ------------- trunk/complement/explore/include/stem/EvSession.h trunk/complement/explore/include/stem/EventSpec.h trunk/complement/explore/include/stem/SessionMgr.h trunk/complement/explore/lib/stem/_EvSession.cc trunk/complement/explore/lib/stem/_SessionMgr.cc Modified: trunk/complement/explore/include/stem/EvManager.h =================================================================== --- trunk/complement/explore/include/stem/EvManager.h 2006-11-29 18:10:09 UTC (rev 1426) +++ trunk/complement/explore/include/stem/EvManager.h 2006-11-30 19:54:45 UTC (rev 1427) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/29 02:52:45 ptr> +// -*- C++ -*- Time-stamp: <06/11/30 22:33:25 ptr> /* * Copyright (c) 1995-1999, 2002, 2003, 2005, 2006 @@ -93,7 +93,8 @@ enum traceflags { notrace = 0, tracenet = 1, - tracedispatch = 2 + tracedispatch = 2, + tracefault = 4 }; typedef std::queue< Event > queue_type; @@ -162,8 +163,14 @@ __FIT_DECLSPEC void Remove( void * ); __FIT_DECLSPEC std::ostream& dump( std::ostream& ) const; - + static void settrf( unsigned f ); + static void unsettrf( unsigned f ); + static void resettrf( unsigned f ); + static void cleantrf(); + static unsigned trflags(); + static void settrs( std::ostream * ); + protected: bool unsafe_is_avail( addr_type id ) const { @@ -251,8 +258,12 @@ xmt::Condition _cnd_queue; static std::string inv_key_str; + static xmt::Mutex _lock_tr; + static unsigned _trflags; + static std::ostream *_trs; friend class Names; + friend class NetTransportMgr; }; } // namespace stem Deleted: trunk/complement/explore/include/stem/EvSession.h =================================================================== --- trunk/complement/explore/include/stem/EvSession.h 2006-11-29 18:10:09 UTC (rev 1426) +++ trunk/complement/explore/include/stem/EvSession.h 2006-11-30 19:54:45 UTC (rev 1427) @@ -1,370 +0,0 @@ -// -*- C++ -*- Time-stamp: <06/07/20 10:32:22 ptr> - -/* - * - * Copyright (c) 1997-1999, 2002, 2003, 2005 - * Petr Ovtchenkov - * - * Copyright (c) 1999-2001 - * ParallelGraphics Ltd. - * - * Licensed under the Academic Free License version 2.1 - * - * This material is provided "as is", with absolutely no warranty expressed - * or implied. Any use is at your own risk. - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. - */ - -#ifndef __stem_EvSession_h -#define __stem_EvSession_h - -#ifndef __config_feature_h -#include <config/feature.h> -#endif - -#include <string> -#include <ctime> - -#ifndef __SOCKSTREAM__ -#include <sockios/sockstream> -#endif - -#include <map> - -#ifndef __XMT_H -#include <mt/xmt.h> -#endif - -#ifndef __Event_h -#include <stem/Event.h> -#endif - -namespace stem { - -#if defined(__SUNPRO_CC) && defined(__STL_USE_NEW_C_HEADERS) -using std::time; -#endif - -struct SessionInfo -{ - SessionInfo() : -// _start( 0 ), -// _last( 0 ), -// _conn( 0 ), - _on_line( 0 ), - _sz_from( 0 ), - _sz_to( 0 ), - _un_from( 0 ), - _un_to( 0 ), - _lun_from( 0 ), - _lun_to( 0 ), - _reconnect_cnt( 0 ), - _control( badaddr ) -// _is_connected( true ) - { - _start = connect(); - // _start = time( &_last ); - // _conn = _last; - } - -#ifndef WIN32 - __FIT_DECLSPEC SessionInfo( const SessionInfo& ); -#else - SessionInfo( const SessionInfo& si ) - { - _host = si._host; - _port = si._port; - - _sz_from = si._sz_from; - _un_from = si._un_from; - _sz_to = si._sz_to; - _un_to = si._un_to; - _lun_from = si._lun_from; - _lun_to = si._lun_to; - _start = si._start; - _on_line = si._on_line; - _conn = si._conn; - _last = si._last; - _reconnect_cnt = si._reconnect_cnt; - _is_connected = si._is_connected; - - _control = si._control; - } -#endif - - -// ConnectSession( sockstream *s ) -// { connect( s ); } - - ~SessionInfo() - { } - - // key_type key; - - // key_type ? secret_key; - - // machine identification: - -// union { -// sockaddr_in inet; -// sockaddr any; -// } _address; - - std::string _host; // name + ip +? port? - int _port; // ? - - // sockstream *_sock; // ? - - // protocols stack: -// sock_base::stype _proto_low; // TCP, UDP, etc -// sock_base::protocol _proto_domain; // inet/local - // ????? proto_high; // row, over HTTP, etc. - - // billing info - size_t _sz_from; // bytes transfer from - size_t _un_from; // transfer units (say, events) from - size_t _sz_to; // bytes transfer to - size_t _un_to; // transfer units (say, events) to - unsigned _lun_from; // last unit number had received - unsigned _lun_to; // last unit number sended; - time_t _start; // session start time - time_t _on_line; // time on line. - time_t _conn; // last time of connect - time_t _last; // last access time - unsigned _reconnect_cnt; // reconnection counter - bool _is_connected; // true if on line now (for stream connection) - - key_type _control; // address of control object; - - // encoding / crypt info - // ... - - - bool is_connected() const - { return _is_connected; } - - void inc_from( size_t sz, size_t u = 1 ) - { - _sz_from += sz; - _un_from += u; - _last = time( 0 ); - } - - void inc_to( size_t sz, size_t u = 1 ) - { - _sz_to += sz; - _un_to += u; - } - - unsigned un_from( unsigned u ) - { - if ( ++_lun_from == u ) { - return 0; - } - unsigned tmp = _lun_from; - _lun_from = u; - return u - tmp; - } - - unsigned un_to( unsigned u ) - { - if ( ++_lun_to == u ) { - return 0; - } - unsigned tmp = _lun_to; - _lun_to = u; - return u - tmp; - } - - time_t connect() - { - _conn = time( &_last ); - _is_connected = true; - return _last; - } - - time_t disconnect() - { - if ( _is_connected ) { - _on_line += time( 0 ) - _conn; - ++_reconnect_cnt; - _is_connected = false; - } - return _on_line; - } - -#ifndef WIN32 - __FIT_DECLSPEC SessionInfo& operator =( const SessionInfo& ); -#else - SessionInfo& operator =( const SessionInfo& si ) - { - _host = si._host; - _port = si._port; - - _sz_from = si._sz_from; - _un_from = si._un_from; - _sz_to = si._sz_to; - _un_to = si._un_to; - _lun_from = si._lun_from; - _lun_to = si._lun_to; - _start = si._start; - _on_line = si._on_line; - _conn = si._conn; - _last = si._last; - _reconnect_cnt = si._reconnect_cnt; - _is_connected = si._is_connected; - - _control = si._control; - - return *this; - } -#endif -}; - -template <class T> -class SessionManager -{ - public: - typedef unsigned key_type; - // typedef __STD::map<key_type,T,__STD::less<key_type>, - // __STL_DEFAULT_ALLOCATOR(T) > heap_type; - typedef std::map<key_type,T> heap_type; - typedef typename heap_type::iterator iterator; - - SessionManager() - { } - - key_type create() - { - MT_REENTRANT( _lock, _x1 ); - return unsafe_create(); - } - - void lock() - { MT_LOCK( _lock ); } - - void unlock() - { MT_UNLOCK( _lock ); } - - bool is_avail( const key_type& k ) const - { - MT_REENTRANT( _lock, _x1 ); - return unsafe_is_avail( k ); - } - - void erase( const key_type& k ) - { - MT_REENTRANT( _lock, _x1 ); - unsafe_erase( k ); - } - - void assign( const key_type& k, const T& v ) - { - MT_REENTRANT( _lock, _x1 ); - heap[k] = v; - } - - protected: - heap_type heap; - - key_type unsafe_create() - { - key_type new_key = create_unique(); - heap[new_key]; - return new_key; - } - - T& operator[]( const key_type& k ) - { - // MT_REENTRANT( _lock, _x1 ); - return heap[k]; - } - - void erase( iterator& k ) - { - MT_REENTRANT( _lock, _x1 ); - unsafe_erase( k ); - } - - bool unsafe_is_avail( const key_type& k ) const - { return heap.find( k ) != heap.end(); } - - void unsafe_erase( const key_type& k ) - { heap.erase( k ); } - - void unsafe_erase( iterator& k ) - { heap.erase( k ); } - - friend class NetTransport_base; - - private: - key_type create_unique(); - static const key_type _low; - static const key_type _high; - static key_type _id; - mutable xmt::Mutex _lock; -}; - -#ifndef _MSC_VER -template <class T> -const typename SessionManager<T>::key_type SessionManager<T>::_low = 0; -#else -template <class T> -const SessionManager<T>::key_type SessionManager<T>::_low = 0; -#endif - -#ifndef _MSC_VER -template <class T> -const typename SessionManager<T>::key_type SessionManager<T>::_high( 65535 ); -#else -template <class T> -const SessionManager<T>::key_type SessionManager<T>::_high = 65535; -#endif - -#ifndef _MSC_VER -template <class T> -typename SessionManager<T>::key_type SessionManager<T>::_id = SessionManager<T>::_low; -// template <class T> -// typename SessionManager<T>::key_type SessionManager<T>::_id( SessionManager<T>::_low ); -#else -template <class T> -SessionManager<T>::key_type SessionManager<T>::_id = SessionManager<T>::_low; -#endif - -#ifndef _MSC_VER -template <class T> -typename SessionManager<T>::key_type SessionManager<T>::create_unique() -#else -template <class T> -SessionManager<T>::key_type SessionManager<T>::create_unique() -#endif -{ -#ifndef _MSC_VER - std::pair<typename heap_type::iterator, bool> ret; -#else - std::pair<heap_type::iterator,bool> ret; -#endif - - do { - if ( ++_id > _high ) { - _id = (_id - _low) % (_high - _low) + _low; - } - } while ( heap.find( _id ) != heap.end() ); - - return _id; -} - -typedef SessionManager<SessionInfo> EvSessionManager; - -} // namespace stem - -#ifdef _MSC_VER -typedef stem::SessionInfo SessionInfo; -#endif - -#endif // __EvSession_h Modified: trunk/complement/explore/include/stem/Event.h =================================================================== --- trunk/complement/explore/include/stem/Event.h 2006-11-29 18:10:09 UTC (rev 1426) +++ trunk/complement/explore/include/stem/Event.h 2006-11-30 19:54:45 UTC (rev 1427) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/26 14:32:35 ptr> +// -*- C++ -*- Time-stamp: <06/11/30 20:11:30 ptr> /* * @@ -70,8 +70,6 @@ # include <bits/type_traits.h> # endif // __GLIBCXX__ -#define _STLP_TEMPLATE_NULL template <> - #endif namespace stem { @@ -147,19 +145,22 @@ __Event_Base() : _code( badcode ), _dst( badaddr ), - _src( badaddr ) + _src( badaddr ), + _flags( 0 ) { } explicit __Event_Base( code_type c ) : _code( c ), _dst( badaddr ), - _src( badaddr ) + _src( badaddr ), + _flags( 0 ) { } /* explicit */ __Event_Base( const __Event_Base& e ) : _code( e._code ), _dst( e._dst ), - _src( e._src ) + _src( e._src ), + _flags( e._flags ) { } code_type code() const @@ -168,6 +169,8 @@ { return _dst; } addr_type src() const { return _src; } + uint32_t flags() const + { return _flags; } bool is_from_foreign() const { return ((_src & extbit) != 0) && (_src != badaddr); } bool is_to_foreign() const @@ -180,33 +183,38 @@ void src( addr_type c ) const { _src = c; } + void setf( uint32_t f ) const + { _flags |= f; } + void unsetf( uint32_t f ) const + { _flags &= (0xffffffff & ~f); } + void resetf( uint32_t f ) const + { _flags = f; } + void cleanf() const + { _flags = 0; } + + enum { + conv = 1, + expand = 2 + }; + protected: - mutable code_type _code; // event code + mutable code_type _code; // event code mutable addr_type _dst; // destination mutable addr_type _src; // source - - friend class NetTransport_base; - friend class NetTransportMgr; + mutable uint32_t _flags; }; -#if defined(_MSC_VER) && !defined(_DEBUG) // workaround for VC 5.0 / Release -} // namespace stem -typedef stem::__Event_Base __Event_Base; -namespace stem { -#endif - // Forward declarations +template <class D, class POD > class __Event_base_aux; +template <class D> class __Event_base_aux<D,__true_type>; +template <class D> class __Event_base_aux<D,__false_type>; + template <class D> class Event_base; -// VC 5.0 to be very huffy on typedefed std::string... -#ifndef _MSC_VER -_STLP_TEMPLATE_NULL class Event_base<std::string>; -#else -_STLP_TEMPLATE_NULL -class Event_base<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >; -#endif -_STLP_TEMPLATE_NULL class Event_base<void>; +template <> class Event_base<std::string>; +template <> class Event_base<void>; + // Typedefs: typedef Event_base<void> EventVoid; @@ -239,8 +247,14 @@ \* ******************************************** */ +template <class D, class POD > +class __Event_base_aux : + public __Event_Base +{ +}; + template <class D> -class Event_base : +class __Event_base_aux<D,__true_type> : public __Event_Base { public: @@ -250,27 +264,24 @@ typedef D * pointer; typedef const D * const_pointer; - Event_base() : + __Event_base_aux() : __Event_Base(), _data() { } - explicit Event_base( code_type c ) : + explicit __Event_base_aux( code_type c ) : __Event_Base( c ), _data() { } - Event_base( code_type c, const D& d ) : + __Event_base_aux( code_type c, const D& d ) : __Event_Base( c ), _data( d ) { } -// #ifndef __GNUG__ // otherwise gcc can't return structure -// explicit -// #endif - Event_base( const Event_base& e ) : + __Event_base_aux( const __Event_Base& e, const D& d ) : __Event_Base( e ), - _data( e._data ) + _data( d ) { } const_reference value() const @@ -280,66 +291,58 @@ size_type value_size() const { return sizeof(_data); } -//#ifndef __FIT_TEMPLATE_FORWARD_BUG -#if 0 - void net_pack( Event& s ) const - { - s.code( _code ); - s.dest( _dst ); - s.src( _src ); - std::ostringstream ss; - net_pack( ss ); - s.value() = ss.str(); - } + void pack( std::ostream& __s ) const + { __pack_base::__pack( __s, _data ); } + void unpack( std::istream& __s ) + { __pack_base::__unpack( __s, _data ); } + void net_pack( std::ostream& __s ) const + { __pack_base::__net_pack( __s, _data ); } + void net_unpack( std::istream& __s ) + { __pack_base::__net_unpack( __s, _data ); } - void net_unpack( const Event& s ) - { - _code = s.code(); - _dst = s.dest(); - _src = s.src(); - std::stringstream ss( s.value() ); - net_unpack( ss ); - } + protected: + value_type _data; +}; - void pack( Event& s ) const - { - s.code( _code ); - s.dest( _dst ); - s.src( _src ); - std::stringstream ss; - pack( ss ); - s.value() = ss.str(); - } +template <class D> +class __Event_base_aux<D,__false_type> : + public __Event_Base +{ + public: + typedef D value_type; + typedef D& reference; + typedef const D& const_reference; + typedef D * pointer; + typedef const D * const_pointer; - void unpack( const Event& s ) - { - _code = s.code(); - _dst = s.dest(); - _src = s.src(); - std::stringstream ss( s.value() ); - unpack( ss ); - } -#else // __FIT_TEMPLATE_FORWARD_BUG - void net_pack( Event& s ) const; - void net_unpack( const Event& s ); - void pack( Event& s ) const; - void unpack( const Event& s ); -#endif + __Event_base_aux() : + __Event_Base(), + _data() + { } -#ifndef _MSC_VER + explicit __Event_base_aux( code_type c ) : + __Event_Base( c ), + _data() + { } + + __Event_base_aux( code_type c, const D& d ) : + __Event_Base( c ), + _data( d ) + { } + + __Event_base_aux( const __Event_Base& e, const D& d ) : + __Event_Base( e ), + _data( d ) + { } + + const_reference value() const + { return _data; } + reference value() + { return _data; } + size_type value_size() const + { return sizeof(_data); } + void pack( std::ostream& __s ) const - { pack( __s, typename __type_traits<D>::is_POD_type() ); } - void unpack( std::istream& __s ) - { unpack( __s, typename __type_traits<D>::is_POD_type() ); } - void net_pack( std::ostream& __s ) const - { net_pack( __s, typename __type_traits<D>::is_POD_type() ); } - void net_unpack( std::istream& __s ) - { net_unpack( __s, typename __type_traits<D>::is_POD_type() ); } -#else -// VC instantiate only whole class, so I need stupid specializaton for it, -// and this template can be compiled for non-POD classes only -// (specialization for integral types in separate file, included below) - void pack( std::ostream& __s ) const { _data.pack( __s ); } void unpack( std::istream& __s ) { _data.unpack( __s ); } @@ -347,49 +350,13 @@ { _data.net_pack( __s ); } void net_unpack( std::istream& __s ) { _data.net_unpack( __s ); } -#endif protected: value_type _data; - -#ifndef _MSC_VER - void pack( std::ostream& __s, __true_type ) const - { __s.write( (const char *)&_data, sizeof(D) ); } - - void pack( std::ostream& __s, __false_type ) const - { _data.pack( __s ); } - - void unpack( std::istream& __s, __true_type ) - { __s.read( (char *)&_data, sizeof(D) ); } - void unpack( std::istream& __s, __false_type ) - { _data.unpack( __s ); } - - void net_pack( std::ostream& __s, __true_type ) const - { - value_type tmp = to_net( _data ); - __s.write( (const char *)&tmp, sizeof(D) ); - } - void net_pack( std::ostream& __s, __false_type ) const - { _data.net_pack( __s ); } - void net_unpack( std::istream& __s, __true_type ) - { - value_type tmp; - __s.read( (char *)&tmp, sizeof(D) ); - _data = from_net( tmp ); - } - void net_unpack( std::istream& __s, __false_type ) - { _data.net_unpack( __s ); } -#endif }; - -// VC 5.0 to be very huffy on typedefed std::string... -_STLP_TEMPLATE_NULL -#ifndef _MSC_VER -class Event_base<std::string> : -#else -class Event_base<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > : -#endif +template <> +class __Event_base_aux<std::string,__false_type> : public __Event_Base { public: @@ -399,27 +366,24 @@ typedef std::string * pointer; typedef const std::string * const_pointer; - Event_base() : + __Event_base_aux() : __Event_Base(), _data() { } - explicit Event_base( code_type c ) : + explicit __Event_base_aux( code_type c ) : __Event_Base( c ), _data() { } - Event_base( code_type c, const std::string& d ) : + __Event_base_aux( code_type c, const std::string& d ) : __Event_Base( c ), _data( d ) { } -#if !defined( __GNUG__ ) && !defined( _MSC_VER ) // otherwise gcc can't return structure -// explicit -#endif - Event_base( const Event_base& e ) : + __Event_base_aux( const __Event_Base& e, const std::string& d ) : __Event_Base( e ), - _data( e._data ) + _data( d ) { } const_reference value() const @@ -427,13 +391,117 @@ reference value() { return _data; } size_type value_size() const - { return _data.size(); } + { return sizeof(_data); } + void pack( std::ostream& __s ) const + { __pack_base::__pack( __s, _data ); } + void unpack( std::istream& __s ) + { __pack_base::__unpack( __s, _data ); } + void net_pack( std::ostream& __s ) const + { __pack_base::__net_pack( __s, _data ); } + void net_unpack( std::istream& __s ) + { __pack_base::__net_unpack( __s, _data ); } + + protected: + value_type _data; +}; + +template <> +class __Event_base_aux<void,__true_type> : + public __Event_Base +{ + public: + typedef void value_type; + typedef void * pointer; + typedef size_t size_type; + typedef const void * const_pointer; + + __Event_base_aux() : + __Event_Base() + { } + + explicit __Event_base_aux( code_type c ) : + __Event_Base( c ) + { } + + __Event_base_aux( const __Event_Base& e ) : + __Event_Base( e ) + { } + + size_type value_size() const + { return 0; } + + void pack( std::ostream& __s ) const + { } + void unpack( std::istream& __s ) + { } + void net_pack( std::ostream& __s ) const + { } + void net_unpack( std::istream& __s ) + { } +}; + +template <class D> +class Event_base : + public __Event_base_aux<D,typename __type_traits<D>::is_POD_type> +{ + private: + typedef __Event_base_aux<D,typename __type_traits<D>::is_POD_type> _Base; + + public: + Event_base() : + __Event_base_aux<D,typename __type_traits<D>::is_POD_type>() + { } + + explicit Event_base( code_type c ) : + __Event_base_aux<D,typename __type_traits<D>::is_POD_type>( c ) + { } + + Event_base( code_type c, const D& d ) : + __Event_base_aux<D,typename __type_traits<D>::is_POD_type>( c, d ) + { } + + Event_base( const Event_base& e ) : + __Event_base_aux<D,typename __type_traits<D>::is_POD_type>( e, e._data ) + { } + + void net_pack( Event& s ) const; + void net_unpack( const Event& s ); + void pack( Event& s ) const; + void unpack( const Event& s ); +}; + + +template <> +class Event_base<std::string> : + public __Event_base_aux<std::string,__false_type> +{ + private: + typedef __Event_base_aux<std::string,__false_type> _Base; + + public: + Event_base() : + __Event_base_aux<std::string,__false_type>() + { } + + explicit Event_base( code_type c ) : + __Event_base_aux<std::string,__false_type>( c ) + { } + + Event_base( code_type c, const std::string& d ) : + __Event_base_aux<std::string,__false_type>( c, d ) + { } + + Event_base( const Event_base& e ) : + __Event_base_aux<std::string,__false_type>( e, e._data ) + { } + void net_pack( Event& s ) const { s.code( _code ); s.dest( _dst ); s.src( _src ); + s.resetf( _flags ); s.value() = _data; } @@ -442,6 +510,7 @@ _code = s.code(); _dst = s.dest(); _src = s.src(); + _flags = s.flags(); _data = s.value(); } @@ -450,6 +519,7 @@ s.code( _code ); s.dest( _dst ); s.src( _src ); + s.resetf( _flags ); s.value() = _data; } @@ -458,96 +528,90 @@ _code = s.code(); _dst = s.dest(); _src = s.src(); + _flags = s.flags(); _data = s.value(); } - - void pack( std::ostream& __s ) const - { __pack_base::__pack( __s, _data ); } - void unpack( std::istream& __s ) - { __pack_base::__unpack( __s, _data ); } - void net_pack( std::ostream& __s ) const - { __pack_base::__net_pack( __s, _data ); } - void net_unpack( std::istream& __s ) - { __pack_base::__net_unpack( __s, _data ); } - - protected: - value_type _data; }; -//#ifdef __FIT_TEMPLATE_FORWARD_BUG template <class D> void Event_base<D>::net_pack( Event& s ) const { - s.code( _code ); - s.dest( _dst ); - s.src( _src ); + // std::cerr << "**1\n"; + s.code( _Base::_code ); + s.dest( _Base::_dst ); + s.src( _Base::_src ); + s.resetf( _Base::_flags | (__Event_Base::conv | __Event_Base::expand) ); std::ostringstream ss; - net_pack( ss ); - s.value() = ss.str(); + _Base::net_pack( ss ); + s.value() = ss.str(); } template <class D> void Event_base<D>::net_unpack( const Event& s ) { - _code = s.code(); - _dst = s.dest(); - _src = s.src(); + _Base::_code = s.code(); + _Base::_dst = s.dest(); + _Base::_src = s.src(); + _Base::_flags = s.flags() & ~(__Event_Base::conv | __Event_Base::expand); std::istringstream ss( s.value() ); - net_unpack( ss ); + _Base::net_unpack( ss ); + // std::cerr << "**2 " << std::hex << _Base::flags() << std::dec << std::endl; } template <class D> void Event_base<D>::pack( Event& s ) const { - s.code( _code ); - s.dest( _dst ); - s.src( _src ); + s.code( _Base::_code ); + s.dest( _Base::_dst ); + s.src( _Base::_src ); + s.resetf( _Base::_flags | __Event_Base::expand & ~__Event_Base::conv ); + // s.unsetf( __Event_Base::conv ); std::ostringstream ss; - pack( ss ); + _Base::pack( ss ); s.value() = ss.str(); + // std::cerr << "**3 " << std::hex << s.flags() << std::dec << std::endl; } template <class D> void Event_base<D>::unpack( const Event& s ) { - _code = s.code(); - _dst = s.dest(); - _src = s.src(); + _Base::_code = s.code(); + _Base::_dst = s.dest(); + _Base::_src = s.src(); + _Base::_flags = s.flags() & ~__Event_Base::expand; + // _Base::unsetf( __Event_Base::expand ); std::istringstream ss( s.value() ); - unpack( ss ); + _Base::unpack( ss ); + // std::cerr << "**4 " << std::hex << _Base::flags() << std::dec << std::endl; } -//#endif // __FIT_TEMPLATE_FORWARD_BUG -_STLP_TEMPLATE_NULL +template <> class Event_base<void> : - public __Event_Base + public __Event_base_aux<void,__true_type> { + private: + typedef __Event_base_aux<void,__true_type> _Base; + public: - typedef void value_type; - typedef void * pointer; - typedef size_t size_type; - typedef const void * const_pointer; Event_base() : - __Event_Base() + __Event_base_aux<void,__true_type>() { } explicit Event_base( code_type c ) : - __Event_Base( c ) + __Event_base_aux<void,__true_type>( c ) { } __FIT_EXPLICIT Event_base( const Event_base& e ) : - __Event_Base( e ) + __Event_base_aux<void,__true_type>( e ) { } - size_type value_size() const - { return 0; } - void net_pack( Event& s ) const { s.code( _code ); s.dest( _dst ); s.src( _src ); + s.resetf( _Base::_flags | __Event_Base::conv | __Event_Base::expand ); s.value().erase(); } @@ -556,6 +620,7 @@ _code = s.code(); _dst = s.dest(); _src = s.src(); + _flags = s.flags() & ~(__Event_Base::conv | __Event_Base::expand); } void pack( Event& s ) const @@ -563,6 +628,7 @@ s.code( _code ); s.dest( _dst ); s.src( _src ); + s.resetf( _Base::_flags & ~__Event_Base::conv | __Event_Base::expand ); s.value().erase(); } @@ -571,6 +637,7 @@ _code = s.code(); _dst = s.dest(); _src = s.src(); + _flags = s.flags() & ~__Event_Base::expand; } void pack( std::ostream& ) const @@ -583,11 +650,6 @@ { } }; -// VC instantiate only whole class, so I need stupid specializaton for it: -#ifdef _MSC_VER -#include <EDS/EventSpec.h> -#endif - } // namespace stem namespace EDS = stem; Modified: trunk/complement/explore/include/stem/EventHandler.h =================================================================== --- trunk/complement/explore/include/stem/EventHandler.h 2006-11-29 18:10:09 UTC (rev 1426) +++ trunk/complement/explore/include/stem/EventHandler.h 2006-11-30 19:54:45 UTC (rev 1427) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/28 20:29:41 ptr> +// -*- C++ -*- Time-stamp: <06/11/30 20:50:13 ptr> /* * Copyright (c) 1995-1999, 2002, 2003, 2005, 2006 @@ -31,6 +31,7 @@ #include <vector> #include <list> #include <ostream> +#include <typeinfo> #include <mt/xmt.h> @@ -109,8 +110,11 @@ { T operator ()( const stem::Event& x ) const { + if ( (x.flags() & __Event_Base::expand) == 0 ) { + throw std::invalid_argument( std::string("invalid conversion") ); + } T tmp; - if ( x.is_from_foreign() ) { + if ( /* x.is_from_foreign() */ x.flags() & __Event_Base::conv ) { tmp.net_unpack( x ); } else { tmp.unpack( x ); @@ -125,8 +129,11 @@ { T operator ()( const stem::Event& x ) const { + if ( (x.flags() & __Event_Base::expand) == 0 ) { + throw std::invalid_argument( std::string("invalid conversion") ); + } stem::Event_base<T> tmp; - if ( x.is_from_foreign() ) { + if ( /* x.is_from_foreign() */ x.flags() & __Event_Base::conv ) { tmp.net_unpack( x ); } else { tmp.unpack( x ); @@ -142,9 +149,9 @@ stem::Event operator ()( const stem::Event_base<T>& x ) const { stem::Event tmp; - // first is evident, the second introduced - // to support Forward autodetection - if ( x.is_to_foreign() || x.is_from_foreign() ) { + // first is evident, the second was introduced + // to support Forward autodetection (and commented with addressing changes) + if ( x.is_to_foreign() /* || x.is_from_foreign() */ ) { x.net_pack( tmp ); } else { x.pack( tmp ); @@ -208,25 +215,15 @@ template <class PMF, class Arg > struct __dispatcher_convert_Event { -#ifndef _MSC_VER static void dispatch( typename PMF::pointer_class_type c, typename PMF::pmf_type pmf, const Arg& arg ) { (c->*pmf)( convert_Event<typename PMF::argument_type>()(arg) ); } -#else - static void dispatch( typename PMF::pointer_class_type c, typename PMF::pmf_type pmf, const Arg& arg ) - { (c->*pmf)( convert_Event<PMF::argument_type>()(arg) ); } -#endif }; template <class PMF, class Arg > struct __dispatcher_convert_Event_extr { -#ifndef _MSC_VER static void dispatch( typename PMF::pointer_class_type c, typename PMF::pmf_type pmf, const Arg& arg ) { (c->*pmf)( convert_Event_extr<typename PMF::argument_type>()(arg) ); } -#else - static void dispatch( typename PMF::pointer_class_type c, typename PMF::pmf_type pmf, const Arg& arg ) - { (c->*pmf)( convert_Event_extr<PMF::argument_type>()(arg) ); } -#endif }; struct __AnyPMFentry @@ -243,11 +240,7 @@ typedef void (T::*PMF)(); PMF pmf; -#if !defined( _MSC_VER ) || defined( _DEBUG ) __FIT_TYPENAME stem::GENERIC::DPMF dpmf; -#else // _MSC_VER && !_DEBUG - GENERIC::DPMF dpmf; -#endif const char *pmf_name; }; @@ -255,18 +248,8 @@ struct __DeclareAnyPMF { state_type st; -#ifndef _MSC_VER /* __FIT_TYPENAME */ stem::code_type code; __FIT_TYPENAME stem::__PMFentry<T> func; -#else // _MSC_VER -# ifdef _DEBUG - stem::code_type code; - stem::__PMFentry<T> func; -# else // !_DEBUG - code_type code; // workaround for VC 5.0 - __PMFentry<T> func; -# endif // _DEBUG -#endif // _MSC_VER }; template <class Key1, class Key2, class Value> @@ -274,9 +257,9 @@ { public: typedef std::pair<Key2,Value> pair2_type; - typedef std::vector<pair2_type,std::allocator<pair2_type > > Container2; + typedef std::vector<pair2_type> Container2; typedef std::pair<Key1,Container2> pair1_type; - typedef std::vector<pair1_type,std::allocator<pair1_type> > Container1; + typedef std::vector<pair1_type> Container1; typedef typename Container1::iterator iterator1; typedef typename Container2::iterator iterator2; typedef typename Container1::const_iterator const_iterator1; @@ -418,11 +401,7 @@ class __EvHandler { public: -#ifndef _MSC_VER typedef typename T::table_type table_type; -#else // should sync at least with EventHandler::table_type below: - typedef __EvTable<stem::code_type,state_type,__AnyPMFentry *> table_type; -#endif // (that was workaround of M$ VC 5.0 bug) __EvHandler() { __EvTableLoader( &table, (T *)0 ); } @@ -558,6 +537,7 @@ typedef __EvTable<code_type,state_type,__AnyPMFentry *> table_type; typedef __DeclareAnyPMF<EventHandler> evtable_decl_type; typedef EventHandler ThisCls; + protected: // See comment near EventHandler::EventHandler() implementation // HistoryContainer& theHistory; @@ -655,6 +635,8 @@ { return false; } virtual void Trace( ostream& ) const { } + virtual const std::type_info& classtype() const + { return typeid(EventHandler); } __FIT_DECLSPEC void TraceStack( ostream& ) const; private: @@ -723,6 +705,8 @@ MT_REENTRANT_SDS( this->_theHistory_lock, _x1 ); \ return theEventsTable.DispatchTrace( theHistory.begin(), \ theHistory.end(), __e, __s ); } \ + virtual const std::type_info& classtype() const \ + { return typeid(ThisCls); } \ typedef stem::__EvHandler<cls,stem::h_iterator> evtable_type; \ typedef stem::__DeclareAnyPMF<cls> evtable_decl_type; \ typedef cls ThisCls; \ Deleted: trunk/complement/explore/include/stem/EventSpec.h =================================================================== --- trunk/complement/explore/include/stem/EventSpec.h 2006-11-29 18:10:09 UTC (rev 1426) +++ trunk/complement/explore/include/stem/EventSpec.h 2006-11-30 19:54:45 UTC (rev 1427) @@ -1,878 +0,0 @@ -// -*- C++ -*- Time-stamp: <03/11/06 07:49:19 ptr> - -/* - * - * Copyright (c) 1997-1999, 2002, 2003 - * Petr Ovchenkov - * - * Copyright (c) 1999-2001 - * ParallelGraphics Ltd. - * - * Licensed under the Academic Free License version 2.0 - * - * This material is provided "as is", with absolutely no warranty expressed - * or implied. Any use is at your own risk. - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. - */ - -// Only for MS VC! -// NEVER direct include! - -#ifdef __unix -# ifdef __HP_aCC -#pragma VERSIONID "@(#)$Id$" -# else -#ident "@(#)$Id$" -# endif -#endif - -_STLP_TEMPLATE_NULL -class Event_base<short> : - public __Event_Base -{ - public: - typedef short value_type; - typedef short& reference; - typedef const short& const_reference; - typedef short * pointer; - typedef const short * const_pointer; - - Event_base() : - __Event_Base(), - _data() - { } - - explicit Event_base( code_type c ) : - __Event_Base( c ), - _data() - { } - - explicit Event_base( code_type c, const short& d ) : - __Event_Base( c ), - _data( d ) - { } - - explicit Event_base( const Event_base& e ) : - __Event_Base( e ), - _data( e._data ) - { } - - const_reference value() const - { return _data; } - reference value() - { return _data; } - size_type value_size() const - { return sizeof(_data); } - - void net_pack( Event& s ) const - { - s.code( _code ); - s.dest( _dst ); - s.src( _src ); - std::stringstream ss; - net_pack( ss ); - s.value() = ss.str(); - } - - void net_unpack( const Event& s ) - { - _code = s.code(); - _dst = s.dest(); - _src = s.src(); - net_unpack( std::stringstream( s.value() ) ); - } - - void pack( Event& s ) const - { - s.code( _code ); - s.dest( _dst ); - s.src( _src ); - std::stringstream ss; - pack( ss ); - s.value() = ss.str(); - } - - void unpack( const Event& s ) - { - _code = s.code(); - _dst = s.dest(); - _src = s.src(); - unpack( std::stringstream( s.value() ) ); - } - - void pack( std::ostream& __s ) const - { __s.write( (const char *)&_data, sizeof(D) ); } - void unpack( std::istream& __s ) - { __s.read( (char *)&_data, sizeof(D) ); } - void net_pack( std::ostream& __s ) const - { - value_type tmp = to_net( _data ); - __s.write( (const char *)&tmp, sizeof(D) ); - } - void net_unpack( std::istream& __s ) - { - value_type tmp; - __s.read( (char *)&tmp, sizeof(D) ); - _data = from_net( tmp ); - } - - protected: - value_type _data; -}; - -_STLP_TEMPLATE_NULL -class Event_base<unsigned short> : - public __Event_Base -{ - public: - typedef unsigned short value_type; - typedef unsigned short& reference; - typedef const unsigned short& const_reference; - typedef unsigned short * pointer; - typedef const unsigned short * const_pointer; - - Event_base() : - __Event_Base(), - _data() - { } - - explicit Event_base( code_type c ) : - __Event_Base( c ), - _data() - { } - - explicit Event_base( code_type c, const unsigned short& d ) : - __Event_Base( c ), - _data( d ) - { } - - explicit Event_base( const Event_base& e ) : - __Event_Base( e ), - _data( e._data ) - { } - - const_reference value() const - { return _data; } - reference value() - { return _data; } - size_type value_size() const - { return sizeof(_data); } - - void net_pack( Event& s ) const - { - s.code( _code ); - s.dest( _dst ); - s.src( _src ); - std::stringstream ss; - net_pack( ss ); - s.value() = ss.str(); - } - - void net_unpack( const Event& s ) - { - _code = s.code(); - _dst = s.dest(); - _src = s.src(); - net_unpack( std::stringstream( s.value() ) ); - } - - void pack( Event& s ) const - { - s.code( _code ); - s.dest( _dst ); - s.src( _src ); - std::stringstream ss; - pack( ss ); - s.value() = ss.str(); - } - - void unpack( const Event& s ) - { - _code = s.code(); - _dst = s.dest(); - _src = s.src(); - unpack( std::stringstream( s.value() ) ); - } - - void pack( std::ostream& __s ) const - { __s.write( (const char *)&_data, sizeof(D) ); } - void unpack( std::istream& __s ) - { __s.read( (char *)&_data, sizeof(D) ); } - void net_pack( std::ostream& __s ) const - { - value_type tmp = to_net( _data ); - __s.write( (const char *)&tmp, sizeof(D) ); - } - void net_unpack( std::istream& __s ) - { - value_type tmp; - __s.read( (char *)&tmp, sizeof(D) ); - _data = from_net( tmp ); - } - - protected: - value_type _data; -}; - -_STLP_TEMPLATE_NULL -class Event_base<int> : - public __Event_Base -{ - public: - typedef int value_type; - typedef int& reference; - typedef const int& const_reference; - typedef int * pointer; - typedef const int * const_pointer; - - Event_base() : - __Event_Base(), - _data() - { } - - explicit Event_base( code_type c ) : - __Event_Base( c ), - _data() - { } - - explicit Event_base( code_type c, const int& d ) : - __Event_Base( c ), - _data( d ) - { } - - explicit Event_base( const Event_base& e ) : - __Event_Base( e ), - _data( e._data ) - { } - - const_reference value() const - { return _data; } - reference value() - { return _data; } - size_type value_size() const - { return sizeof(_data); } - - void net_pack( Event& s ) const - { - s.code( _code ); - s.dest( _dst ); - s.src( _src ); - std::stringstream ss; - net_pack( ss ); - s.value() = ss.str(); - } - - void net_unpack( const Event& s ) - { - _code = s.code(); - _dst = s.dest(); - _src = s.src(); - net_unpack( std::stringstream( s.value() ) ); - } - - void pack( Event& s ) const - { - s.code( _code ); - s.dest( _dst ); - s.src( _src ); - std::stringstream ss; - pack( ss ); - s.value() = ss.str(); - } - - void unpack( const Event& s ) - { - _code = s.code(); - _dst = s.dest(); - _src = s.src(); - unpack( std::stringstream( s.value() ) ); - } - - void pack( std::ostream& __s ) const - { __s.write( (const char *)&_data, sizeof(D) ); } - void unpack( std::istream& __s ) - { __s.read( (char *)&_data, sizeof(D) ); } - void net_pack( std::ostream& __s ) const - { - value_type tmp = to_net( _data ); - __s.write( (const char *)&tmp, sizeof(D) ); - } - void net_unpack( std::istream& __s ) - { - value_type tmp; - __s.read( (char *)&tmp, sizeof(D) ); - _data = from_net( tmp ); - } - - protected: - value_type _data; -}; - -_STLP_TEMPLATE_NULL -class Event_base<unsigned> : - public __Event_Base -{ - public: - typedef unsigned value_type; - typedef unsigned& reference; - typedef const unsigned& const_reference; - typedef unsigned * pointer; - typedef const unsigned * const_pointer; - - Event_base() : - __Event_Base(), - _data() - { } - - explicit Event_base( code_type c ) : - __Event_Base( c ), - _data() - { } - - explicit Event_base( code_type c, const unsigned& d ) : - __Event_Base( c ), - _data( d ) - { } - - explicit Event_base( const Event_base& e ) : - __Event_Base( e ), - _data( e._data ) - { } - - const_reference value() const - { return _data; } - reference value() - { return _data; } - size_type value_size() const - { return sizeof(_data); } - - void net_pack( Event& s ) const - { - s.code( _code ); - s.dest( _dst ); - s.src( _src ); - std::stringstream ss; - net_pack( ss ); - s.value() = ss.str(); - } - - void net_unpack( const Event& s ) - { - _code = s.code(); - _dst = s.dest(); - _src = s.src(); - net_unpack( std::stringstream( s.value() ) ); - } - - void pack( Event& s ) const - { - s.code( _code ); - s.dest( _dst ); - s.src( _src ); - std::stringstream ss; - pack( ss ); - s.value() = ss.str(); - } - - void unpack( const Event& s ) - { - _code = s.code(); - _dst = s.dest(); - _src = s.src(); - unpack( std::stringstream( s.value() ) ); - } - - void pack( std::ostream& __s ) const - { __s.write( (const char *)&_data, sizeof(D) ); } - void unpack( std::istream& __s ) - { __s.read( (char *)&_data, sizeof(D) ); } - void net_pack( std::ostream& __s ) const - { - value_type tmp = to_net( _data ); - __s.write( (const char *)&tmp, sizeof(D) ); - } - void net_unpack( std::istream& __s ) - { - value_type tmp; - __s.read( (char *)&tmp, sizeof(D) ); - _data = from_net( tmp ); - } - - protected: - value_type _data; -}; - -_STLP_TEMPLATE_NULL -class Event_base<long> : - public __Event_Base -{ - public: - typedef long value_type; - typedef long& reference; - typedef const long& const_reference; - typedef long * pointer; - typedef const long * const_pointer; - - Event_base() : - __Event_Base(), - _data() - { } - - explicit Event_base( code_type c ) : - __Event_Base( c ), - _data() - { } - - explicit Event_base( code_type c, const long& d ) : - __Event_Base( c ), - _data( d ) - { } - - explicit Event_base( const Event_base& e ) : - __Event_Base( e ), - _data( e._data ) - { } - - const_reference value() const - { return _data; } - reference value() - { return _data; } - size_type value_size() const - { return sizeof(_data); } - - void net_pack( Event& s ) const - { - s.code( _code ); - s.dest( _dst ); - s.src( _src ); - std::stringstream ss; - net_pack( ss ); - s.value() = ss.str(); - } - - void net_unpack( const Event& s ) - { - _code = s.code(); - _dst = s.dest(); - _src = s.src(); - net_unpack( std::stringstream( s.value() ) ); - } - - void pack( Event& s ) const - { - s.code( _code ); - s.dest( _dst ); - s.src( _src ); - std::stringstream ss; - pack( ss ); - s.value() = ss.str(); - } - - void unpack( const Event& s ) - { - _code = s.code(); - _dst = s.dest(); - _src = s.src(); - unpack( std::stringstream( s.value() ) ); - } - - void pack( std::ostream& __s ) const - { __s.write( (const char *)&_data, sizeof(D) ); } - void unpack( std::istream& __s ) - { __s.read( (char *)&_data, sizeof(D) ); } - void net_pack( std::ostream& __s ) const - { - value_type tmp = to_net( _data ); - __s.write( (const char *)&tmp, sizeof(D) ); - } - void net_unpack( std::istream& __s ) - { - value_type tmp; - __s.read( (char *)&tmp, sizeof(D) ); - _data = from_net( tmp ); - } - - protected: - value_type _data; -}; - -_STLP_TEMPLATE_NULL -class Event_base<unsigned long> : - public __Event_Base -{ - public: - typedef unsigned long value_type; - typedef unsigned long& reference; - typedef const unsigned long& const_reference; - typedef unsigned long * pointer; - typedef const unsigned long * const_pointer; - - Event_base() : - __Event_Base(), - _data() - { } - - explicit Event_base( code_type c ) : - __Event_Base( c ), - _data() - { } - - explicit Event_base( code_type c, const unsigned long& d ) : - __Event_Base( c ), - _data( d ) - { } - - explicit Event_base( const Event_base& e ) : - __Event_Base( e ), - _data( e._data ) - { } - - const_reference value() const - { return _data; } - reference value() - { return _data; } - size_type value_size() const - { return sizeof(_data); } - - void net_pack( Event& s ) const - { - s.code( _code ); - s.dest( _dst ); - s.src( _src ); - std::stringstream ss; - net_pack( ss ); - s.value() = ss.str(); - } - - void net_unpack( const Event& s ) - { - _code = s.code(); - _dst = s.dest(); - _src = s.src(); - net_unpack( std::stringstream( s.value() ) ); - } - - void pack( Event& s ) const - { - s.code( _code ); - s.dest( _dst ); - s.src( _src ); - std::stringstream ss; - pack( ss ); - s.value() = ss.str(); - } - - void unpack( const Event& s ) - { - _code = s.code(); - _dst = s.dest(); - _src = s.src(); - unpack( std::stringstream( s.value() ) ); - } - - void pack( std::ostream& __s ) const - { __s.write( (const char *)&_data, sizeof(D) ); } - void unpack( std::istream& __s ) - { __s.read( (char *)&_data, sizeof(D) ); } - void net_pack( std::ostream& __s ) const - { - value_type tmp = to_net( _data ); - __s.write( (const char *)&tmp, sizeof(D) ); - } - void net_unpack( std::istream& __s ) - { - value_type tmp; - __s.read( (char *)&tmp, sizeof(D) ); - _data = from_net( tmp ); - } - - protected: - value_type _data; -}; - -_STLP_TEMPLATE_NULL -class Event_base<char> : - public __Event_Base -{ - public: - typedef char value_type; - typedef char& reference; - typedef const char& const_reference; - typedef char * pointer; - typedef const char * const_pointer; - - Event_base() : - __Event_Base(), - _data() - { } - - explicit Event_base( code_type c ) : - __Event_Base( c ), - _data() - { } - - explicit Event_base( code_type c, const char& d ) : - __Event_Base( c ), - _data( d ) - { } - - explicit Event_base( const Event_base& e ) : - __Event_Base( e ), - _data( e._data ) - { } - - const_reference value() const - { return _data; } - reference value() - { return _data; } - size_type value_size() const - { return sizeof(_data); } - - void net_pack( Event& s ) const - { - s.code( _code ); - s.dest( _dst ); - s.src( _src ); - std::stringstream ss; - net_pack( ss ); - s.value() = ss.str(); - } - - void net_unpack( const Event& s ) - { - _code = s.code(); - _dst = s.dest(); - _src = s.src(); - net_unpack( std::stringstream( s.value() ) ); - } - - void pack( Event& s ) const - { - s.code( _code ); - s.dest( _dst ); - s.src( _src ); - std::stringstream ss; - pack( ss ); - s.value() = ss.str(); - } - - void unpack( const Event& s ) - { - _code = s.code(); - _dst = s.dest(); - _src = s.src(); - unpack( std::stringstream( s.value() ) ); - } - - void pack( std::ostream& __s ) const - { __s.write( (const char *)&_data, sizeof(D) ); } - void unpack( std::istream& __s ) - { __s.read( (char *)&_data, sizeof(D) ); } - void net_pack( std::ostream& __s ) const - { - value_type tmp = to_net( _data ); - __s.write( (const char *)&tmp, sizeof(D) ); - } - void net_unpack( std::istream& __s ) - { - value_type tmp; - __s.read( (char *)&tmp, sizeof(D) ); - _data = from_net( tmp ); - } - - protected: - value_type _data; -}; - -_STLP_TEMPLATE_NULL -class Event_base<unsigned char> : - public __Event_Base -{ - public: - typedef unsigned char value_type; - typedef unsigned char& reference; - typedef const unsigned char& const_reference; - typedef unsigned char * pointer; - typedef const unsigned char * const_pointer; - - Event_base() : - __Event_Base(), - _data() - { } - - explicit Event_base( code_type c ) : - __Event_Base( c ), - _data() - { } - - explicit Event_base( code_type c, const unsigned char& d ) : - __Event_Base( c ), - _data( d ) - { } - - explicit Event_base( const Event_base& e ) : - __Event_Base( e ), - _data( e._data ) - { } - - const_reference value() const - { return _data; } - reference value() - { return _data; } - size_type value_size() const - { return sizeof(_data); } - - void net_pack( Event& s ) const - { - s.code( _code ); - s.dest( _dst ); - s.src( _src ); - std::stringstream ss; - net_pack( ss ); - s.value() = ss.str(); - } - - void net_unpack( const Event& s ) - { - _code = s.code(); - _dst = s.dest(); - _src = s.src(); - net_unpack( std::stringstream( s.value() ) ); - } - - void pack( Event& s ) const - { - s.code( _code ); - s.dest( _dst ); - s.src( _src ); - std::stringstream ss; - pack( ss ); - s.value() = ss.str(); - } - - void unpack( const Event& s ) - { - _code = s.code(); - _dst = s.dest(); - _src = s.src(); - unpack( std::stringstream( s.value() ) ); - } - - void pack( std::ostream& __s ) const - { __s.write( (const char *)&_data, sizeof(D) ); } - void unpack( std::istream& __s ) - { __s.read( (char *)&_data, sizeof(D) ); } - void net_pack( std::ostream& __s ) const - { - value_type tmp = to_net( _data ); - __s.write( (const char *)&tmp, sizeof(D) ); - } - void net_unpack( std::istream& __s ) - { - value_type tmp; - __s.read( (char *)&tmp, sizeof(D) ); - _data = from_net( tmp ); - } - - protected: - value_type _data; -}; - -_STLP_TEMPLATE_NULL -class Event_base<signed char> : - public __Event_Base -{ - public: - typedef signed char value_type; - typedef signed char& reference; - typedef const signed char& const_reference; - typedef signed char * pointer; - typedef const signed char * const_pointer; - - Event_base() : - __Event_Base(), - _data() - { } - - explicit Event_base( code_type c ) : - __Event_Base( c ), - _data() - { } - - explicit Event_base( code_type c, const signed char& d ) : - __Event_Base( c ), - _data( d ) - { } - - explicit Event_base( const Event_base& e ) : - __Event_Base( e ), - _data( e._data ) - { } - - const_reference value() const - { return _data; } - reference value() - { return _data; } - size_type value_size() const - { return sizeof(_data); } - - void net_pack( Event& s ) const - { - s.code( _code ); - s.dest( _dst ); - s.src( _src ); - std::stringstream ss; - net_pack( ss ); - s.value() = ss.str(); - } - - void net_unpack( const Event& s ) - { - _code = s.code(); - _dst = s.dest(); - _src = s.src(); - net_unpack( std::stringstream( s.value() ) ); - } - - void pack( Event& s ) const - { - s.code( _code ); - s.dest( _dst ); - s.src( _src ); - std::stringstream ss; - pack( ss ); - s.value() = ss.str(); - } - - void unpack( const Event& s ) - { - _code = s.code(); - _dst = s.dest(); - _src = s.src(); - unpack( std::stringstream( s.value() ) ); - } - - void pack( std::ostream& __s ) const - { __s.write( (const char *)&_data, sizeof(D) ); } - void unpack( std::istream& __s ) - { __s.read( (char *)&_data, sizeof(D) ); } - void net_pack( std::ostream& __s ) const - { - value_type tmp = to_net( _data ); - __s.write( (const char *)&tmp, sizeof(D) ); - } - void net_unpack( std::istream& __s ) - { - value_type tmp; - __s.read( (char *)&tmp, sizeof(D) ); - _data = from_net( tmp ); - } - - protected: - value_type _data; -}; Deleted: trunk/complement/explore/include/stem/SessionMgr.h =================================================================== --- trunk/complement/explore/include/stem/SessionMgr.h 2006-11-29 18:10:09 UTC (rev 1426) +++ trunk/complement/explore/include/stem/SessionMgr.h 2006-11-30 19:54:45 UTC (rev 1427) @@ -1,107 +0,0 @@ -// -*- C++ -*- Time-stamp: <06/06/28 15:09:44 ptr> - -/* - * - * Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 - * Petr Ovtchenkov - * - * Copyright (c) 1999-2001 - * ParallelGraphics Ltd. - * - * Licensed under the Academic Free License version 2.1 - * - * This material is provided "as is", with absolutely no warranty expressed - * or implied. Any use is at your own risk. - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. - */ - -#ifndef __stem_SessionMgr_h -#define __stem_SessionMgr_h - -#ifndef __config_feature_h -#include <config/feature.h> -#endif - -#ifndef __stem_Event_h -#include <stem/Event.h> -#endif - -#ifndef __stem_EventHandler_h -#include <stem/EventHandler.h> -#endif - -#include <ctime> - -#ifndef __stem_EvPack_h -#include <stem/EvPack.h> -#endif - -namespace stem { - -class SessionMgr : - public EventHandler -{ - public: - __FIT_DECLSPEC SessionMgr(); - __FIT_DECLSPEC SessionMgr( const char *info ); - __FIT_DECLSPEC SessionMgr( addr_type addr, const char *info = 0 ); - __FIT_DECLSPEC ~SessionMgr(); - - void raw_establish_session( EventHandler *, addr_type ); - - protected: - - virtual __FIT_DECLSPEC EventHandler *session_leader( const std::string& account, - const std::string& passwd, - addr_type addr ) throw(); - virtual __FIT_DECLSPEC void destroy_session_leader( EventHandler * ) throw(); - - void establish_session( const Event& ); - void restore_session( const Event_base<key_type>& ); - void close_session( const Event_base<key_type>& ); - - struct __S - { - // Event::key_type leader; - EventHandler *leader; - time_t timeout; - }; - - typedef std::pair<key_type,__S> account_type; - typedef std::vector<account_type> Container; - - key_type key_generate(); - Container _M_c; -#ifdef STLPORT - std::select1st<account_type> _skey; - std::select2nd<account_type> _sess; -#else - __gnu_cxx::select1st<account_type> _skey; - __gnu_cxx::select2nd<account_type> _sess; -#endif - std::equal_to<key_type> _eq_key; - - DECLARE_RESPONSE_TABLE( SessionMgr, EventHandler ); -}; - - -struct SessionRsp : - public __pack_base -{ - key_type key; - addr_type addr; - - virtual __FIT_DECLSPEC void pack( std::ostream& s ) const; - virtual __FIT_DECLSPEC void net_pack( std::ostream& s ) const; - virtual __FIT_DECLSPEC void unpack( std::istream& s ); - virtual __FIT_DECLSPEC void net_unpack( std::istream& s ); -}; - -} // namespace stem - -#endif // __stem_SessionMgr_h Modified: trunk/complement/explore/lib/stem/ChangeLog =================================================================== --- trunk/complement/explore/lib/stem/ChangeLog 2006-11-29 18:10:09 UTC (rev 1426) +++ trunk/complement/explore/lib/stem/ChangeLog 2006-11-30 19:54:45 UTC (rev 1427) @@ -1,3 +1,31 @@ +2006-11-30 Petr Ovtchenkov <pt...@is...> + + * Event.h: code clean; change specialization of Event_base + to avoid wrong code or bogus workarounds if whole cla... [truncated message content] |
From: <com...@us...> - 2006-11-29 18:10:12
|
Revision: 1426 http://svn.sourceforge.net/complement/?rev=1426&view=rev Author: complement Date: 2006-11-29 10:10:09 -0800 (Wed, 29 Nov 2006) Log Message: ----------- subscribe already subscribed objects, if ones are non-local (add another communication channel to object) Modified Paths: -------------- trunk/complement/explore/lib/stem/NetTransport.cc trunk/complement/explore/test/libstem/unit/unit_test.cc Modified: trunk/complement/explore/lib/stem/NetTransport.cc =================================================================== --- trunk/complement/explore/lib/stem/NetTransport.cc 2006-11-29 18:07:36 UTC (rev 1425) +++ trunk/complement/explore/lib/stem/NetTransport.cc 2006-11-29 18:10:09 UTC (rev 1426) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/29 01:28:01 ptr> +// -*- C++ -*- Time-stamp: <06/11/29 17:30:01 ptr> /* * @@ -225,12 +225,12 @@ if ( ev.code() == EV_STEM_TRANSPORT ) { src.addr = ns_addr; addr_type xsrc = manager()->reflect( src ); - if ( xsrc == badaddr ) { + if ( xsrc == badaddr || (xsrc & extbit) ) { // ignore, if local; but add new transport otherwise manager()->SubscribeRemote( detail::transport( static_cast<NetTransport_base *>(this), detail::transport::socket_tcp, 10 ), src ); } src.addr = default_addr; xsrc = manager()->reflect( src ); - if ( xsrc == badaddr ) { + if ( xsrc == badaddr || (xsrc & extbit) ) { // ignore, if local; but add new transport otherwise manager()->SubscribeRemote( detail::transport( static_cast<NetTransport_base *>(this), detail::transport::socket_tcp, 10 ), src ); } Event ack( EV_STEM_TRANSPORT_ACK ); @@ -339,13 +339,13 @@ xsrc = manager()->reflect( src ); // indeed src is something like NetTransport, so substitute ns: src.addr = ns_addr; - if ( xsrc == badaddr ) { + if ( xsrc == badaddr || (xsrc & extbit)) { // ignore local; but add new transport otherwise manager()->SubscribeRemote( detail::transport( static_cast<NetTransport_base *>(this), detail::transport::socket_tcp, 10 ), src ); } // indeed src is something like NetTransport, so substitute default: src.addr = default_addr; xsrc = manager()->reflect( src ); - if ( xsrc == badaddr ) { + if ( xsrc == badaddr || (xsrc & extbit)) { // ignore local; but add new transport otherwise xsrc = manager()->SubscribeRemote( detail::transport( static_cast<NetTransport_base *>(this), detail::transport::socket_tcp, 10 ), src ); } } else { Modified: trunk/complement/explore/test/libstem/unit/unit_test.cc =================================================================== --- trunk/complement/explore/test/libstem/unit/unit_test.cc 2006-11-29 18:07:36 UTC (rev 1425) +++ trunk/complement/explore/test/libstem/unit/unit_test.cc 2006-11-29 18:10:09 UTC (rev 1426) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/29 14:34:41 ptr> +// -*- C++ -*- Time-stamp: <06/11/29 18:18:10 ptr> /* * Copyright (c) 2002, 2003, 2006 @@ -279,7 +279,7 @@ node.wait(); mgr.close(); - // mgr.join(); + mgr.join(); srv.close(); srv.wait(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2006-11-29 18:07:37
|
Revision: 1425 http://svn.sourceforge.net/complement/?rev=1425&view=rev Author: complement Date: 2006-11-29 10:07:36 -0800 (Wed, 29 Nov 2006) Log Message: ----------- don't delete objects via _conn_pool container content [this is secondary structure, objects will be deleted in the _M_c container]; this fix sporadic crashes of server on exit Modified Paths: -------------- trunk/complement/explore/include/sockios/sockmgr.cc trunk/complement/explore/lib/sockios/ChangeLog trunk/complement/explore/lib/sockios/Makefile.inc Modified: trunk/complement/explore/include/sockios/sockmgr.cc =================================================================== --- trunk/complement/explore/include/sockios/sockmgr.cc 2006-11-29 12:03:40 UTC (rev 1424) +++ trunk/complement/explore/include/sockios/sockmgr.cc 2006-11-29 18:07:36 UTC (rev 1425) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/28 01:31:14 ptr> +// -*- C++ -*- Time-stamp: <06/11/29 18:43:21 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 @@ -441,11 +441,10 @@ stream = c->s; if ( stream->is_open() ) { c->_proc->connect( *stream ); - if ( !stream->good() ) { - stream->close(); - c->_proc->close(); - delete c->_proc; - c->_proc = 0; + if ( c->s == 0 || !stream->good() ) { + if ( c->_proc != 0 ) { + c->_proc->close(); + } } else if ( stream->is_open() ) { if ( stream->rdbuf()->in_avail() > 0 ) { // socket has buffered data, push it back to queue @@ -458,11 +457,8 @@ sock_base::socket_type rfd = stream->rdbuf()->fd(); ::write( me->_cfd, reinterpret_cast<const char *>(&rfd), sizeof(sock_base::socket_type) ); } - } else { - stream->close(); + } else if ( c->_proc ) { c->_proc->close(); - delete c->_proc; - c->_proc = 0; } } } Modified: trunk/complement/explore/lib/sockios/ChangeLog =================================================================== --- trunk/complement/explore/lib/sockios/ChangeLog 2006-11-29 12:03:40 UTC (rev 1424) +++ trunk/complement/explore/lib/sockios/ChangeLog 2006-11-29 18:07:36 UTC (rev 1425) @@ -1,3 +1,12 @@ +2006-11-29 Petr Ovtchenkov <pt...@is...> + + * sockmgr.cc: don't delete objects via _conn_pool + container content [this is secondary structure, + objects will be deleted in the _M_c container]; + this fix sporadic crashes of server on exit. + + * libsockios: Version 1.10.1 + 2006-11-27 Petr Ovtchenkov <pt...@is...> * sockmgr.h, sockmgr.cc: delete connect processors and Modified: trunk/complement/explore/lib/sockios/Makefile.inc =================================================================== --- trunk/complement/explore/lib/sockios/Makefile.inc 2006-11-29 12:03:40 UTC (rev 1424) +++ trunk/complement/explore/lib/sockios/Makefile.inc 2006-11-29 18:07:36 UTC (rev 1425) @@ -1,9 +1,9 @@ -# -*- Makefile -*- Time-stamp: <06/11/27 17:19:45 ptr> +# -*- Makefile -*- Time-stamp: <06/11/29 18:47:25 ptr> LIBNAME = sockios MAJOR = 1 MINOR = 10 -PATCH = 0 +PATCH = 1 SRC_CC = _sockstream.cc _sockmgr.cc SRC_C = freebsd/getaddrinfo.c \ freebsd/ns_parse.c \ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2006-11-29 12:03:41
|
Revision: 1424 http://svn.sourceforge.net/complement/?rev=1424&view=rev Author: complement Date: 2006-11-29 04:03:40 -0800 (Wed, 29 Nov 2006) Log Message: ----------- tests pass with new naming/addressing of external objects; recommendation: use --catch_system_errors=no for unit tests, it allow avoid problems of utf with catching signals Modified Paths: -------------- trunk/complement/explore/lib/stem/ChangeLog trunk/complement/explore/lib/stem/EvManager.cc trunk/complement/explore/test/libstem/unit/Echo.cc trunk/complement/explore/test/libstem/unit/unit_test.cc Modified: trunk/complement/explore/lib/stem/ChangeLog =================================================================== --- trunk/complement/explore/lib/stem/ChangeLog 2006-11-29 11:55:20 UTC (rev 1423) +++ trunk/complement/explore/lib/stem/ChangeLog 2006-11-29 12:03:40 UTC (rev 1424) @@ -1,3 +1,12 @@ +2006-11-29 Petr Ovtchenkov <pt...@is...> + + * EvManager.h, EvManager.cc, NetTransport.h, NetTransport.cc: + global addressing/naming scheme [communication with external + objects] now in working state. + + * Names.cc: ditto; return not only external addresses, but + internal too. + 2006-11-24 Petr Ovtchenkov <pt...@is...> * Event.h, EvPack.h, EvPack.cc: introduce 'global Modified: trunk/complement/explore/lib/stem/EvManager.cc =================================================================== --- trunk/complement/explore/lib/stem/EvManager.cc 2006-11-29 11:55:20 UTC (rev 1423) +++ trunk/complement/explore/lib/stem/EvManager.cc 2006-11-29 12:03:40 UTC (rev 1424) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/29 10:49:19 ptr> +// -*- C++ -*- Time-stamp: <06/11/29 13:22:14 ptr> /* * @@ -256,11 +256,8 @@ addr_type EvManager::SubscribeRemote( const gaddr_type& addr, const std::string& info ) { - cerr << __FILE__ << ":" << __LINE__ << endl; - addr_type id; if ( addr.hid == xmt::hostid() && addr.pid == xmt::getpid() ) { // local - cerr << __FILE__ << ":" << __LINE__ << endl; if ( addr.addr & extbit ) { // may be transit object Locker lk( _lock_xheap ); uuid_ext_heap_type::const_iterator i = _ui_heap.find( addr ); @@ -277,20 +274,16 @@ } return badaddr; // don't know what I can made } else { // foreign object - cerr << __FILE__ << ":" << __LINE__ << endl; Locker lk( _lock_xheap ); uuid_ext_heap_type::const_iterator i = _ui_heap.find( addr ); if ( i != _ui_heap.end() ) { - cerr << __FILE__ << ":" << __LINE__ << endl; return i->second; } gaddr_type peer_zero( addr ); peer_zero.addr = default_addr; pair<uuid_tr_heap_type::const_iterator,uuid_tr_heap_type::const_iterator> range = _tr_heap.equal_range( peer_zero ); - cerr << __FILE__ << ":" << __LINE__ << "\n" << peer_zero << endl; if ( range.first == range.second ) { // no transport - cerr << "#####" << endl;// << __FILE__ << ":" << __LINE__ << endl; return badaddr; } id = create_unique_x(); @@ -393,23 +386,12 @@ __FIT_DECLSPEC addr_type EvManager::reflect( const gaddr_type& addr ) const { - if ( stem::superflag != 0 ) { - cerr << "%%%%%\n"; - cerr << addr << endl; - cerr << dec << xmt::getpid() << endl; - } if ( addr.hid == xmt::hostid() && addr.pid == xmt::getpid() ) { // this host, this process - if ( stem::superflag != 0 ) { - cerr << "%%%%% 1\n"; - } if ( (addr.addr & extbit) == 0 ) { // looks like local object Locker _x1( _lock_heap ); local_heap_type::const_iterator l = heap.find( addr.addr ); if ( l != heap.end() ) { - if ( superflag != 0 ) { - cerr << "%%%%% 2\n"; - } return addr.addr; // l->first } } @@ -434,14 +416,8 @@ Locker _x1( _lock_xheap ); uuid_ext_heap_type::const_iterator i = _ui_heap.find( addr ); if ( i == _ui_heap.end() ) { - if ( stem::superflag != 0 ) { - cerr << "%%%%% 3\n"; - } return badaddr; } - if ( stem::superflag != 0 ) { - cerr << "%%%%% 4\n"; - } return i->second; } @@ -471,12 +447,6 @@ __FIT_DECLSPEC void EvManager::unsafe_Remove( void *channel ) { - if ( superflag != 0 ) { - cerr << "Remove channel" << endl; - // dump( cerr ); - cerr << "==== 1" << endl; - // abort(); - } pair<tr_uuid_heap_type::iterator,tr_uuid_heap_type::iterator> ch_range = _ch_heap.equal_range( channel ); for (tr_uuid_heap_type::iterator i = ch_range.first; i != ch_range.second; ++i ) { _tr_heap.erase( i->second ); @@ -486,11 +456,6 @@ _ui_heap.erase( i->second ); } _ch_heap.erase( ch_range.first, ch_range.second ); - if ( superflag != 0 ) { - cerr << "==== 2" << endl; - dump( cerr ); - cerr << "==== 3" << endl; - } } __FIT_DECLSPEC const detail::transport& EvManager::transport( addr_type id ) const @@ -590,11 +555,6 @@ EventHandler *object = i->second; // target object _lock_heap.unlock(); - // if ( e.src() & extbit ) { - // xmt::Locker lk( _lock_xheap ); - // - // } - try { if ( superflag ) { cerr << hex << e.dest() << " " << e.src() << " " << e.code() << dec << endl; @@ -602,9 +562,6 @@ cerr << endl; } object->Dispatch( e ); // call dispatcher - if ( superflag ) { - cerr << "***************" << endl; - } } catch ( ... ) { } Modified: trunk/complement/explore/test/libstem/unit/Echo.cc =================================================================== --- trunk/complement/explore/test/libstem/unit/Echo.cc 2006-11-29 11:55:20 UTC (rev 1423) +++ trunk/complement/explore/test/libstem/unit/Echo.cc 2006-11-29 12:03:40 UTC (rev 1424) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/28 16:32:53 ptr> +// -*- C++ -*- Time-stamp: <06/11/29 13:02:34 ptr> /* * Copyright (c) 2006 @@ -133,7 +133,6 @@ { BOOST_CHECK( ev.value() == mess ); - // cerr << mess << endl; cnd.set(true); } Modified: trunk/complement/explore/test/libstem/unit/unit_test.cc =================================================================== --- trunk/complement/explore/test/libstem/unit/unit_test.cc 2006-11-29 11:55:20 UTC (rev 1423) +++ trunk/complement/explore/test/libstem/unit/unit_test.cc 2006-11-29 12:03:40 UTC (rev 1424) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/29 10:40:45 ptr> +// -*- C++ -*- Time-stamp: <06/11/29 14:34:41 ptr> /* * Copyright (c) 2002, 2003, 2006 @@ -38,6 +38,8 @@ #include <sys/shm.h> #include <sys/wait.h> +#include <signal.h> + using namespace std; struct stem_test @@ -288,54 +290,80 @@ void stem_test::echo_net() { - xmt::__Condition<true> fcnd; + shmid_ds ds; + int id = shmget( 5000, 1024, IPC_CREAT | IPC_EXCL | 0600 ); + BOOST_REQUIRE( id != -1 ); + // if ( id == -1 ) { + // cerr << "Error on shmget" << endl; + // } + BOOST_REQUIRE( shmctl( id, IPC_STAT, &ds ) != -1 ); + // if ( shmctl( id, IPC_STAT, &ds ) == -1 ) { + // cerr << "Error on shmctl" << endl; + // } + void *buf = shmat( id, 0, 0 ); + BOOST_REQUIRE( buf != reinterpret_cast<void *>(-1) ); + // if ( buf == reinterpret_cast<void *>(-1) ) { + // cerr << "Error on shmat" << endl; + // } + + xmt::__Condition<true>& fcnd = *new( buf ) xmt::__Condition<true>(); fcnd.set( false ); try { xmt::Thread::fork(); - stem::NetTransportMgr mgr; + try { + stem::NetTransportMgr mgr; - fcnd.try_wait(); + fcnd.try_wait(); - stem::addr_type zero = mgr.open( "localhost", 6995 ); + stem::addr_type zero = mgr.open( "localhost", 6995 ); - BOOST_CHECK( zero != stem::badaddr ); - BOOST_CHECK( zero != 0 ); // NetTransportMgr should detect external delivery + BOOST_CHECK( zero != stem::badaddr ); + BOOST_CHECK( zero != 0 ); // NetTransportMgr should detect external delivery - EchoClient node; + EchoClient node; - stem::Event ev( NODE_EV_ECHO ); + stem::Event ev( NODE_EV_ECHO ); - ev.dest( zero ); - ev.value() = node.mess; + ev.dest( zero ); + ev.value() = node.mess; - node.Send( ev ); + node.Send( ev ); - node.wait(); + node.wait(); - mgr.close(); + mgr.close(); + mgr.join(); + } + catch ( ... ) { + } exit( 0 ); } - catch ( xmt::fork_in_parent& ) { - - } + catch ( xmt::fork_in_parent& child ) { + try { + sockmgr_stream_MP<stem::NetTransport> srv( 6995 ); - try { - sockmgr_stream_MP<stem::NetTransport> srv( 6995 ); + StEMecho echo( 0, "echo service"); // <= zero! - StEMecho echo( 0, "echo service"); // <= zero! + fcnd.set( true ); - fcnd.set( true ); + int stat; + waitpid( child.pid(), &stat, 0 ); - // mgr.join(); - - srv.close(); - srv.wait(); + srv.close(); + srv.wait(); + } + catch ( ... ) { + } } - catch ( ... ) { - } + + (&fcnd)->~__Condition<true>(); + + shmdt( buf ); + shmctl( id, IPC_RMID, &ds ); + // cerr << "Fine\n"; } @@ -343,9 +371,15 @@ extern int superflag; } +extern "C" { + +static void dummy_signal_handler( int ) +{ } + +} + void stem_test::peer() { - cerr << "peer" << endl; /* * Scheme: * / NetTransport / c1 @@ -369,16 +403,19 @@ shmid_ds ds; int id = shmget( 5000, 1024, IPC_CREAT | IPC_EXCL | 0600 ); - if ( id == -1 ) { - cerr << "Error on shmget" << endl; - } - if ( shmctl( id, IPC_STAT, &ds ) == -1 ) { - cerr << "Error on shmctl" << endl; - } + BOOST_REQUIRE( id != -1 ); + // if ( id == -1 ) { + // cerr << "Error on shmget" << endl; + // } + BOOST_REQUIRE( shmctl( id, IPC_STAT, &ds ) != -1 ); + // if ( shmctl( id, IPC_STAT, &ds ) == -1 ) { + // cerr << "Error on shmctl" << endl; + // } void *buf = shmat( id, 0, 0 ); - if ( buf == reinterpret_cast<void *>(-1) ) { - cerr << "Error on shmat" << endl; - } + BOOST_REQUIRE( buf != reinterpret_cast<void *>(-1) ); + // if ( buf == reinterpret_cast<void *>(-1) ) { + // cerr << "Error on shmat" << endl; + // } xmt::__Condition<true>& fcnd = *new( buf ) xmt::__Condition<true>(); fcnd.set( false ); @@ -390,88 +427,100 @@ scnd.set( false ); try { + // Client 1 xmt::Thread::fork(); - stem::NetTransportMgr mgr; +#if 0 + struct sigaction action; + struct sigaction old_action; + action.sa_flags = 0; + action.sa_handler = &dummy_signal_handler; + sigemptyset( &action.sa_mask ); - PeerClient c1( "c1 local" ); // c1 client - Naming nm; + sigaction( SIGFPE, &action, &old_action ); + sigaction( SIGTRAP, &action, &old_action ); + sigaction( SIGSEGV, &action, &old_action ); + sigaction( SIGBUS, &action, &old_action ); + sigaction( SIGABRT, &action, &old_action ); + sigaction( SIGALRM, &action, &old_action ); +#endif - cerr << "1\n"; - fcnd.try_wait(); + try { + stem::NetTransportMgr mgr; - // c1.manager()->dump( cerr ); - stem::addr_type zero = mgr.open( "localhost", 6995 ); // take address of 'zero' (aka default) object via net transport from server - // It done like it should on client side - // cerr << "===========" << endl; - // c1.manager()->dump( cerr ); + PeerClient c1( "c1 local" ); // c1 client + Naming nm; - BOOST_CHECK( zero != stem::badaddr ); - BOOST_CHECK( zero != 0 ); - BOOST_CHECK( zero & stem::extbit ); // "external" address + fcnd.try_wait(); - stem::Event ev( NODE_EV_REGME ); - ev.dest( zero ); + stem::addr_type zero = mgr.open( "localhost", 6995 ); // take address of 'zero' (aka default) object via net transport from server + // It done like it should on client side - ev.value() = "c1@here"; - c1.Send( ev ); // 'register' c1 client on 'echo' server + BOOST_CHECK( zero != stem::badaddr ); + BOOST_CHECK( zero != 0 ); + BOOST_CHECK( zero & stem::extbit ); // "external" address - stem::gaddr_type ga( c1.manager()->reflect( zero ) ); + stem::Event ev( NODE_EV_REGME ); + ev.dest( zero ); - BOOST_CHECK( ga.addr == 0 ); - BOOST_CHECK( ga.pid != -1 ); + ev.value() = "c1@here"; + c1.Send( ev ); // 'register' c1 client on 'echo' server - ga.addr = stem::ns_addr; // this will be global address of ns of the same process - // as zero + stem::gaddr_type ga( c1.manager()->reflect( zero ) ); - BOOST_CHECK( c1.manager()->reflect( ga ) != stem::badaddr ); + BOOST_CHECK( ga.addr == 0 ); + BOOST_CHECK( ga.pid != -1 ); - // c1.manager()->dump( cerr ); + ga.addr = stem::ns_addr; // this will be global address of ns of the same process + // as zero - stem::Event evname( EV_STEM_GET_NS_NAME ); - evname.dest( c1.manager()->reflect( ga ) ); - evname.value() = "c2@here"; + BOOST_CHECK( c1.manager()->reflect( ga ) != stem::badaddr ); - pcnd.try_wait(); + stem::Event evname( EV_STEM_GET_NS_NAME ); + evname.dest( c1.manager()->reflect( ga ) ); + evname.value() = "c2@here"; - cerr << "@1\n"; + pcnd.try_wait(); - Naming::nsrecords_type::const_iterator i; + Naming::nsrecords_type::const_iterator i; - do { - nm.reset(); - nm.lst.clear(); - nm.Send( evname ); - nm.wait(); - i = find_if( nm.lst.begin(), nm.lst.end(), compose1( bind2nd( equal_to<string>(), string( "c2@here" ) ), select2nd<pair<stem::gaddr_type,string> >() ) ); - } while ( i == nm.lst.end() ); + do { + nm.reset(); + nm.lst.clear(); + nm.Send( evname ); + nm.wait(); + i = find_if( nm.lst.begin(), nm.lst.end(), compose1( bind2nd( equal_to<string>(), string( "c2@here" ) ), select2nd<pair<stem::gaddr_type,string> >() ) ); + } while ( i == nm.lst.end() ); - BOOST_CHECK( i != nm.lst.end() ); - BOOST_CHECK( i->second == "c2@here" ); + BOOST_CHECK( i != nm.lst.end() ); + BOOST_CHECK( i->second == "c2@here" ); - stem::addr_type pa = c1.manager()->reflect( i->first ); - if ( pa == stem::badaddr ) { // unknown yet - pa = c1.manager()->SubscribeRemote( i->first, i->second ); - } + stem::addr_type pa = c1.manager()->reflect( i->first ); + if ( pa == stem::badaddr ) { // unknown yet + pa = c1.manager()->SubscribeRemote( i->first, i->second ); + if ( pa == stem::badaddr ) { // it still unknown, transport not found + // hint: use transport as object zero used + pa = c1.manager()->SubscribeRemote( c1.manager()->transport( zero ), i->first, i->second ); + } + } - // stem::superflag = 1; - c1.manager()->dump( cerr ); + BOOST_CHECK( pa != stem::badaddr ); - if ( pa != stem::badaddr ) { - stem::Event pe( NODE_EV_ECHO ); - pe.dest( pa ); - pe.value() = "peer client"; - c1.Send( pe ); + if ( pa != stem::badaddr ) { + stem::Event pe( NODE_EV_ECHO ); + pe.dest( pa ); + pe.value() = "c2 local"; // <<-- mess is like name ... | + // . + c1.Send( pe ); + } - cerr << hex << pa << dec << endl; + scnd.try_wait(); + + mgr.close(); + mgr.join(); } + catch ( ... ) { + } - cerr << "1.1\n"; - - scnd.try_wait(); - - mgr.close(); - mgr.join(); - exit( 0 ); } catch ( xmt::fork_in_parent& child ) { @@ -479,56 +528,67 @@ } try { + // Client 2 xmt::Thread::fork(); - stem::NetTransportMgr mgr; - cerr << "2\n"; +#if 0 + struct sigaction action; + struct sigaction old_action; + action.sa_flags = 0; + action.sa_handler = &dummy_signal_handler; + sigemptyset( &action.sa_mask ); - PeerClient c2( "c2 local" ); // c2 client + sigaction( SIGFPE, &action, &old_action ); + sigaction( SIGTRAP, &action, &old_action ); + sigaction( SIGSEGV, &action, &old_action ); + sigaction( SIGBUS, &action, &old_action ); + sigaction( SIGABRT, &action, &old_action ); + sigaction( SIGALRM, &action, &old_action ); +#endif - fcnd.try_wait(); - stem::addr_type zero = mgr.open( "localhost", 6995 ); // take address of 'zero' (aka default) object via net transport from server - // It done like it should on client side + try { + stem::NetTransportMgr mgr; + // ^ + PeerClient c2( "c2 local" ); // <<--- name the same as mess expected ... | - BOOST_CHECK( zero != stem::badaddr ); - BOOST_CHECK( zero != 0 ); - BOOST_CHECK( zero & stem::extbit ); // "external" address + fcnd.try_wait(); + stem::addr_type zero = mgr.open( "localhost", 6995 ); // take address of 'zero' (aka default) object via net transport from server + // It done like it should on client side - stem::Event ev( NODE_EV_REGME ); - ev.dest( zero ); + BOOST_CHECK( zero != stem::badaddr ); + BOOST_CHECK( zero != 0 ); + BOOST_CHECK( zero & stem::extbit ); // "external" address - ev.value() = "c2@here"; - c2.Send( ev ); // 'register' c2 client on 'echo' server + stem::Event ev( NODE_EV_REGME ); + ev.dest( zero ); - cerr << "2.1\n"; + ev.value() = "c2@here"; + c2.Send( ev ); // 'register' c2 client on 'echo' server - pcnd.set( true ); + pcnd.set( true ); - c2.wait(); - cerr << "2.2\n"; + c2.wait(); + cerr << "Fine!" << endl; + scnd.set( true ); - scnd.set( true ); + mgr.close(); + mgr.join(); + } + catch ( ... ) { + } - mgr.close(); - mgr.join(); - exit( 0 ); } catch ( xmt::fork_in_parent& child ) { sockmgr_stream_MP<stem::NetTransport> srv( 6995 ); // server, it serve 'echo' StEMecho echo( 0, "echo service"); // <= zero! 'echo' server, default ('zero' address) - cerr << "3\n"; fcnd.set( true, true ); - // scnd.try_wait(); - int stat; waitpid( child.pid(), &stat, 0 ); waitpid( fpid, &stat, 0 ); - cerr << "3.1\n"; - srv.close(); srv.wait(); } @@ -539,105 +599,6 @@ shmdt( buf ); shmctl( id, IPC_RMID, &ds ); - -#if 0 - /* - * Scheme: - * / NetTransport / c1 - * Local Event Manager - NetTransportMgr - c2 - * \ echo - * Due to all objects in the same process space, - * c1 and c2 use the same Local Event Manager - * but I try to bypass this fact. - * I.e. I try to simulate - * - * / NetTransport ~~ NetTransportMgr - LEM - c1 - * Local Event Manager \ - * \ echo ~~ NetTransportMgr - LEM - c2 - * - * and provide simulation of logical connection - * - * / c1 - * echo - * \ c2 - * - * (c1 <-> c2, through 'echo') - */ - - sockmgr_stream_MP<stem::NetTransport> srv( 6995 ); // server, it serve 'echo' - - stem::NetTransportMgr mgr; - StEMecho echo( 0, "echo service"); // <= zero! 'echo' server, default ('zero' address) - - echo.cnd.set( false ); - - stem::addr_type zero = mgr.open( "localhost", 6995 ); // take address of 'zero' (aka default) object via net transport from server - // It done like it should on client side - - BOOST_CHECK( zero != stem::badaddr ); - BOOST_CHECK( zero != 0 ); - BOOST_CHECK( zero & stem::extbit ); // "external" address - - PeerClient c1( "c1 local" ); // c1 client - - stem::Event ev( NODE_EV_REGME ); - ev.dest( zero ); - - ev.value() = "c1@here"; - c1.Send( ev ); // 'register' c1 client on 'echo' server - - echo.cnd.try_wait(); - echo.cnd.set( false ); - - PeerClient c2( "c2 local" ); // c2 client - - ev.value() = "c2@here"; - c2.Send( ev ); // 'register' c2 client on 'echo' server - - echo.cnd.try_wait(); - - Naming nm; // use it to take names from NS - - // stem::Event ev_nm( EV_STEM_RQ_ADDR_LIST1 ); - stem::Event ev_nm( EV_STEM_RQ_EXT_ADDR_LIST1 ); - ev_nm.dest( /* stem::ns_addr */ mgr.ns() ); - nm.Send( ev_nm ); - - nm.wait(); - - stem::addr_type peer_addr = stem::badaddr; - - // This is to make chance for mapping address later: - stem::NetTransport_base *tr = c1.manager()->transport( mgr.ns() ); - - BOOST_CHECK( tr != 0 ); // processed via network transport, indeed - - for ( Naming::nsrecords_type::const_iterator i = nm.lst1.begin(); i != nm.lst1.end(); ++i ) { - BOOST_CHECK( i->first & stem::extbit ); // "external" - if ( i->second.find( "c2@" ) == 0 ) { - // make pair: address on side of c1 -> address on side of 'echo' - peer_addr = c1.manager()->SubscribeRemote( tr, i->first, "c2@foreign" ); - } - // cerr << hex << i->first << dec << " => " << i->second << endl; - // cerr << hex << tr->make_map( i->first, "map" ) << dec << endl; - } - BOOST_CHECK( peer_addr != stem::badaddr ); // address found - BOOST_CHECK( peer_addr & stem::extbit ); // address external - - stem::Event echo_ev( NODE_EV_ECHO ); - - echo_ev.dest( /* 0x8000000b */ peer_addr ); - echo_ev.value() = "c2 local"; - - c1.Send( echo_ev ); - - c2.wait(); - - mgr.close(); - srv.close(); - - srv.wait(); -#endif } struct stem_test_suite : @@ -680,7 +641,7 @@ add( ns_tc ); add( echo_tc ); - // add( echo_net_tc ); + add( echo_net_tc ); add( peer_tc ); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2006-11-29 11:55:21
|
Revision: 1423 http://svn.sourceforge.net/complement/?rev=1423&view=rev Author: complement Date: 2006-11-29 03:55:20 -0800 (Wed, 29 Nov 2006) Log Message: ----------- code reorganization to avoid problems with order of static objects dtors calls and libraries unload order; libxmt: version 1.9.3 Modified Paths: -------------- trunk/complement/explore/include/mt/uid.h trunk/complement/explore/lib/mt/ChangeLog trunk/complement/explore/lib/mt/uid.cc Modified: trunk/complement/explore/include/mt/uid.h =================================================================== --- trunk/complement/explore/include/mt/uid.h 2006-11-29 08:07:54 UTC (rev 1422) +++ trunk/complement/explore/include/mt/uid.h 2006-11-29 11:55:20 UTC (rev 1423) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/27 18:07:44 ptr> +// -*- C++ -*- Time-stamp: <06/11/29 13:38:05 ptr> /* * Copyright (c) 2006 @@ -62,7 +62,7 @@ } }; -const std::string& hostid_str(); +const char *hostid_str(); const xmt::uuid_type& hostid(); } // namespace xmt Modified: trunk/complement/explore/lib/mt/ChangeLog =================================================================== --- trunk/complement/explore/lib/mt/ChangeLog 2006-11-29 08:07:54 UTC (rev 1422) +++ trunk/complement/explore/lib/mt/ChangeLog 2006-11-29 11:55:20 UTC (rev 1423) @@ -5,6 +5,9 @@ really. I use syscall here and rewrite appropriate var during Thread::fork(). + * uid.h, uid.cc: code reorganization to avoid problems with order + of static objects dtors calls and libraries unload order. + * libxmt: version 1.9.3 2006-11-23 Petr Ovtchenkov <pt...@is...> Modified: trunk/complement/explore/lib/mt/uid.cc =================================================================== --- trunk/complement/explore/lib/mt/uid.cc 2006-11-29 08:07:54 UTC (rev 1422) +++ trunk/complement/explore/lib/mt/uid.cc 2006-11-29 11:55:20 UTC (rev 1423) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/28 12:31:04 ptr> +// -*- C++ -*- Time-stamp: <06/11/29 13:38:19 ptr> /* * Copyright (c) 2006 @@ -13,6 +13,7 @@ #include <fstream> #include <sstream> #include <iomanip> +#include <cstring> namespace xmt { @@ -26,22 +27,25 @@ public: __uid_init(); - static Mutex _lk; static uuid_type _host_id; - static string _host_id_str; + static char _host_id_str[48]; // 37 really }; -Mutex __uid_init::_lk; uuid_type __uid_init::_host_id; -string __uid_init::_host_id_str; +char __uid_init::_host_id_str[48]; __uid_init::__uid_init() { + static Mutex _lk; + Locker lock( _lk ); ifstream f( "/proc/sys/kernel/random/boot_id" ); - getline( f, _host_id_str ); + string tmp; + getline( f, tmp ); + strcpy( _host_id_str, tmp.c_str() ); + stringstream s; s << _host_id_str[0] << _host_id_str[1] << ' ' << _host_id_str[2] << _host_id_str[3] << ' ' @@ -81,7 +85,7 @@ } // namespace detail -const std::string& hostid_str() +const char *hostid_str() { static detail::__uid_init _uid; return detail::__uid_init::_host_id_str; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2006-11-29 08:07:55
|
Revision: 1422 http://svn.sourceforge.net/complement/?rev=1422&view=rev Author: complement Date: 2006-11-29 00:07:54 -0800 (Wed, 29 Nov 2006) Log Message: ----------- nettransport/nettransport name resolving work now Modified Paths: -------------- trunk/complement/explore/include/stem/EvManager.h trunk/complement/explore/lib/stem/EvManager.cc trunk/complement/explore/lib/stem/Names.cc trunk/complement/explore/lib/stem/NetTransport.cc trunk/complement/explore/test/libstem/unit/NameService.cc trunk/complement/explore/test/libstem/unit/unit_test.cc Modified: trunk/complement/explore/include/stem/EvManager.h =================================================================== --- trunk/complement/explore/include/stem/EvManager.h 2006-11-29 08:05:27 UTC (rev 1421) +++ trunk/complement/explore/include/stem/EvManager.h 2006-11-29 08:07:54 UTC (rev 1422) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/28 16:52:05 ptr> +// -*- C++ -*- Time-stamp: <06/11/29 02:52:45 ptr> /* * Copyright (c) 1995-1999, 2002, 2003, 2005, 2006 @@ -89,6 +89,13 @@ { return l.second < r.second; } public: + + enum traceflags { + notrace = 0, + tracenet = 1, + tracedispatch = 2 + }; + typedef std::queue< Event > queue_type; __FIT_DECLSPEC EvManager(); @@ -106,6 +113,10 @@ __FIT_DECLSPEC addr_type SubscribeRemote( const detail::transport& tr, const gaddr_type& addr, const char *info = 0 ); + __FIT_DECLSPEC addr_type SubscribeRemote( const gaddr_type& addr, + const std::string& info ); + __FIT_DECLSPEC addr_type SubscribeRemote( const gaddr_type& addr, + const char *info = 0 ); __FIT_DECLSPEC bool Unsubscribe( addr_type id ); __FIT_DECLSPEC addr_type reflect( const gaddr_type& addr ) const; __FIT_DECLSPEC gaddr_type reflect( addr_type addr ) const; Modified: trunk/complement/explore/lib/stem/EvManager.cc =================================================================== --- trunk/complement/explore/lib/stem/EvManager.cc 2006-11-29 08:05:27 UTC (rev 1421) +++ trunk/complement/explore/lib/stem/EvManager.cc 2006-11-29 08:07:54 UTC (rev 1422) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/28 21:47:34 ptr> +// -*- C++ -*- Time-stamp: <06/11/29 10:49:19 ptr> /* * @@ -115,7 +115,7 @@ Locker lk( _lock_xheap ); gaddr_type& gaddr = _ex_heap[id]; gaddr.hid = xmt::hostid(); - gaddr.pid = getpid(); + gaddr.pid = xmt::getpid(); gaddr.addr = id; _ui_heap[gaddr] = id; } @@ -139,7 +139,7 @@ Locker lk( _lock_xheap ); gaddr_type& gaddr = _ex_heap[id]; gaddr.hid = xmt::hostid(); - gaddr.pid = getpid(); + gaddr.pid = xmt::getpid(); gaddr.addr = id; _ui_heap[gaddr] = id; } @@ -168,7 +168,7 @@ Locker lk( _lock_xheap ); gaddr_type& gaddr = _ex_heap[id]; gaddr.hid = xmt::hostid(); - gaddr.pid = getpid(); + gaddr.pid = xmt::getpid(); gaddr.addr = id; _ui_heap[gaddr] = id; } @@ -196,7 +196,7 @@ Locker lk( _lock_xheap ); gaddr_type& gaddr = _ex_heap[id]; gaddr.hid = xmt::hostid(); - gaddr.pid = getpid(); + gaddr.pid = xmt::getpid(); gaddr.addr = id; _ui_heap[gaddr] = id; } @@ -253,6 +253,111 @@ } __FIT_DECLSPEC +addr_type EvManager::SubscribeRemote( const gaddr_type& addr, + const std::string& info ) +{ + cerr << __FILE__ << ":" << __LINE__ << endl; + + addr_type id; + if ( addr.hid == xmt::hostid() && addr.pid == xmt::getpid() ) { // local + cerr << __FILE__ << ":" << __LINE__ << endl; + if ( addr.addr & extbit ) { // may be transit object + Locker lk( _lock_xheap ); + uuid_ext_heap_type::const_iterator i = _ui_heap.find( addr ); + + if ( i != _ui_heap.end() ) { + return i->second; + } + } else { // may be local object + Locker lk( _lock_heap ); + local_heap_type::const_iterator i = heap.find( addr.addr ); + if ( i != heap.end() ) { + return i->first; + } + } + return badaddr; // don't know what I can made + } else { // foreign object + cerr << __FILE__ << ":" << __LINE__ << endl; + Locker lk( _lock_xheap ); + uuid_ext_heap_type::const_iterator i = _ui_heap.find( addr ); + + if ( i != _ui_heap.end() ) { + cerr << __FILE__ << ":" << __LINE__ << endl; + return i->second; + } + gaddr_type peer_zero( addr ); + peer_zero.addr = default_addr; + pair<uuid_tr_heap_type::const_iterator,uuid_tr_heap_type::const_iterator> range = _tr_heap.equal_range( peer_zero ); + cerr << __FILE__ << ":" << __LINE__ << "\n" << peer_zero << endl; + if ( range.first == range.second ) { // no transport + cerr << "#####" << endl;// << __FILE__ << ":" << __LINE__ << endl; + return badaddr; + } + id = create_unique_x(); + for ( uuid_tr_heap_type::const_iterator j = range.first; j != range.second; ++j ) { + _tr_heap.insert( make_pair( addr, j->second ) ); // all available transports + _ch_heap.insert( make_pair( j->second.link, addr ) ); + } + _ex_heap[id] = addr; + _ui_heap[addr] = id; + } + { + Locker lk( _lock_iheap ); + iheap[id] = info; + } + return id; +} + +__FIT_DECLSPEC +addr_type EvManager::SubscribeRemote( const gaddr_type& addr, + const char *info ) +{ + addr_type id; + if ( addr.hid == xmt::hostid() && addr.pid == xmt::getpid() ) { + if ( addr.addr & extbit ) { // may be transit object + Locker lk( _lock_xheap ); + uuid_ext_heap_type::const_iterator i = _ui_heap.find( addr ); + + if ( i != _ui_heap.end() ) { + return i->second; + } + } else { // may be local object + Locker lk( _lock_heap ); + local_heap_type::const_iterator i = heap.find( addr.addr ); + if ( i != heap.end() ) { + return i->first; + } + } + return badaddr; // don't know what I can made + } else { + Locker lk( _lock_xheap ); + uuid_ext_heap_type::const_iterator i = _ui_heap.find( addr ); + + if ( i != _ui_heap.end() ) { + return i->second; + } + gaddr_type peer_zero( addr ); + peer_zero.addr = default_addr; + pair<uuid_tr_heap_type::const_iterator,uuid_tr_heap_type::const_iterator> range = _tr_heap.equal_range( peer_zero ); + if ( range.first == range.second ) { // no transport + return badaddr; + } + id = create_unique_x(); + for ( uuid_tr_heap_type::const_iterator j = range.first; j != range.second; ++j ) { + _tr_heap.insert( make_pair( addr, j->second ) ); // all available transports + _ch_heap.insert( make_pair( j->second.link, addr ) ); + } + _ex_heap[id] = addr; + _ui_heap[addr] = id; + } + if ( info ) { + Locker _x1( _lock_iheap ); + iheap[id] = info; + } + return id; +} + +__FIT_DECLSPEC bool EvManager::Unsubscribe( addr_type id ) { if ( (id & extbit) ) { @@ -291,9 +396,9 @@ if ( stem::superflag != 0 ) { cerr << "%%%%%\n"; cerr << addr << endl; - cerr << dec << getpid() << endl; + cerr << dec << xmt::getpid() << endl; } - if ( addr.hid == xmt::hostid() && addr.pid == getpid() ) { + if ( addr.hid == xmt::hostid() && addr.pid == xmt::getpid() ) { // this host, this process if ( stem::superflag != 0 ) { cerr << "%%%%% 1\n"; @@ -420,7 +525,7 @@ if ( i == _ex_heap.end() ) { // destination not found ostringstream s; s << "external address unknown: " << hex << e.dest() << " from " - << e.src() << ", pid " << getpid() << dec; + << e.src() << ", pid " << xmt::getpid() << dec; throw invalid_argument( s.str() ); } @@ -438,7 +543,7 @@ if ( j == _ex_heap.end() ) { gaddr_type& _gaddr_src = _ex_heap[e.src()]; _gaddr_src.hid = xmt::hostid(); - _gaddr_src.pid = getpid(); + _gaddr_src.pid = xmt::getpid(); _gaddr_src.addr = e.src(); // it may be as local as foreign; if e.src() // is foreign, the object is 'transit object' _ui_heap[_gaddr_src] = e.src(); Modified: trunk/complement/explore/lib/stem/Names.cc =================================================================== --- trunk/complement/explore/lib/stem/Names.cc 2006-11-29 08:05:27 UTC (rev 1421) +++ trunk/complement/explore/lib/stem/Names.cc 2006-11-29 08:07:54 UTC (rev 1422) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/28 17:12:45 ptr> +// -*- C++ -*- Time-stamp: <06/11/29 10:21:44 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 @@ -83,24 +83,18 @@ manager()->_lock_iheap.lock(); for ( EvManager::info_heap_type::const_iterator i = manager()->iheap.begin(); i != manager()->iheap.end(); ++i ) { - cerr << hex << i->first << " => " << i->second << endl; if ( i->second == rq.value() ) { - if ( /* i->first & extbit */ true ) { + if ( i->first & extbit /* true */ ) { Locker lk( manager()->_lock_xheap ); EvManager::ext_uuid_heap_type::const_iterator j = manager()->_ex_heap.find( i->first ); if ( j != manager()->_ex_heap.end() ) { lst.push_back( make_pair( j->second, i->second ) ); - cerr << "Found\n"; } } else { Locker lk( manager()->_lock_heap ); EvManager::local_heap_type::const_iterator j = manager()->heap.find( i->first ); if ( j != manager()->heap.end() ) { - gaddr_type gaddr; - gaddr.hid = xmt::hostid(); - gaddr.pid = getpid(); - gaddr.addr = j->first; - lst.push_back( make_pair( gaddr, i->second ) ); + lst.push_back( make_pair( gaddr_type(xmt::hostid(), xmt::getpid(), j->first ), i->second ) ); } } } @@ -108,7 +102,6 @@ manager()->_lock_iheap.unlock(); rs.dest( rq.src() ); - cerr << "Send\n"; Send( rs ); } Modified: trunk/complement/explore/lib/stem/NetTransport.cc =================================================================== --- trunk/complement/explore/lib/stem/NetTransport.cc 2006-11-29 08:05:27 UTC (rev 1421) +++ trunk/complement/explore/lib/stem/NetTransport.cc 2006-11-29 08:07:54 UTC (rev 1422) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/28 21:17:59 ptr> +// -*- C++ -*- Time-stamp: <06/11/29 01:28:01 ptr> /* * @@ -234,7 +234,9 @@ manager()->SubscribeRemote( detail::transport( static_cast<NetTransport_base *>(this), detail::transport::socket_tcp, 10 ), src ); } Event ack( EV_STEM_TRANSPORT_ACK ); - push( ack, src, self_glid() ); // the source (second arg) is NetTransport + if ( !push( ack, src, self_glid() ) ) { // the source (second arg) is NetTransport + throw runtime_error( "net handshake error" ); + } } else { throw runtime_error( "net handshake error" ); } @@ -328,7 +330,9 @@ gaddr_type dst; gaddr_type src; addr_type xsrc = badaddr; - push( ev, gaddr_type(), self_glid() ); + if ( !push( ev, gaddr_type(), self_glid() ) ) { + throw runtime_error( "net error or net handshake error" ); + } if ( pop( ev, dst, src ) ) { if ( ev.code() == EV_STEM_TRANSPORT_ACK ) { src.addr = ns_addr; @@ -392,7 +396,7 @@ try { while ( me.pop( ev, dst, src ) ) { if ( superflag ) { - cerr << "NetTransportMgr::_loop\n"; + cerr << "NetTransportMgr::_loop " << xmt::getpid() << " " << getppid() << endl; manager()->dump( cerr ); cerr << "===\n"; // cerr << dst.hid << dst.pid << dst.addr << endl; Modified: trunk/complement/explore/test/libstem/unit/NameService.cc =================================================================== --- trunk/complement/explore/test/libstem/unit/NameService.cc 2006-11-29 08:05:27 UTC (rev 1421) +++ trunk/complement/explore/test/libstem/unit/NameService.cc 2006-11-29 08:07:54 UTC (rev 1422) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/28 17:03:26 ptr> +// -*- C++ -*- Time-stamp: <06/11/29 10:50:21 ptr> /* * Copyright (c) 2006 @@ -42,7 +42,6 @@ void Naming::names_list( const nsrecords_type& nr ) { - // std::cerr << hex << nr.addr << " " << nr.record << dec << endl; copy( nr.container.begin(), nr.container.end(), back_insert_iterator<nsrecords_type::container_type>(lst) ); cnd.set(true); @@ -50,8 +49,6 @@ void Naming::names_name( const nsrecords_type& nr ) { - std::cerr << hex << /* nr.addr */ "Naming::names_name" << dec << endl; - copy( nr.container.begin(), nr.container.end(), back_insert_iterator<nsrecords_type::container_type>(lst) ); cnd.set(true); Modified: trunk/complement/explore/test/libstem/unit/unit_test.cc =================================================================== --- trunk/complement/explore/test/libstem/unit/unit_test.cc 2006-11-29 08:05:27 UTC (rev 1421) +++ trunk/complement/explore/test/libstem/unit/unit_test.cc 2006-11-29 08:07:54 UTC (rev 1422) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/28 17:27:34 ptr> +// -*- C++ -*- Time-stamp: <06/11/29 10:40:45 ptr> /* * Copyright (c) 2002, 2003, 2006 @@ -346,6 +346,22 @@ void stem_test::peer() { cerr << "peer" << endl; + /* + * Scheme: + * / NetTransport / c1 + * Local Event Manager - NetTransportMgr - c2 + * \ echo + * Due to all objects in the same process space, + * c1, c2 and echo in different processes. + * + * The logical scheme is: + * + * / c1 + * echo + * \ c2 + * + * (c1 <-> c2, through 'echo') + */ stem::superflag = 0; @@ -420,7 +436,6 @@ cerr << "@1\n"; Naming::nsrecords_type::const_iterator i; - stem::superflag = 1; do { nm.reset(); @@ -433,11 +448,30 @@ BOOST_CHECK( i != nm.lst.end() ); BOOST_CHECK( i->second == "c2@here" ); - // c1.manager()->reflect( i->first ); + stem::addr_type pa = c1.manager()->reflect( i->first ); + if ( pa == stem::badaddr ) { // unknown yet + pa = c1.manager()->SubscribeRemote( i->first, i->second ); + } + // stem::superflag = 1; + c1.manager()->dump( cerr ); + + if ( pa != stem::badaddr ) { + stem::Event pe( NODE_EV_ECHO ); + pe.dest( pa ); + pe.value() = "peer client"; + c1.Send( pe ); + + cerr << hex << pa << dec << endl; + } + cerr << "1.1\n"; - scnd.set( true, true ); + scnd.try_wait(); + + mgr.close(); + mgr.join(); + exit( 0 ); } catch ( xmt::fork_in_parent& child ) { @@ -469,8 +503,15 @@ cerr << "2.1\n"; pcnd.set( true ); - scnd.try_wait(); + + c2.wait(); cerr << "2.2\n"; + + scnd.set( true ); + + mgr.close(); + mgr.join(); + exit( 0 ); } catch ( xmt::fork_in_parent& child ) { @@ -480,7 +521,7 @@ fcnd.set( true, true ); - scnd.try_wait(); + // scnd.try_wait(); int stat; waitpid( child.pid(), &stat, 0 ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2006-11-29 08:05:30
|
Revision: 1421 http://svn.sourceforge.net/complement/?rev=1421&view=rev Author: complement Date: 2006-11-29 00:05:27 -0800 (Wed, 29 Nov 2006) Log Message: ----------- added xmt::getpid() and xmt:getppid(); ::getpid() really return cached value, so returned pid may be parent's pid really. I use syscall here and rewrite appropriate var during Thread::fork() Modified Paths: -------------- trunk/complement/explore/include/mt/xmt.h trunk/complement/explore/lib/mt/ChangeLog trunk/complement/explore/lib/mt/Makefile.inc trunk/complement/explore/lib/mt/xmt.cc Modified: trunk/complement/explore/include/mt/xmt.h =================================================================== --- trunk/complement/explore/include/mt/xmt.h 2006-11-28 19:10:41 UTC (rev 1420) +++ trunk/complement/explore/include/mt/xmt.h 2006-11-29 08:05:27 UTC (rev 1421) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/27 10:30:33 ptr> +// -*- C++ -*- Time-stamp: <06/11/29 01:50:24 ptr> /* * Copyright (c) 1997-1999, 2002-2006 @@ -1810,6 +1810,9 @@ #endif } +pid_t getpid(); +pid_t getppid(); + } // namespace xmt namespace __impl = xmt; // compatibility Modified: trunk/complement/explore/lib/mt/ChangeLog =================================================================== --- trunk/complement/explore/lib/mt/ChangeLog 2006-11-28 19:10:41 UTC (rev 1420) +++ trunk/complement/explore/lib/mt/ChangeLog 2006-11-29 08:05:27 UTC (rev 1421) @@ -1,3 +1,12 @@ +2006-11-29 Petr Ovtchenkov <pt...@is...> + + * xmt.h, xmt.cc: added xmt::getpid() and xmt:getppid(); ::getpid() + really return cached value, so returned pid may be parent's pid + really. I use syscall here and rewrite appropriate var during + Thread::fork(). + + * libxmt: version 1.9.3 + 2006-11-23 Petr Ovtchenkov <pt...@is...> * uid.h, uid.cc: return hostid on Linux Modified: trunk/complement/explore/lib/mt/Makefile.inc =================================================================== --- trunk/complement/explore/lib/mt/Makefile.inc 2006-11-28 19:10:41 UTC (rev 1420) +++ trunk/complement/explore/lib/mt/Makefile.inc 2006-11-29 08:05:27 UTC (rev 1421) @@ -1,8 +1,8 @@ -# -*- Makefile -*- Time-stamp: <06/11/23 17:32:14 ptr> +# -*- Makefile -*- Time-stamp: <06/11/29 01:59:50 ptr> LIBNAME = xmt MAJOR = 1 MINOR = 9 -PATCH = 2 +PATCH = 3 SRC_CC = xmt.cc thr_mgr.cc time.cc uid.cc SRC_C = fl.c Modified: trunk/complement/explore/lib/mt/xmt.cc =================================================================== --- trunk/complement/explore/lib/mt/xmt.cc 2006-11-28 19:10:41 UTC (rev 1420) +++ trunk/complement/explore/lib/mt/xmt.cc 2006-11-29 08:05:27 UTC (rev 1421) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/10/24 09:32:17 ptr> +// -*- C++ -*- Time-stamp: <06/11/29 03:10:16 ptr> /* * Copyright (c) 1997-1999, 2002-2006 @@ -46,6 +46,7 @@ #endif #include <stdio.h> +#include <syscall.h> #include <cmath> // for time operations @@ -79,6 +80,12 @@ int Init_count = 0; +// problem: ::getpid() really return cached value, so pid returned may be +// parent's pid really. I use syscall here and rewrite it during Thread::fork(). + +static pid_t _pid = syscall( SYS_getpid ); +static pid_t _ppid = syscall( SYS_getppid ); + #ifdef __FIT_NOVELL_THREADS xmt::Thread::thread_key_type _mt_key = 0; #else // !__FIT_NOVELL_THREADS @@ -227,12 +234,7 @@ } char *Init_buf[32]; -// int Thread::Init::_count = 0; -#if defined(_MSC_VER) && (_MSC_VER <= 1200) -int& Thread::Init::_count = detail::Init_count; // trick to avoid friend declarations -#else int& Thread::Init::_count( detail::Init_count ); // trick to avoid friend declarations -#endif const std::string msg1( "Can't create thread" ); const std::string msg2( "Can't fork" ); @@ -311,11 +313,7 @@ const Thread::thread_id_type Thread::bad_thread_id = EFAILURE; #endif // __FIT_NOVELL_THREADS -#if defined(_MSC_VER) && (_MSC_VER <= 1200) -Thread::thread_key_type& Thread::_mt_key = detail::_mt_key; -#else Thread::thread_key_type& Thread::_mt_key( detail::_mt_key ); -#endif __FIT_DECLSPEC void Thread::_dealloc_uw() @@ -724,6 +722,8 @@ if ( f.pid() == -1 ) { throw std::runtime_error( msg2 ); } + detail::_ppid = detail::_pid; + detail::_pid = syscall( SYS_getpid ); #endif } @@ -1004,4 +1004,14 @@ return _idx++; } +pid_t getpid() +{ + return detail::_pid; +} + +pid_t getppid() +{ + return detail::_ppid; +} + } // namespace xmt This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2006-11-28 19:10:50
|
Revision: 1420 http://svn.sourceforge.net/complement/?rev=1420&view=rev Author: complement Date: 2006-11-28 11:10:41 -0800 (Tue, 28 Nov 2006) Log Message: ----------- debugging; problem with global address assign Modified Paths: -------------- trunk/complement/explore/include/stem/EvManager.h trunk/complement/explore/include/stem/EventHandler.h trunk/complement/explore/lib/stem/EvManager.cc trunk/complement/explore/lib/stem/Names.cc trunk/complement/explore/lib/stem/NetTransport.cc trunk/complement/explore/lib/stem/_EventHandler.cc trunk/complement/explore/test/libstem/unit/Echo.cc trunk/complement/explore/test/libstem/unit/NameService.cc trunk/complement/explore/test/libstem/unit/unit_test.cc Modified: trunk/complement/explore/include/stem/EvManager.h =================================================================== --- trunk/complement/explore/include/stem/EvManager.h 2006-11-28 10:08:16 UTC (rev 1419) +++ trunk/complement/explore/include/stem/EvManager.h 2006-11-28 19:10:41 UTC (rev 1420) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/28 11:06:04 ptr> +// -*- C++ -*- Time-stamp: <06/11/28 16:52:05 ptr> /* * Copyright (c) 1995-1999, 2002, 2003, 2005, 2006 @@ -178,6 +178,8 @@ info_heap_type::iterator i = iheap.find( id ); if ( i != iheap.end() ) { i->second = info; + } else { + iheap[id] = info; } } @@ -185,7 +187,13 @@ { info_heap_type::iterator i = iheap.find( id ); if ( i != iheap.end() ) { - i->second = info; + if ( info != 0 ) { + i->second = info; + } else { + i->second.clear(); + } + } else if ( info != 0 ) { + iheap[id] = info; } } Modified: trunk/complement/explore/include/stem/EventHandler.h =================================================================== --- trunk/complement/explore/include/stem/EventHandler.h 2006-11-28 10:08:16 UTC (rev 1419) +++ trunk/complement/explore/include/stem/EventHandler.h 2006-11-28 19:10:41 UTC (rev 1420) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/24 20:32:06 ptr> +// -*- C++ -*- Time-stamp: <06/11/28 20:29:41 ptr> /* * Copyright (c) 1995-1999, 2002, 2003, 2005, 2006 @@ -572,7 +572,7 @@ Init(); ~Init(); private: - static int _count; + static void _guard( int ); }; __FIT_DECLSPEC EventHandler(); @@ -662,7 +662,8 @@ const_h_iterator __find( state_type ) const; addr_type _id; - static EvManager *_mgr; + static class EvManager *_mgr; + static class Names *_ns; friend class Init; }; Modified: trunk/complement/explore/lib/stem/EvManager.cc =================================================================== --- trunk/complement/explore/lib/stem/EvManager.cc 2006-11-28 10:08:16 UTC (rev 1419) +++ trunk/complement/explore/lib/stem/EvManager.cc 2006-11-28 19:10:41 UTC (rev 1420) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/28 12:33:34 ptr> +// -*- C++ -*- Time-stamp: <06/11/28 21:47:34 ptr> /* * @@ -40,8 +40,11 @@ std::string EvManager::inv_key_str( "invalid key" ); -// int EvManager_flags = 0; +extern int superflag; +int superflag; +std::ostream& operator <<( std::ostream& s, const gaddr_type& ga ); + __FIT_DECLSPEC EvManager::EvManager() : _low( beglocaddr ), _high( endlocaddr ), @@ -246,8 +249,6 @@ iheap[id] = info; } - // cerr << "EvManager:: " << tr.link << " / " << hex << addr.pid << " + " << addr.addr << " - " << id << " = " << getpid() << dec << endl; - return id; } @@ -287,12 +288,23 @@ __FIT_DECLSPEC addr_type EvManager::reflect( const gaddr_type& addr ) const { + if ( stem::superflag != 0 ) { + cerr << "%%%%%\n"; + cerr << addr << endl; + cerr << dec << getpid() << endl; + } if ( addr.hid == xmt::hostid() && addr.pid == getpid() ) { // this host, this process + if ( stem::superflag != 0 ) { + cerr << "%%%%% 1\n"; + } if ( (addr.addr & extbit) == 0 ) { // looks like local object Locker _x1( _lock_heap ); local_heap_type::const_iterator l = heap.find( addr.addr ); if ( l != heap.end() ) { + if ( superflag != 0 ) { + cerr << "%%%%% 2\n"; + } return addr.addr; // l->first } } @@ -317,8 +329,14 @@ Locker _x1( _lock_xheap ); uuid_ext_heap_type::const_iterator i = _ui_heap.find( addr ); if ( i == _ui_heap.end() ) { + if ( stem::superflag != 0 ) { + cerr << "%%%%% 3\n"; + } return badaddr; } + if ( stem::superflag != 0 ) { + cerr << "%%%%% 4\n"; + } return i->second; } @@ -348,21 +366,26 @@ __FIT_DECLSPEC void EvManager::unsafe_Remove( void *channel ) { - // cerr << "Remove channel " << channel << hex << " " << getpid() << dec << endl; + if ( superflag != 0 ) { + cerr << "Remove channel" << endl; + // dump( cerr ); + cerr << "==== 1" << endl; + // abort(); + } pair<tr_uuid_heap_type::iterator,tr_uuid_heap_type::iterator> ch_range = _ch_heap.equal_range( channel ); for (tr_uuid_heap_type::iterator i = ch_range.first; i != ch_range.second; ++i ) { -#if 1 _tr_heap.erase( i->second ); addr_type address = _ui_heap[i->second]; _ex_heap.erase( address ); iheap.erase( address ); _ui_heap.erase( i->second ); -#else - cerr << i->first << "; " << hex << i->second.addr << dec << endl; - cerr << hex << _ui_heap[i->second] << dec << endl; -#endif } _ch_heap.erase( ch_range.first, ch_range.second ); + if ( superflag != 0 ) { + cerr << "==== 2" << endl; + dump( cerr ); + cerr << "==== 3" << endl; + } } __FIT_DECLSPEC const detail::transport& EvManager::transport( addr_type id ) const @@ -428,11 +451,10 @@ switch ( k ) { case detail::transport::socket_tcp: - if ( reinterpret_cast<NetTransport_base *>(link)->push( e, gaddr_dst, gaddr_src) ) { + if ( !reinterpret_cast<NetTransport_base *>(link)->push( e, gaddr_dst, gaddr_src) ) { // if I detect bad connection during writing to net // (in the push), I remove this connetion related entries. - // Required by non-Solaris OS. Unsafe variant allow avoid - // deadlock here. + // Unsafe variant allow avoid deadlock here. unsafe_Remove( link ); } break; @@ -463,8 +485,21 @@ EventHandler *object = i->second; // target object _lock_heap.unlock(); + // if ( e.src() & extbit ) { + // xmt::Locker lk( _lock_xheap ); + // + // } + try { + if ( superflag ) { + cerr << hex << e.dest() << " " << e.src() << " " << e.code() << dec << endl; + object->DispatchTrace( e, cerr ); + cerr << endl; + } object->Dispatch( e ); // call dispatcher + if ( superflag ) { + cerr << "***************" << endl; + } } catch ( ... ) { } @@ -529,7 +564,7 @@ << "-" << dec << ga.pid << "-" - << setw(8) << setfill( '0' ) << ga.addr; + << setw(8) << hex << setfill( '0' ) << ga.addr; } __FIT_DECLSPEC std::ostream& EvManager::dump( std::ostream& s ) const Modified: trunk/complement/explore/lib/stem/Names.cc =================================================================== --- trunk/complement/explore/lib/stem/Names.cc 2006-11-28 10:08:16 UTC (rev 1419) +++ trunk/complement/explore/lib/stem/Names.cc 2006-11-28 19:10:41 UTC (rev 1420) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/27 18:45:00 ptr> +// -*- C++ -*- Time-stamp: <06/11/28 17:12:45 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 @@ -77,19 +77,20 @@ void __FIT_DECLSPEC Names::ns_name( const Event& rq ) { - cerr << __FILE__ << ":" << __LINE__ << endl; typedef NameRecords<gaddr_type,string> Seq; Event_base<Seq> rs( EV_STEM_NS_NAME ); Seq::container_type& lst = rs.value().container; manager()->_lock_iheap.lock(); - for ( EvManager::info_heap_type::const_iterator i = manager()->iheap.begin(); i != manager()->iheap.end(); ++i ) { + for ( EvManager::info_heap_type::const_iterator i = manager()->iheap.begin(); i != manager()->iheap.end(); ++i ) { + cerr << hex << i->first << " => " << i->second << endl; if ( i->second == rq.value() ) { if ( /* i->first & extbit */ true ) { Locker lk( manager()->_lock_xheap ); EvManager::ext_uuid_heap_type::const_iterator j = manager()->_ex_heap.find( i->first ); if ( j != manager()->_ex_heap.end() ) { lst.push_back( make_pair( j->second, i->second ) ); + cerr << "Found\n"; } } else { Locker lk( manager()->_lock_heap ); @@ -106,8 +107,8 @@ } manager()->_lock_iheap.unlock(); - cerr << __FILE__ << ":" << __LINE__ << endl; rs.dest( rq.src() ); + cerr << "Send\n"; Send( rs ); } Modified: trunk/complement/explore/lib/stem/NetTransport.cc =================================================================== --- trunk/complement/explore/lib/stem/NetTransport.cc 2006-11-28 10:08:16 UTC (rev 1419) +++ trunk/complement/explore/lib/stem/NetTransport.cc 2006-11-28 19:10:41 UTC (rev 1420) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/28 11:40:21 ptr> +// -*- C++ -*- Time-stamp: <06/11/28 21:17:59 ptr> /* * @@ -33,6 +33,8 @@ using namespace std; +extern int superflag; + #ifdef _BIG_ENDIAN static const uint32_t EDS_MAGIC = 0xc2454453U; #elif defined(_LITTLE_ENDIAN) @@ -96,11 +98,9 @@ __FIT_DECLSPEC void NetTransport_base::close() { - // cerr << __FILE__ << ":" << __LINE__ << endl; if ( net != 0 ) { manager()->Remove( this ); net->close(); - // cerr << __FILE__ << ":" << __LINE__ << endl; net = 0; } } @@ -154,6 +154,10 @@ str += (char)net->get(); } + // if ( superflag ) { + // cerr << __FILE__ << ":" << __LINE__ << " " << net->good() << endl; + // } + return net->good(); } @@ -256,21 +260,15 @@ gaddr_type src; if ( pop( ev, dst, src ) ) { - // cerr << getpid() << "= " << __FILE__ << ":" << __LINE__ << endl; addr_type xdst = manager()->reflect( dst ); - // cerr << getpid() << "= " << __FILE__ << ":" << __LINE__ << " " << hex << xdst << dec << endl; if ( xdst == badaddr ) { - // cerr << getpid() << "= " << __FILE__ << ":" << __LINE__ << endl; return; } - // cerr << __FILE__ << ":" << __LINE__ << endl; ev.dest( xdst ); addr_type xsrc = manager()->reflect( src ); if ( xsrc == badaddr ) { - // cerr << __FILE__ << ":" << __LINE__ << endl; ev.src( manager()->SubscribeRemote( detail::transport( static_cast<NetTransport_base *>(this), detail::transport::socket_tcp, 10 ), src ) ); } else { - // cerr << __FILE__ << ":" << __LINE__ << endl; ev.src( xsrc ); } manager()->push( ev ); @@ -282,7 +280,6 @@ catch ( ... ) { s.close(); } - // cerr << "Disconnected" << endl; } // connect initiator (client) function @@ -290,16 +287,12 @@ __FIT_DECLSPEC NetTransportMgr::~NetTransportMgr() { - // cerr << __FILE__ << ":" << __LINE__ << endl; if ( net ) { - // cerr << __FILE__ << ":" << __LINE__ << endl; net->rdbuf()->shutdown( sock_base::stop_in | sock_base::stop_out ); net->close(); // otherwise _loop may not exited // this->close(); - // cerr << __FILE__ << ":" << __LINE__ << endl; join(); // NetTransport_base::close() called during loop thread termination (see _loop) - // cerr << __FILE__ << ":" << __LINE__ << endl; delete net; net = 0; } @@ -317,7 +310,13 @@ net = new sockstream( hostname, port, stype ); } else if ( net->is_open() ) { // net->close(); + if ( superflag != 0 ) { + // cerr << __FILE__ << ":" << __LINE__ << endl; + } close(); // I should wait termination of _loop, clear EDS address mapping, etc. + if ( superflag != 0 ) { + // cerr << __FILE__ << ":" << __LINE__ << endl; + } net->open( hostname, port, stype ); } else { join(); // This is safe: transparent if no _loop, and wait it if one exist @@ -358,6 +357,9 @@ catch ( runtime_error& err ) { cerr << err.what() << endl; } + catch ( ... ) { + // cerr << __FILE__ << ":" << __LINE__ << endl; + } return badaddr; } @@ -365,14 +367,14 @@ void NetTransportMgr::close() { if ( net ) { - // cerr << __FILE__ << ":" << __LINE__ << endl; + if ( superflag != 0 ) { + // cerr << __FILE__ << ":" << __LINE__ << endl; + } net->rdbuf()->shutdown( sock_base::stop_in | sock_base::stop_out ); net->close(); // otherwise _loop may not exited // this->close(); - // cerr << __FILE__ << ":" << __LINE__ << endl; join(); // NetTransport_base::close() called during loop thread termination (see _loop) - // cerr << __FILE__ << ":" << __LINE__ << endl; delete net; net = 0; } @@ -389,8 +391,17 @@ try { while ( me.pop( ev, dst, src ) ) { + if ( superflag ) { + cerr << "NetTransportMgr::_loop\n"; + manager()->dump( cerr ); + cerr << "===\n"; + // cerr << dst.hid << dst.pid << dst.addr << endl; + } addr_type xdst = manager()->reflect( dst ); if ( xdst == badaddr ) { + if ( superflag ) { + cerr << "xdst == badaddr\n"; + } continue; } ev.dest( xdst ); @@ -400,9 +411,11 @@ } else { ev.src( xsrc ); } + if ( superflag ) { + cerr << "Destination: " << hex << ev.dest() << " Source: " << ev.src() << dec << endl; + } manager()->push( ev ); } - // cerr << __FILE__ << ":" << __LINE__ << endl; me.NetTransport_base::close(); } catch ( ... ) { @@ -418,7 +431,6 @@ void NetTransportMP::connect( sockstream& s ) { Event ev; - // cerr << "Connected: " << _hostname << endl; gaddr_type dst; gaddr_type src; @@ -446,7 +458,6 @@ this->close(); // clear connection net = 0; } - // cerr << "Connected: " << _hostname << endl; } } // namespace stem Modified: trunk/complement/explore/lib/stem/_EventHandler.cc =================================================================== --- trunk/complement/explore/lib/stem/_EventHandler.cc 2006-11-28 10:08:16 UTC (rev 1419) +++ trunk/complement/explore/lib/stem/_EventHandler.cc 2006-11-28 19:10:41 UTC (rev 1420) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/27 17:26:35 ptr> +// -*- C++ -*- Time-stamp: <06/11/28 20:32:35 ptr> /* * Copyright (c) 1995-1999, 2002, 2003, 2005, 2006 @@ -25,14 +25,10 @@ namespace stem { -char *Init_buf[32]; +char *Init_buf[128]; EvManager *EventHandler::_mgr = 0; -stem::Names *_ns = 0; -const char *_ns_name = "ns"; +Names *EventHandler::_ns = 0; -int EventHandler::Init::_count = 0; -xmt::MutexRS _init_lock; - #if 0 // depends where fork happens: in the EvManager loop (stack) or not. extern "C" void __at_fork_prepare() { @@ -51,25 +47,31 @@ } #endif -EventHandler::Init::Init() +void EventHandler::Init::_guard( int direction ) { - MT_REENTRANT_RS( _init_lock, _x ); - if ( _count++ == 0 ) { - EventHandler::_mgr = new EvManager(); - stem::_ns = new Names( ns_addr, _ns_name ); + static xmt::MutexRS _init_lock; + static int _count = 0; + + if ( direction ) { + if ( _count++ == 0 ) { + EventHandler::_mgr = new EvManager(); + EventHandler::_ns = new Names( ns_addr, "ns" ); + } + } else { + --_count; + if ( _count == 1 ) { + delete EventHandler::_ns; + } else if ( _count == 0 ) { + delete EventHandler::_mgr; + } } } +EventHandler::Init::Init() +{ _guard( 1 ); } + EventHandler::Init::~Init() -{ - MT_REENTRANT_RS( _init_lock, _x ); - --_count; - if ( _count == 1 ) { - delete stem::_ns; - } else if ( _count == 0 ) { - delete EventHandler::_mgr; - } -} +{ _guard( 0 ); } __FIT_DECLSPEC const string EventHandler::who_is( addr_type k ) const Modified: trunk/complement/explore/test/libstem/unit/Echo.cc =================================================================== --- trunk/complement/explore/test/libstem/unit/Echo.cc 2006-11-28 10:08:16 UTC (rev 1419) +++ trunk/complement/explore/test/libstem/unit/Echo.cc 2006-11-28 19:10:41 UTC (rev 1420) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/28 11:49:49 ptr> +// -*- C++ -*- Time-stamp: <06/11/28 16:32:53 ptr> /* * Copyright (c) 2006 Modified: trunk/complement/explore/test/libstem/unit/NameService.cc =================================================================== --- trunk/complement/explore/test/libstem/unit/NameService.cc 2006-11-28 10:08:16 UTC (rev 1419) +++ trunk/complement/explore/test/libstem/unit/NameService.cc 2006-11-28 19:10:41 UTC (rev 1420) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/24 20:14:45 ptr> +// -*- C++ -*- Time-stamp: <06/11/28 17:03:26 ptr> /* * Copyright (c) 2006 @@ -50,7 +50,8 @@ void Naming::names_name( const nsrecords_type& nr ) { - // std::cerr << hex << nr.addr << dec << endl; + std::cerr << hex << /* nr.addr */ "Naming::names_name" << dec << endl; + copy( nr.container.begin(), nr.container.end(), back_insert_iterator<nsrecords_type::container_type>(lst) ); cnd.set(true); Modified: trunk/complement/explore/test/libstem/unit/unit_test.cc =================================================================== --- trunk/complement/explore/test/libstem/unit/unit_test.cc 2006-11-28 10:08:16 UTC (rev 1419) +++ trunk/complement/explore/test/libstem/unit/unit_test.cc 2006-11-28 19:10:41 UTC (rev 1420) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/28 11:02:56 ptr> +// -*- C++ -*- Time-stamp: <06/11/28 17:27:34 ptr> /* * Copyright (c) 2002, 2003, 2006 @@ -339,10 +339,16 @@ // cerr << "Fine\n"; } +namespace stem { +extern int superflag; +} + void stem_test::peer() { cerr << "peer" << endl; + stem::superflag = 0; + pid_t fpid; shmid_ds ds; @@ -377,8 +383,11 @@ cerr << "1\n"; fcnd.try_wait(); + // c1.manager()->dump( cerr ); stem::addr_type zero = mgr.open( "localhost", 6995 ); // take address of 'zero' (aka default) object via net transport from server - // It done like it should on client side + // It done like it should on client side + // cerr << "===========" << endl; + // c1.manager()->dump( cerr ); BOOST_CHECK( zero != stem::badaddr ); BOOST_CHECK( zero != 0 ); @@ -400,7 +409,7 @@ BOOST_CHECK( c1.manager()->reflect( ga ) != stem::badaddr ); - c1.manager()->dump( cerr ); + // c1.manager()->dump( cerr ); stem::Event evname( EV_STEM_GET_NS_NAME ); evname.dest( c1.manager()->reflect( ga ) ); @@ -409,12 +418,18 @@ pcnd.try_wait(); cerr << "@1\n"; - nm.Send( evname ); - nm.wait(); - cerr << "@2\n"; - Naming::nsrecords_type::const_iterator i = find_if( nm.lst.begin(), nm.lst.end(), compose1( bind2nd( equal_to<string>(), string( "c2@here" ) ), select2nd<pair<stem::gaddr_type,string> >() ) ); + Naming::nsrecords_type::const_iterator i; + stem::superflag = 1; + do { + nm.reset(); + nm.lst.clear(); + nm.Send( evname ); + nm.wait(); + i = find_if( nm.lst.begin(), nm.lst.end(), compose1( bind2nd( equal_to<string>(), string( "c2@here" ) ), select2nd<pair<stem::gaddr_type,string> >() ) ); + } while ( i == nm.lst.end() ); + BOOST_CHECK( i != nm.lst.end() ); BOOST_CHECK( i->second == "c2@here" ); @@ -455,6 +470,7 @@ pcnd.set( true ); scnd.try_wait(); + cerr << "2.2\n"; exit( 0 ); } catch ( xmt::fork_in_parent& child ) { @@ -470,8 +486,10 @@ waitpid( child.pid(), &stat, 0 ); waitpid( fpid, &stat, 0 ); + cerr << "3.1\n"; + srv.close(); - srv.wait(); + srv.wait(); } (&fcnd)->~__Condition<true>(); @@ -621,7 +639,7 @@ add( ns_tc ); add( echo_tc ); - add( echo_net_tc ); + // add( echo_net_tc ); add( peer_tc ); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2006-11-28 10:08:22
|
Revision: 1419 http://svn.sourceforge.net/complement/?rev=1419&view=rev Author: complement Date: 2006-11-28 02:08:16 -0800 (Tue, 28 Nov 2006) Log Message: ----------- method for dump tables of EvManager Modified Paths: -------------- trunk/complement/explore/include/stem/EvManager.h trunk/complement/explore/lib/stem/EvManager.cc trunk/complement/explore/lib/stem/NetTransport.cc trunk/complement/explore/test/libstem/unit/Echo.cc trunk/complement/explore/test/libstem/unit/unit_test.cc Modified: trunk/complement/explore/include/stem/EvManager.h =================================================================== --- trunk/complement/explore/include/stem/EvManager.h 2006-11-28 10:06:40 UTC (rev 1418) +++ trunk/complement/explore/include/stem/EvManager.h 2006-11-28 10:08:16 UTC (rev 1419) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/26 21:10:31 ptr> +// -*- C++ -*- Time-stamp: <06/11/28 11:06:04 ptr> /* * Copyright (c) 1995-1999, 2002, 2003, 2005, 2006 @@ -29,6 +29,7 @@ #include <stem/Event.h> #include <stem/EventHandler.h> +#include <ostream> namespace stem { @@ -149,6 +150,8 @@ } __FIT_DECLSPEC void Remove( void * ); + __FIT_DECLSPEC std::ostream& dump( std::ostream& ) const; + protected: bool unsafe_is_avail( addr_type id ) const Modified: trunk/complement/explore/lib/stem/EvManager.cc =================================================================== --- trunk/complement/explore/lib/stem/EvManager.cc 2006-11-28 10:06:40 UTC (rev 1418) +++ trunk/complement/explore/lib/stem/EvManager.cc 2006-11-28 10:08:16 UTC (rev 1419) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/27 21:40:35 ptr> +// -*- C++ -*- Time-stamp: <06/11/28 12:33:34 ptr> /* * @@ -246,7 +246,7 @@ iheap[id] = info; } - cerr << "EvManager:: " << tr.link << " / " << hex << addr.pid << " + " << addr.addr << " - " << id << " = " << getpid() << dec << endl; + // cerr << "EvManager:: " << tr.link << " / " << hex << addr.pid << " + " << addr.addr << " - " << id << " = " << getpid() << dec << endl; return id; } @@ -348,7 +348,7 @@ __FIT_DECLSPEC void EvManager::unsafe_Remove( void *channel ) { - cerr << "Remove channel " << channel << hex << " " << getpid() << dec << endl; + // cerr << "Remove channel " << channel << hex << " " << getpid() << dec << endl; pair<tr_uuid_heap_type::iterator,tr_uuid_heap_type::iterator> ch_range = _ch_heap.equal_range( channel ); for (tr_uuid_heap_type::iterator i = ch_range.first; i != ch_range.second; ++i ) { #if 1 @@ -500,9 +500,76 @@ if ( ++_x_id > _x_high ) { _x_id = (_x_id - _x_low) % (_x_high - _x_low) + _x_low; } - } while ( heap.find( _x_id ) != heap.end() ); + } while ( _ex_heap.find( _x_id ) != _ex_heap.end() ); return _x_id; } + +std::ostream& operator <<( ostream& s, const gaddr_type& ga ) +{ + s.unsetf( ios_base::showbase ); + s << hex << setfill('0') + << setw(2) << static_cast<unsigned>(ga.hid.u.b[0]) + << setw(2) << static_cast<unsigned>(ga.hid.u.b[1]) + << setw(2) << static_cast<unsigned>(ga.hid.u.b[2]) + << setw(2) << static_cast<unsigned>(ga.hid.u.b[3]) + << setw(2) << static_cast<unsigned>(ga.hid.u.b[4]) + << setw(2) << static_cast<unsigned>(ga.hid.u.b[5]) + << setw(2) << static_cast<unsigned>(ga.hid.u.b[6]) + << setw(2) << static_cast<unsigned>(ga.hid.u.b[7]) + << setw(2) << static_cast<unsigned>(ga.hid.u.b[8]) + << setw(2) << static_cast<unsigned>(ga.hid.u.b[9]) + << setw(2) << static_cast<unsigned>(ga.hid.u.b[10]) + << setw(2) << static_cast<unsigned>(ga.hid.u.b[11]) + << setw(2) << static_cast<unsigned>(ga.hid.u.b[12]) + << setw(2) << static_cast<unsigned>(ga.hid.u.b[13]) + << setw(2) << static_cast<unsigned>(ga.hid.u.b[14]) + << setw(2) << static_cast<unsigned>(ga.hid.u.b[15]) + << "-" + << dec << ga.pid + << "-" + << setw(8) << setfill( '0' ) << ga.addr; +} + +__FIT_DECLSPEC std::ostream& EvManager::dump( std::ostream& s ) const +{ + s << "Local map:\n"; + + s << hex << showbase; + for ( local_heap_type::const_iterator i = heap.begin(); i != heap.end(); ++i ) { + s << i->first << "\t=> " << i->second << "\n"; + } + + s << "\nInfo map:\n"; + + for ( info_heap_type::const_iterator i = iheap.begin(); i != iheap.end(); ++i ) { + s << i->first << "\t=> '" << i->second << "'\n"; + } + + s << "\nUnique Id map:\n"; + for ( uuid_ext_heap_type::const_iterator i = _ui_heap.begin(); i != _ui_heap.end(); ++i ) { + s << i->first << "\t=> " << hex << showbase << i->second << "\n"; + } + + s << "\nExternal address map:\n"; + for ( ext_uuid_heap_type::const_iterator i = _ex_heap.begin(); i != _ex_heap.end(); ++i ) { + s << hex << showbase << i->first << "\t=> " << i->second << "\n"; + } + + s << "\nUnique Id to transport map:\n"; + for ( uuid_tr_heap_type::const_iterator i = _tr_heap.begin(); i != _tr_heap.end(); ++i ) { + s << i->first << "\t=> " << i->second.link << " " << i->second.metric << "\n"; + } + + s << "\nTransport to Unique Id map:\n"; + for ( tr_uuid_heap_type::const_iterator i = _ch_heap.begin(); i != _ch_heap.end(); ++i ) { + s << i->first << "\t=> " << i->second << "\n"; + } + + s << dec << endl; + + return s; +} + } // namespace stem Modified: trunk/complement/explore/lib/stem/NetTransport.cc =================================================================== --- trunk/complement/explore/lib/stem/NetTransport.cc 2006-11-28 10:06:40 UTC (rev 1418) +++ trunk/complement/explore/lib/stem/NetTransport.cc 2006-11-28 10:08:16 UTC (rev 1419) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/27 20:24:50 ptr> +// -*- C++ -*- Time-stamp: <06/11/28 11:40:21 ptr> /* * @@ -256,21 +256,21 @@ gaddr_type src; if ( pop( ev, dst, src ) ) { - cerr << getpid() << "= " << __FILE__ << ":" << __LINE__ << endl; + // cerr << getpid() << "= " << __FILE__ << ":" << __LINE__ << endl; addr_type xdst = manager()->reflect( dst ); - cerr << getpid() << "= " << __FILE__ << ":" << __LINE__ << " " << hex << xdst << dec << endl; + // cerr << getpid() << "= " << __FILE__ << ":" << __LINE__ << " " << hex << xdst << dec << endl; if ( xdst == badaddr ) { - cerr << getpid() << "= " << __FILE__ << ":" << __LINE__ << endl; + // cerr << getpid() << "= " << __FILE__ << ":" << __LINE__ << endl; return; } - cerr << __FILE__ << ":" << __LINE__ << endl; + // cerr << __FILE__ << ":" << __LINE__ << endl; ev.dest( xdst ); addr_type xsrc = manager()->reflect( src ); if ( xsrc == badaddr ) { - cerr << __FILE__ << ":" << __LINE__ << endl; + // cerr << __FILE__ << ":" << __LINE__ << endl; ev.src( manager()->SubscribeRemote( detail::transport( static_cast<NetTransport_base *>(this), detail::transport::socket_tcp, 10 ), src ) ); } else { - cerr << __FILE__ << ":" << __LINE__ << endl; + // cerr << __FILE__ << ":" << __LINE__ << endl; ev.src( xsrc ); } manager()->push( ev ); Modified: trunk/complement/explore/test/libstem/unit/Echo.cc =================================================================== --- trunk/complement/explore/test/libstem/unit/Echo.cc 2006-11-28 10:06:40 UTC (rev 1418) +++ trunk/complement/explore/test/libstem/unit/Echo.cc 2006-11-28 10:08:16 UTC (rev 1419) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/27 18:33:21 ptr> +// -*- C++ -*- Time-stamp: <06/11/28 11:49:49 ptr> /* * Copyright (c) 2006 @@ -45,7 +45,7 @@ void StEMecho::regme( const stem::Event& ev ) { - cerr << "Echo\n"; + // cerr << "Echo\n"; manager()->change_announce( ev.src(), ev.value() ); cnd.set( true ); } Modified: trunk/complement/explore/test/libstem/unit/unit_test.cc =================================================================== --- trunk/complement/explore/test/libstem/unit/unit_test.cc 2006-11-28 10:06:40 UTC (rev 1418) +++ trunk/complement/explore/test/libstem/unit/unit_test.cc 2006-11-28 10:08:16 UTC (rev 1419) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/27 18:20:55 ptr> +// -*- C++ -*- Time-stamp: <06/11/28 11:02:56 ptr> /* * Copyright (c) 2002, 2003, 2006 @@ -36,6 +36,7 @@ #endif #include <sys/shm.h> +#include <sys/wait.h> using namespace std; @@ -342,6 +343,8 @@ { cerr << "peer" << endl; + pid_t fpid; + shmid_ds ds; int id = shmget( 5000, 1024, IPC_CREAT | IPC_EXCL | 0600 ); if ( id == -1 ) { @@ -397,6 +400,8 @@ BOOST_CHECK( c1.manager()->reflect( ga ) != stem::badaddr ); + c1.manager()->dump( cerr ); + stem::Event evname( EV_STEM_GET_NS_NAME ); evname.dest( c1.manager()->reflect( ga ) ); evname.value() = "c2@here"; @@ -420,8 +425,8 @@ scnd.set( true, true ); exit( 0 ); } - catch ( xmt::fork_in_parent& ) { - + catch ( xmt::fork_in_parent& child ) { + fpid = child.pid(); } try { @@ -452,18 +457,23 @@ scnd.try_wait(); exit( 0 ); } - catch ( xmt::fork_in_parent& ) { - - } + catch ( xmt::fork_in_parent& child ) { + sockmgr_stream_MP<stem::NetTransport> srv( 6995 ); // server, it serve 'echo' + StEMecho echo( 0, "echo service"); // <= zero! 'echo' server, default ('zero' address) + cerr << "3\n"; - sockmgr_stream_MP<stem::NetTransport> srv( 6995 ); // server, it serve 'echo' - StEMecho echo( 0, "echo service"); // <= zero! 'echo' server, default ('zero' address) - cerr << "3\n"; + fcnd.set( true, true ); - fcnd.set( true, true ); + scnd.try_wait(); - scnd.try_wait(); + int stat; + waitpid( child.pid(), &stat, 0 ); + waitpid( fpid, &stat, 0 ); + srv.close(); + srv.wait(); + } + (&fcnd)->~__Condition<true>(); (&pcnd)->~__Condition<true>(); (&scnd)->~__Condition<true>(); @@ -471,9 +481,6 @@ shmdt( buf ); shmctl( id, IPC_RMID, &ds ); - srv.close(); - srv.wait(); - #if 0 /* * Scheme: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2006-11-28 10:06:41
|
Revision: 1418 http://svn.sourceforge.net/complement/?rev=1418&view=rev Author: complement Date: 2006-11-28 02:06:40 -0800 (Tue, 28 Nov 2006) Log Message: ----------- use IPC technique that work to sync after fork (via shm segment) Modified Paths: -------------- trunk/complement/explore/test/libsockios/unit/read0_on_exec.cc Modified: trunk/complement/explore/test/libsockios/unit/read0_on_exec.cc =================================================================== --- trunk/complement/explore/test/libsockios/unit/read0_on_exec.cc 2006-11-28 10:05:20 UTC (rev 1417) +++ trunk/complement/explore/test/libsockios/unit/read0_on_exec.cc 2006-11-28 10:06:40 UTC (rev 1418) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/08/21 23:48:43 ptr> +// -*- C++ -*- Time-stamp: <06/11/28 09:33:13 ptr> /* * @@ -22,6 +22,8 @@ #include <sys/types.h> #include <sys/wait.h> +#include <sys/shm.h> + using namespace std; using namespace xmt; @@ -62,7 +64,6 @@ extern xmt::Mutex pr_lock; // static __Condition<true> cndf; -static Semaphore sem( 1, true ); class ConnectionProcessor5 // dummy variant { @@ -125,6 +126,21 @@ void test_read0() { + shmid_ds ds; + int id = shmget( 5000, 1024, IPC_CREAT | IPC_EXCL | 0600 ); + if ( id == -1 ) { + cerr << "Error on shmget" << endl; + } + if ( shmctl( id, IPC_STAT, &ds ) == -1 ) { + cerr << "Error on shmctl" << endl; + } + void *buf = shmat( id, 0, 0 ); + if ( buf == reinterpret_cast<void *>(-1) ) { + cerr << "Error on shmat" << endl; + } + + Semaphore& sem = *new( buf ) Semaphore( 1, true ); + try { // cerr << "** 1" << endl; // cndf.set( false ); @@ -166,6 +182,10 @@ srv.close(); srv.wait(); } + (&sem)->~Semaphore(); + + shmdt( buf ); + shmctl( id, IPC_RMID, &ds ); } class ConnectionProcessor6 // dummy variant @@ -177,7 +197,7 @@ void close(); }; -static Semaphore sem2( 2, false ); +static Semaphore *sem2; ConnectionProcessor6::ConnectionProcessor6( std::sockstream& s ) { @@ -187,7 +207,7 @@ BOOST_REQUIRE( s.good() ); pr_lock.unlock(); - sem2.post(); + sem2->post(); } void ConnectionProcessor6::connect( std::sockstream& s ) @@ -203,6 +223,21 @@ void test_read0_srv() { + shmid_ds ds; + int id = shmget( 5000, 1024, IPC_CREAT | IPC_EXCL | 0600 ); + if ( id == -1 ) { + cerr << "Error on shmget" << endl; + } + if ( shmctl( id, IPC_STAT, &ds ) == -1 ) { + cerr << "Error on shmctl" << endl; + } + void *buf = shmat( id, 0, 0 ); + if ( buf == reinterpret_cast<void *>(-1) ) { + cerr << "Error on shmat" << endl; + } + + sem2 = new( buf ) Semaphore( 2, true ); + sockmgr_stream_MP<ConnectionProcessor6> srv( ::port ); { @@ -213,7 +248,7 @@ BOOST_CHECK( s.good() ); - sem2.wait(); + sem2->wait(); } system( "echo > /dev/null" ); // <------ key line @@ -226,7 +261,7 @@ BOOST_CHECK( s.good() ); - sem2.wait(); + sem2->wait(); } BOOST_CHECK( srv.good() ); // server must correctly process interrupt during system call @@ -234,4 +269,9 @@ srv.close(); srv.wait(); + + sem2->~Semaphore(); + + shmdt( buf ); + shmctl( id, IPC_RMID, &ds ); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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. |
From: <com...@us...> - 2006-11-28 10:03:32
|
Revision: 1416 http://svn.sourceforge.net/complement/?rev=1416&view=rev Author: complement Date: 2006-11-28 02:03:31 -0800 (Tue, 28 Nov 2006) Log Message: ----------- fix wrong uuid filling Modified Paths: -------------- trunk/complement/explore/lib/mt/uid.cc Modified: trunk/complement/explore/lib/mt/uid.cc =================================================================== --- trunk/complement/explore/lib/mt/uid.cc 2006-11-27 18:53:49 UTC (rev 1415) +++ trunk/complement/explore/lib/mt/uid.cc 2006-11-28 10:03:31 UTC (rev 1416) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/23 17:35:29 ptr> +// -*- C++ -*- Time-stamp: <06/11/28 12:31:04 ptr> /* * Copyright (c) 2006 @@ -42,18 +42,41 @@ getline( f, _host_id_str ); - istringstream s( _host_id_str ); - char delimiter; - - s >> hex >> _host_id.u.b[0] >> _host_id.u.b[1] >> _host_id.u.b[2] >> _host_id.u.b[3] - >> delimiter - >> _host_id.u.b[4] >> _host_id.u.b[5] - >> delimiter - >> _host_id.u.b[6] >> _host_id.u.b[7] - >> delimiter - >> _host_id.u.b[8] >> _host_id.u.b[9] - >> delimiter - >> _host_id.u.b[10] >> _host_id.u.b[11] >> _host_id.u.b[12] >> _host_id.u.b[13] >> _host_id.u.b[14] >> _host_id.u.b[15]; + stringstream s; + s << _host_id_str[0] << _host_id_str[1] << ' ' + << _host_id_str[2] << _host_id_str[3] << ' ' + << _host_id_str[4] << _host_id_str[5] << ' ' + << _host_id_str[6] << _host_id_str[7] << ' ' // - + << _host_id_str[9] << _host_id_str[10] << ' ' + << _host_id_str[11] << _host_id_str[12] << ' ' // - + << _host_id_str[14] << _host_id_str[15] << ' ' + << _host_id_str[16] << _host_id_str[17] << ' ' // - + << _host_id_str[19] << _host_id_str[20] << ' ' + << _host_id_str[21] << _host_id_str[22] << ' ' // - + << _host_id_str[24] << _host_id_str[25] << ' ' + << _host_id_str[26] << _host_id_str[27] << ' ' + << _host_id_str[28] << _host_id_str[29] << ' ' + << _host_id_str[30] << _host_id_str[31] << ' ' + << _host_id_str[32] << _host_id_str[33] << ' ' + << _host_id_str[34] << _host_id_str[35]; + + s >> hex + >> reinterpret_cast<unsigned&>(_host_id.u.b[0]) + >> reinterpret_cast<unsigned&>(_host_id.u.b[1]) + >> reinterpret_cast<unsigned&>(_host_id.u.b[2]) + >> reinterpret_cast<unsigned&>(_host_id.u.b[3]) + >> reinterpret_cast<unsigned&>(_host_id.u.b[4]) + >> reinterpret_cast<unsigned&>(_host_id.u.b[5]) + >> reinterpret_cast<unsigned&>(_host_id.u.b[6]) + >> reinterpret_cast<unsigned&>(_host_id.u.b[7]) + >> reinterpret_cast<unsigned&>(_host_id.u.b[8]) + >> reinterpret_cast<unsigned&>(_host_id.u.b[9]) + >> reinterpret_cast<unsigned&>(_host_id.u.b[10]) + >> reinterpret_cast<unsigned&>(_host_id.u.b[11]) + >> reinterpret_cast<unsigned&>(_host_id.u.b[12]) + >> reinterpret_cast<unsigned&>(_host_id.u.b[13]) + >> reinterpret_cast<unsigned&>(_host_id.u.b[14]) + >> reinterpret_cast<unsigned&>(_host_id.u.b[15]); } } // namespace detail This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2006-11-27 18:53:51
|
Revision: 1415 http://svn.sourceforge.net/complement/?rev=1415&view=rev Author: complement Date: 2006-11-27 10:53:49 -0800 (Mon, 27 Nov 2006) Log Message: ----------- debugging Modified Paths: -------------- trunk/complement/explore/include/stem/NetTransport.h trunk/complement/explore/lib/stem/EvManager.cc trunk/complement/explore/lib/stem/Names.cc trunk/complement/explore/lib/stem/NetTransport.cc trunk/complement/explore/lib/stem/_EventHandler.cc trunk/complement/explore/test/libstem/unit/Echo.cc trunk/complement/explore/test/libstem/unit/unit_test.cc Modified: trunk/complement/explore/include/stem/NetTransport.h =================================================================== --- trunk/complement/explore/include/stem/NetTransport.h 2006-11-27 18:52:47 UTC (rev 1414) +++ trunk/complement/explore/include/stem/NetTransport.h 2006-11-27 18:53:49 UTC (rev 1415) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/24 15:29:19 ptr> +// -*- C++ -*- Time-stamp: <06/11/27 17:22:33 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 Modified: trunk/complement/explore/lib/stem/EvManager.cc =================================================================== --- trunk/complement/explore/lib/stem/EvManager.cc 2006-11-27 18:52:47 UTC (rev 1414) +++ trunk/complement/explore/lib/stem/EvManager.cc 2006-11-27 18:53:49 UTC (rev 1415) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/26 21:21:55 ptr> +// -*- C++ -*- Time-stamp: <06/11/27 21:40:35 ptr> /* * @@ -40,6 +40,8 @@ std::string EvManager::inv_key_str( "invalid key" ); +// int EvManager_flags = 0; + __FIT_DECLSPEC EvManager::EvManager() : _low( beglocaddr ), _high( endlocaddr ), @@ -244,6 +246,8 @@ iheap[id] = info; } + cerr << "EvManager:: " << tr.link << " / " << hex << addr.pid << " + " << addr.addr << " - " << id << " = " << getpid() << dec << endl; + return id; } @@ -344,13 +348,19 @@ __FIT_DECLSPEC void EvManager::unsafe_Remove( void *channel ) { + cerr << "Remove channel " << channel << hex << " " << getpid() << dec << endl; pair<tr_uuid_heap_type::iterator,tr_uuid_heap_type::iterator> ch_range = _ch_heap.equal_range( channel ); for (tr_uuid_heap_type::iterator i = ch_range.first; i != ch_range.second; ++i ) { +#if 1 _tr_heap.erase( i->second ); addr_type address = _ui_heap[i->second]; _ex_heap.erase( address ); iheap.erase( address ); _ui_heap.erase( i->second ); +#else + cerr << i->first << "; " << hex << i->second.addr << dec << endl; + cerr << hex << _ui_heap[i->second] << dec << endl; +#endif } _ch_heap.erase( ch_range.first, ch_range.second ); } @@ -383,22 +393,25 @@ if ( e.dest() & extbit ) { // external object try { _lock_xheap.lock(); - ext_uuid_heap_type::iterator i = _ex_heap.find( e.dest() ); + ext_uuid_heap_type::const_iterator i = _ex_heap.find( e.dest() ); if ( i == _ex_heap.end() ) { // destination not found - throw invalid_argument( string("external address unknown") ); + ostringstream s; + s << "external address unknown: " << hex << e.dest() << " from " + << e.src() << ", pid " << getpid() << dec; + throw invalid_argument( s.str() ); } - pair<uuid_tr_heap_type::iterator,uuid_tr_heap_type::iterator> range = _tr_heap.equal_range( i->second ); + pair<uuid_tr_heap_type::const_iterator,uuid_tr_heap_type::const_iterator> range = _tr_heap.equal_range( i->second ); if ( range.first == _tr_heap.end() ) { throw range_error( string( "no transport" ) ); } - detail::transport& tr = min_element( range.first, range.second, tr_compare )->second; + const detail::transport& tr = min_element( range.first, range.second, tr_compare )->second; detail::transport::kind_type k = tr.kind; void *link = tr.link; gaddr_type gaddr_dst( i->second ); gaddr_type gaddr_src; - ext_uuid_heap_type::iterator j = _ex_heap.find( e.src() ); + ext_uuid_heap_type::const_iterator j = _ex_heap.find( e.src() ); if ( j == _ex_heap.end() ) { gaddr_type& _gaddr_src = _ex_heap[e.src()]; _gaddr_src.hid = xmt::hostid(); @@ -429,6 +442,14 @@ break; } } + catch ( std::logic_error& err ) { + cerr << err.what() << endl; + _lock_xheap.unlock(); + } + catch ( std::runtime_error& err ) { + cerr << err.what() << endl; + _lock_xheap.unlock(); + } catch ( ... ) { _lock_xheap.unlock(); } @@ -448,6 +469,14 @@ catch ( ... ) { } } + catch ( std::logic_error& err ) { + cerr << err.what() << endl; + _lock_heap.unlock(); + } + catch ( std::runtime_error& err ) { + cerr << err.what() << endl; + _lock_heap.unlock(); + } catch ( ... ) { _lock_heap.unlock(); } Modified: trunk/complement/explore/lib/stem/Names.cc =================================================================== --- trunk/complement/explore/lib/stem/Names.cc 2006-11-27 18:52:47 UTC (rev 1414) +++ trunk/complement/explore/lib/stem/Names.cc 2006-11-27 18:53:49 UTC (rev 1415) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/26 12:22:27 ptr> +// -*- C++ -*- Time-stamp: <06/11/27 18:45:00 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 @@ -77,6 +77,7 @@ void __FIT_DECLSPEC Names::ns_name( const Event& rq ) { + cerr << __FILE__ << ":" << __LINE__ << endl; typedef NameRecords<gaddr_type,string> Seq; Event_base<Seq> rs( EV_STEM_NS_NAME ); Seq::container_type& lst = rs.value().container; @@ -105,6 +106,7 @@ } manager()->_lock_iheap.unlock(); + cerr << __FILE__ << ":" << __LINE__ << endl; rs.dest( rq.src() ); Send( rs ); } Modified: trunk/complement/explore/lib/stem/NetTransport.cc =================================================================== --- trunk/complement/explore/lib/stem/NetTransport.cc 2006-11-27 18:52:47 UTC (rev 1414) +++ trunk/complement/explore/lib/stem/NetTransport.cc 2006-11-27 18:53:49 UTC (rev 1415) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/26 19:14:58 ptr> +// -*- C++ -*- Time-stamp: <06/11/27 20:24:50 ptr> /* * @@ -230,7 +230,7 @@ manager()->SubscribeRemote( detail::transport( static_cast<NetTransport_base *>(this), detail::transport::socket_tcp, 10 ), src ); } Event ack( EV_STEM_TRANSPORT_ACK ); - push( ack, src, self_glid() ); + push( ack, src, self_glid() ); // the source (second arg) is NetTransport } else { throw runtime_error( "net handshake error" ); } @@ -256,15 +256,21 @@ gaddr_type src; if ( pop( ev, dst, src ) ) { + cerr << getpid() << "= " << __FILE__ << ":" << __LINE__ << endl; addr_type xdst = manager()->reflect( dst ); + cerr << getpid() << "= " << __FILE__ << ":" << __LINE__ << " " << hex << xdst << dec << endl; if ( xdst == badaddr ) { + cerr << getpid() << "= " << __FILE__ << ":" << __LINE__ << endl; return; } + cerr << __FILE__ << ":" << __LINE__ << endl; ev.dest( xdst ); addr_type xsrc = manager()->reflect( src ); if ( xsrc == badaddr ) { + cerr << __FILE__ << ":" << __LINE__ << endl; ev.src( manager()->SubscribeRemote( detail::transport( static_cast<NetTransport_base *>(this), detail::transport::socket_tcp, 10 ), src ) ); } else { + cerr << __FILE__ << ":" << __LINE__ << endl; ev.src( xsrc ); } manager()->push( ev ); @@ -319,9 +325,6 @@ } if ( net->good() ) { - // _net_ns = rar_map( ns_addr, __ns_at + hostname ); - // addr_type zero_object = rar_map( 0, __at + hostname ); - Event ev( EV_STEM_TRANSPORT ); gaddr_type dst; gaddr_type src; @@ -331,9 +334,12 @@ if ( ev.code() == EV_STEM_TRANSPORT_ACK ) { src.addr = ns_addr; xsrc = manager()->reflect( src ); + // indeed src is something like NetTransport, so substitute ns: + src.addr = ns_addr; if ( xsrc == badaddr ) { manager()->SubscribeRemote( detail::transport( static_cast<NetTransport_base *>(this), detail::transport::socket_tcp, 10 ), src ); } + // indeed src is something like NetTransport, so substitute default: src.addr = default_addr; xsrc = manager()->reflect( src ); if ( xsrc == badaddr ) { Modified: trunk/complement/explore/lib/stem/_EventHandler.cc =================================================================== --- trunk/complement/explore/lib/stem/_EventHandler.cc 2006-11-27 18:52:47 UTC (rev 1414) +++ trunk/complement/explore/lib/stem/_EventHandler.cc 2006-11-27 18:53:49 UTC (rev 1415) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/26 12:22:42 ptr> +// -*- C++ -*- Time-stamp: <06/11/27 17:26:35 ptr> /* * Copyright (c) 1995-1999, 2002, 2003, 2005, 2006 @@ -33,10 +33,28 @@ int EventHandler::Init::_count = 0; xmt::MutexRS _init_lock; +#if 0 // depends where fork happens: in the EvManager loop (stack) or not. +extern "C" void __at_fork_prepare() +{ +} + +extern "C" void __at_fork_child() +{ + if ( EventHandler::Init::_count != 0 ) { + // delete EventHandler::_mgr; + EventHandler::_mgr = new( EventHandler::_mgr ) EvManager(); + } +} + +extern "C" void __at_fork_parent() +{ +} +#endif + EventHandler::Init::Init() { MT_REENTRANT_RS( _init_lock, _x ); - if ( _count++ == 0 ) { + if ( _count++ == 0 ) { EventHandler::_mgr = new EvManager(); stem::_ns = new Names( ns_addr, _ns_name ); } Modified: trunk/complement/explore/test/libstem/unit/Echo.cc =================================================================== --- trunk/complement/explore/test/libstem/unit/Echo.cc 2006-11-27 18:52:47 UTC (rev 1414) +++ trunk/complement/explore/test/libstem/unit/Echo.cc 2006-11-27 18:53:49 UTC (rev 1415) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/10/12 15:12:19 ptr> +// -*- C++ -*- Time-stamp: <06/11/27 18:33:21 ptr> /* * Copyright (c) 2006 @@ -45,6 +45,7 @@ void StEMecho::regme( const stem::Event& ev ) { + cerr << "Echo\n"; manager()->change_announce( ev.src(), ev.value() ); cnd.set( true ); } Modified: trunk/complement/explore/test/libstem/unit/unit_test.cc =================================================================== --- trunk/complement/explore/test/libstem/unit/unit_test.cc 2006-11-27 18:52:47 UTC (rev 1414) +++ trunk/complement/explore/test/libstem/unit/unit_test.cc 2006-11-27 18:53:49 UTC (rev 1415) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/27 11:15:16 ptr> +// -*- C++ -*- Time-stamp: <06/11/27 18:20:55 ptr> /* * Copyright (c) 2002, 2003, 2006 @@ -35,6 +35,8 @@ using namespace __gnu_cxx; #endif +#include <sys/shm.h> + using namespace std; struct stem_test @@ -281,7 +283,6 @@ } catch ( ... ) { } - // cerr << "Fine\n"; } void stem_test::echo_net() @@ -339,13 +340,28 @@ void stem_test::peer() { - xmt::__Condition<true> fcnd; + cerr << "peer" << endl; + + shmid_ds ds; + int id = shmget( 5000, 1024, IPC_CREAT | IPC_EXCL | 0600 ); + if ( id == -1 ) { + cerr << "Error on shmget" << endl; + } + if ( shmctl( id, IPC_STAT, &ds ) == -1 ) { + cerr << "Error on shmctl" << endl; + } + void *buf = shmat( id, 0, 0 ); + if ( buf == reinterpret_cast<void *>(-1) ) { + cerr << "Error on shmat" << endl; + } + + xmt::__Condition<true>& fcnd = *new( buf ) xmt::__Condition<true>(); fcnd.set( false ); - xmt::__Condition<true> pcnd; + xmt::__Condition<true>& pcnd = *new( (char *)buf + sizeof(xmt::__Condition<true>) ) xmt::__Condition<true>(); pcnd.set( false ); - xmt::__Condition<true> scnd; + xmt::__Condition<true>& scnd = *new( (char *)buf + sizeof(xmt::__Condition<true>) * 2 ) xmt::__Condition<true>(); scnd.set( false ); try { @@ -387,8 +403,10 @@ pcnd.try_wait(); + cerr << "@1\n"; nm.Send( evname ); nm.wait(); + cerr << "@2\n"; Naming::nsrecords_type::const_iterator i = find_if( nm.lst.begin(), nm.lst.end(), compose1( bind2nd( equal_to<string>(), string( "c2@here" ) ), select2nd<pair<stem::gaddr_type,string> >() ) ); @@ -399,13 +417,13 @@ cerr << "1.1\n"; - scnd.set( true ); + scnd.set( true, true ); exit( 0 ); } catch ( xmt::fork_in_parent& ) { } -#if 0 + try { xmt::Thread::fork(); stem::NetTransportMgr mgr; @@ -431,20 +449,28 @@ cerr << "2.1\n"; pcnd.set( true ); + scnd.try_wait(); exit( 0 ); } catch ( xmt::fork_in_parent& ) { } -#endif + sockmgr_stream_MP<stem::NetTransport> srv( 6995 ); // server, it serve 'echo' StEMecho echo( 0, "echo service"); // <= zero! 'echo' server, default ('zero' address) cerr << "3\n"; - fcnd.set( true ); + fcnd.set( true, true ); scnd.try_wait(); + (&fcnd)->~__Condition<true>(); + (&pcnd)->~__Condition<true>(); + (&scnd)->~__Condition<true>(); + + shmdt( buf ); + shmctl( id, IPC_RMID, &ds ); + srv.close(); srv.wait(); @@ -569,7 +595,6 @@ test_case *echo_tc = BOOST_CLASS_TEST_CASE( &stem_test::echo, instance ); test_case *echo_net_tc = BOOST_CLASS_TEST_CASE( &stem_test::echo_net, instance ); test_case *peer_tc = BOOST_CLASS_TEST_CASE( &stem_test::peer, instance ); - basic2_tc->depends_on( basic1_tc ); basic1n_tc->depends_on( basic1_tc ); basic2n_tc->depends_on( basic2_tc ); @@ -590,7 +615,7 @@ add( echo_tc ); add( echo_net_tc ); - // add( peer_tc ); + add( peer_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. |
From: <com...@us...> - 2006-11-27 18:52:51
|
Revision: 1414 http://svn.sourceforge.net/complement/?rev=1414&view=rev Author: complement Date: 2006-11-27 10:52:47 -0800 (Mon, 27 Nov 2006) Log Message: ----------- add install-release-static tag Modified Paths: -------------- trunk/complement/extern/custom/boost/libs/Makefile Modified: trunk/complement/extern/custom/boost/libs/Makefile =================================================================== --- trunk/complement/extern/custom/boost/libs/Makefile 2006-11-27 18:49:17 UTC (rev 1413) +++ trunk/complement/extern/custom/boost/libs/Makefile 2006-11-27 18:52:47 UTC (rev 1414) @@ -11,7 +11,7 @@ include ${SRCROOT}/Makefiles/gmake/subdirs.mak -all install depend clean clobber distclean: +all install install-release-static depend clean clobber distclean: $(doinsubdirs) -.PHONY: all install depend clean clobber distclean +.PHONY: all install install-release-static depend clean clobber distclean This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2006-11-27 18:49:39
|
Revision: 1413 http://svn.sourceforge.net/complement/?rev=1413&view=rev Author: complement Date: 2006-11-27 10:49:17 -0800 (Mon, 27 Nov 2006) Log Message: ----------- delete connections objects and sockstreams Modified Paths: -------------- trunk/complement/explore/include/sockios/sockmgr.cc trunk/complement/explore/include/sockios/sockmgr.h trunk/complement/explore/lib/sockios/ChangeLog trunk/complement/explore/lib/sockios/Makefile.inc Modified: trunk/complement/explore/include/sockios/sockmgr.cc =================================================================== --- trunk/complement/explore/include/sockios/sockmgr.cc 2006-11-27 18:47:32 UTC (rev 1412) +++ trunk/complement/explore/include/sockios/sockmgr.cc 2006-11-27 18:49:17 UTC (rev 1413) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/10/11 15:30:02 ptr> +// -*- C++ -*- Time-stamp: <06/11/27 17:13:31 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 @@ -362,6 +362,8 @@ (*i)->s->close(); (*i)->_proc->close(); } + delete (*i)->_proc; + delete (*i)->s; } ::close( me->_cfd ); ::close( me->_pfd[1].fd ); @@ -386,6 +388,8 @@ (*i)->s->close(); (*i)->_proc->close(); } + delete (*i)->_proc; + delete (*i)->s; } ::close( me->_cfd ); ::close( me->_pfd[1].fd ); Modified: trunk/complement/explore/include/sockios/sockmgr.h =================================================================== --- trunk/complement/explore/include/sockios/sockmgr.h 2006-11-27 18:47:32 UTC (rev 1412) +++ trunk/complement/explore/include/sockios/sockmgr.h 2006-11-27 18:49:17 UTC (rev 1413) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/10/10 19:44:38 ptr> +// -*- C++ -*- Time-stamp: <06/11/27 17:13:22 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 @@ -189,7 +189,7 @@ } ~sockmgr_stream_MP() - { } + { loop_id.join(); } void open( const in_addr& addr, int port, sock_base::stype t = sock_base::sock_stream ); void open( unsigned long addr, int port, sock_base::stype t = sock_base::sock_stream ); Modified: trunk/complement/explore/lib/sockios/ChangeLog =================================================================== --- trunk/complement/explore/lib/sockios/ChangeLog 2006-11-27 18:47:32 UTC (rev 1412) +++ trunk/complement/explore/lib/sockios/ChangeLog 2006-11-27 18:49:17 UTC (rev 1413) @@ -1,3 +1,12 @@ +2006-11-27 Petr Ovtchenkov <pt...@is...> + + * sockmgr.h, sockmgr.cc: delete connect processors and + sockstreams at exit from loop; wait loop thread in sockmgr + dtor, it safe even after wait() call, but keep from bogus + confuse. + + * libsockios: Version 1.10.0 + 2006-10-11 Petr Ovtchenkov <pt...@is...> * sockmgr.cc: fix inconsistency with observer_run Modified: trunk/complement/explore/lib/sockios/Makefile.inc =================================================================== --- trunk/complement/explore/lib/sockios/Makefile.inc 2006-11-27 18:47:32 UTC (rev 1412) +++ trunk/complement/explore/lib/sockios/Makefile.inc 2006-11-27 18:49:17 UTC (rev 1413) @@ -1,8 +1,8 @@ -# -*- Makefile -*- Time-stamp: <06/09/21 22:08:04 ptr> +# -*- Makefile -*- Time-stamp: <06/11/27 17:19:45 ptr> LIBNAME = sockios MAJOR = 1 -MINOR = 9 +MINOR = 10 PATCH = 0 SRC_CC = _sockstream.cc _sockmgr.cc SRC_C = freebsd/getaddrinfo.c \ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2006-11-27 18:47:36
|
Revision: 1412 http://svn.sourceforge.net/complement/?rev=1412&view=rev Author: complement Date: 2006-11-27 10:47:32 -0800 (Mon, 27 Nov 2006) Log Message: ----------- fix typo in comparison Modified Paths: -------------- trunk/complement/explore/include/mt/uid.h Modified: trunk/complement/explore/include/mt/uid.h =================================================================== --- trunk/complement/explore/include/mt/uid.h 2006-11-27 08:15:46 UTC (rev 1411) +++ trunk/complement/explore/include/mt/uid.h 2006-11-27 18:47:32 UTC (rev 1412) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/24 20:50:19 ptr> +// -*- C++ -*- Time-stamp: <06/11/27 18:07:44 ptr> /* * Copyright (c) 2006 @@ -58,7 +58,7 @@ bool operator <( const uuid_type& uid ) const { // return std::lexicographical_compare( u.i, u.i + 4, uid.u.i, uid.u.i + 4 ); - return u.l < uid.u.l ? true : u.l > uid.u.l ? false : (u.l[1] < uid.u.l[1]); + return u.l[0] < uid.u.l[0] ? true : u.l[0] > uid.u.l[0] ? false : (u.l[1] < uid.u.l[1]); } }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2006-11-27 08:15:47
|
Revision: 1411 http://svn.sourceforge.net/complement/?rev=1411&view=rev Author: complement Date: 2006-11-27 00:15:46 -0800 (Mon, 27 Nov 2006) Log Message: ----------- change pass addresses when go through some transport; looks like work now Modified Paths: -------------- trunk/complement/explore/test/libstem/unit/unit_test.cc Modified: trunk/complement/explore/test/libstem/unit/unit_test.cc =================================================================== --- trunk/complement/explore/test/libstem/unit/unit_test.cc 2006-11-27 08:15:11 UTC (rev 1410) +++ trunk/complement/explore/test/libstem/unit/unit_test.cc 2006-11-27 08:15:46 UTC (rev 1411) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/27 11:08:36 ptr> +// -*- C++ -*- Time-stamp: <06/11/27 11:15:16 ptr> /* * Copyright (c) 2002, 2003, 2006 @@ -590,7 +590,7 @@ add( echo_tc ); add( echo_net_tc ); - add( peer_tc ); + // add( peer_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. |
From: <com...@us...> - 2006-11-27 08:15:13
|
Revision: 1410 http://svn.sourceforge.net/complement/?rev=1410&view=rev Author: complement Date: 2006-11-27 00:15:11 -0800 (Mon, 27 Nov 2006) Log Message: ----------- change pass addresses when go through some transport; looks like work now Modified Paths: -------------- trunk/complement/explore/include/stem/EDSEv.h trunk/complement/explore/include/stem/EvManager.h trunk/complement/explore/include/stem/Event.h trunk/complement/explore/lib/stem/EvManager.cc trunk/complement/explore/lib/stem/Names.cc trunk/complement/explore/lib/stem/NetTransport.cc trunk/complement/explore/lib/stem/_EventHandler.cc trunk/complement/explore/test/libstem/unit/unit_test.cc Modified: trunk/complement/explore/include/stem/EDSEv.h =================================================================== --- trunk/complement/explore/include/stem/EDSEv.h 2006-11-27 08:03:33 UTC (rev 1409) +++ trunk/complement/explore/include/stem/EDSEv.h 2006-11-27 08:15:11 UTC (rev 1410) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/24 17:39:23 ptr> +// -*- C++ -*- Time-stamp: <06/11/26 14:15:19 ptr> /* * Copyright (c) 1995-1999, 2002, 2003, 2005, 2006 @@ -16,14 +16,17 @@ namespace stem { -#define EV_EDS_CONNECT 0x06 -#define EV_EDS_DISCONNECT 0x07 -#define EV_EDS_ANNOUNCE 0x08 -#define EV_EDS_RQ_SESSION 0x09 -#define EV_EDS_RRQ_SESSION 0x10 -#define EV_EDS_RS_SESSION 0x11 -#define EV_EDS_CL_SESSION 0x12 +#define EV_STEM_TRANSPORT 0x06 +#define EV_STEM_TRANSPORT_ACK 0x07 +// #define EV_EDS_CONNECT 0x06 +// #define EV_EDS_DISCONNECT 0x07 +// #define EV_EDS_ANNOUNCE 0x08 +// #define EV_EDS_RQ_SESSION 0x09 +// #define EV_EDS_RRQ_SESSION 0x10 +// #define EV_EDS_RS_SESSION 0x11 +// #define EV_EDS_CL_SESSION 0x12 + // Name Service #define EV_STEM_GET_NS_LIST 0x13 #define EV_STEM_GET_NS_NAME 0x14 Modified: trunk/complement/explore/include/stem/EvManager.h =================================================================== --- trunk/complement/explore/include/stem/EvManager.h 2006-11-27 08:03:33 UTC (rev 1409) +++ trunk/complement/explore/include/stem/EvManager.h 2006-11-27 08:15:11 UTC (rev 1410) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/24 17:11:52 ptr> +// -*- C++ -*- Time-stamp: <06/11/26 21:10:31 ptr> /* * Copyright (c) 1995-1999, 2002, 2003, 2005, 2006 @@ -107,6 +107,7 @@ const char *info = 0 ); __FIT_DECLSPEC bool Unsubscribe( addr_type id ); __FIT_DECLSPEC addr_type reflect( const gaddr_type& addr ) const; + __FIT_DECLSPEC gaddr_type reflect( addr_type addr ) const; bool is_avail( addr_type id ) const { Modified: trunk/complement/explore/include/stem/Event.h =================================================================== --- trunk/complement/explore/include/stem/Event.h 2006-11-27 08:03:33 UTC (rev 1409) +++ trunk/complement/explore/include/stem/Event.h 2006-11-27 08:15:11 UTC (rev 1410) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/24 20:57:55 ptr> +// -*- C++ -*- Time-stamp: <06/11/26 14:32:35 ptr> /* * @@ -78,24 +78,13 @@ typedef uint32_t addr_type; typedef uint32_t code_type; -typedef uint32_t key_type; -#ifndef WIN32 extern const addr_type badaddr; extern const addr_type extbit; +extern const addr_type default_addr; extern const addr_type ns_addr; -extern const key_type badkey; extern const code_type badcode; -#endif -#ifdef WIN32 -extern __PG_DECLSPEC addr_type badaddr; -extern __PG_DECLSPEC addr_type extbit; -extern __PG_DECLSPEC addr_type ns_addr; -extern __PG_DECLSPEC key_type badkey; -extern __PG_DECLSPEC code_type badcode; -#endif - #ifdef STLPORT using std::__true_type; using std::__false_type; @@ -175,9 +164,9 @@ code_type code() const { return _code; } - key_type dest() const + addr_type dest() const { return _dst; } - key_type src() const + addr_type src() const { return _src; } bool is_from_foreign() const { return ((_src & extbit) != 0) && (_src != badaddr); } Modified: trunk/complement/explore/lib/stem/EvManager.cc =================================================================== --- trunk/complement/explore/lib/stem/EvManager.cc 2006-11-27 08:03:33 UTC (rev 1409) +++ trunk/complement/explore/lib/stem/EvManager.cc 2006-11-27 08:15:11 UTC (rev 1410) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/24 20:11:46 ptr> +// -*- C++ -*- Time-stamp: <06/11/26 21:21:55 ptr> /* * @@ -27,27 +27,17 @@ using namespace std; using namespace xmt; -#ifndef WIN32 const addr_type badaddr = 0xffffffff; -const key_type badkey = 0xffffffff; const code_type badcode = static_cast<code_type>(-1); const addr_type extbit = 0x80000000; +const addr_type default_addr = 0x00000000; const addr_type ns_addr = 0x00000001; -#endif -#ifdef WIN32 -__PG_DECLSPEC addr_type badaddr = 0xffffffff; -__PG_DECLSPEC key_type badkey = 0xffffffff; -__PG_DECLSPEC code_type badcode = static_cast<code_type>(-1); -__PG_DECLSPEC addr_type extbit = 0x80000000; -__PG_DECLSPEC addr_type ns_addr = 0x00000001; -#endif +const addr_type beglocaddr = 0x00000100; +const addr_type endlocaddr = 0x3fffffff; +const addr_type begextaddr = extbit; +const addr_type endextaddr = 0xbfffffff; -const addr_type beglocaddr = 0x00000100; -const addr_type endlocaddr = 0x3fffffff; -const addr_type begextaddr = extbit; -const addr_type endextaddr = 0xbfffffff; - std::string EvManager::inv_key_str( "invalid key" ); __FIT_DECLSPEC EvManager::EvManager() : @@ -293,7 +283,8 @@ __FIT_DECLSPEC addr_type EvManager::reflect( const gaddr_type& addr ) const { - if ( addr.hid == xmt::hostid() && addr.pid == getpid() ) { // this host, this process + if ( addr.hid == xmt::hostid() && addr.pid == getpid() ) { + // this host, this process if ( (addr.addr & extbit) == 0 ) { // looks like local object Locker _x1( _lock_heap ); local_heap_type::const_iterator l = heap.find( addr.addr ); @@ -302,6 +293,22 @@ } } } +#if 0 + else if ( addr.hid == gaddr_type() && addr.pid == -1 ) { + // this host, special case: + // peer don't know host ids, used as access to 'standard' services and initial + // communication + if ( (addr.addr & extbit) == 0 && addr.addr <= _low ) { + Locker _x1( _lock_heap ); + local_heap_type::const_iterator l = heap.find( addr.addr ); + if ( l != heap.end() ) { + return addr.addr; // l->first + } + } + // disable external objects here; restrict to 'standard' services + return badaddr; + } +#endif Locker _x1( _lock_xheap ); uuid_ext_heap_type::const_iterator i = _ui_heap.find( addr ); @@ -312,6 +319,17 @@ } __FIT_DECLSPEC +gaddr_type EvManager::reflect( addr_type addr ) const +{ + Locker lk( _lock_xheap ); + ext_uuid_heap_type::const_iterator i = _ex_heap.find( addr ); + if ( i != _ex_heap.end() ) { + return i->second; + } + return gaddr_type(); +} + +__FIT_DECLSPEC void EvManager::Remove( void *channel ) { Locker _x1( _lock_xheap ); Modified: trunk/complement/explore/lib/stem/Names.cc =================================================================== --- trunk/complement/explore/lib/stem/Names.cc 2006-11-27 08:03:33 UTC (rev 1409) +++ trunk/complement/explore/lib/stem/Names.cc 2006-11-27 08:15:11 UTC (rev 1410) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/24 20:17:46 ptr> +// -*- C++ -*- Time-stamp: <06/11/26 12:22:27 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 @@ -16,14 +16,18 @@ #endif #include <config/feature.h> + +#include <unistd.h> + #include "stem/Names.h" #include "stem/EvManager.h" #include "stem/EDSEv.h" + #include <list> +#include <iostream> + #include <mt/xmt.h> -#include <iostream> - namespace stem { using namespace std; Modified: trunk/complement/explore/lib/stem/NetTransport.cc =================================================================== --- trunk/complement/explore/lib/stem/NetTransport.cc 2006-11-27 08:03:33 UTC (rev 1409) +++ trunk/complement/explore/lib/stem/NetTransport.cc 2006-11-27 08:15:11 UTC (rev 1410) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/24 21:44:47 ptr> +// -*- C++ -*- Time-stamp: <06/11/26 19:14:58 ptr> /* * @@ -111,13 +111,11 @@ uint32_t buf[bsz]; using namespace std; - // cerr << __FILE__ << ":" << __LINE__ << endl; MT_IO_REENTRANT( *net ) if ( !net->read( (char *)buf, sizeof(uint32_t) ).good() ) { return false; } - // cerr << __FILE__ << ":" << __LINE__ << endl; if ( buf[0] != EDS_MAGIC ) { cerr << "EDS Magic fail" << endl; @@ -212,16 +210,51 @@ NetTransport::NetTransport( std::sockstream& s ) : NetTransport_base( "stem::NetTransport" ) { + net = &s; + + try { + Event ev; + gaddr_type dst; + gaddr_type src; + + if ( pop( ev, dst, src ) ) { + if ( ev.code() == EV_STEM_TRANSPORT ) { + src.addr = ns_addr; + addr_type xsrc = manager()->reflect( src ); + if ( xsrc == badaddr ) { + manager()->SubscribeRemote( detail::transport( static_cast<NetTransport_base *>(this), detail::transport::socket_tcp, 10 ), src ); + } + src.addr = default_addr; + xsrc = manager()->reflect( src ); + if ( xsrc == badaddr ) { + manager()->SubscribeRemote( detail::transport( static_cast<NetTransport_base *>(this), detail::transport::socket_tcp, 10 ), src ); + } + Event ack( EV_STEM_TRANSPORT_ACK ); + push( ack, src, self_glid() ); + } else { + throw runtime_error( "net handshake error" ); + } + } else { + throw runtime_error( "net error or net handshake error" ); + } + } + catch ( runtime_error& err ) { + s.close(); + cerr << err.what() << endl; + } + catch ( ... ) { + s.close(); + } } __FIT_DECLSPEC void NetTransport::connect( sockstream& s ) { - Event ev; - gaddr_type dst; - gaddr_type src; + try { + Event ev; + gaddr_type dst; + gaddr_type src; - try { if ( pop( ev, dst, src ) ) { addr_type xdst = manager()->reflect( dst ); if ( xdst == badaddr ) { @@ -230,8 +263,7 @@ ev.dest( xdst ); addr_type xsrc = manager()->reflect( src ); if ( xsrc == badaddr ) { - detail::transport tr( static_cast<NetTransport_base *>(this), detail::transport::socket_tcp, 10 ); - ev.src( manager()->SubscribeRemote( tr, src ) ); + ev.src( manager()->SubscribeRemote( detail::transport( static_cast<NetTransport_base *>(this), detail::transport::socket_tcp, 10 ), src ) ); } else { ev.src( xsrc ); } @@ -271,28 +303,55 @@ addr_type NetTransportMgr::open( const char *hostname, int port, std::sock_base::stype stype ) { - // I should be sure, that not more then one _loop running from here! - // For this, I enforce close connection before I try open new, - // and wait thread with _loop before start new. - if ( net == 0 ) { - net = new sockstream( hostname, port, stype ); - } else if ( net->is_open() ) { - // net->close(); - close(); // I should wait termination of _loop, clear EDS address mapping, etc. - net->open( hostname, port, stype ); - } else { - join(); // This is safe: transparent if no _loop, and wait it if one exist - net->open( hostname, port, stype ); - } + try { + // I should be sure, that not more then one _loop running from here! + // For this, I enforce close connection before I try open new, + // and wait thread with _loop before start new. + if ( net == 0 ) { + net = new sockstream( hostname, port, stype ); + } else if ( net->is_open() ) { + // net->close(); + close(); // I should wait termination of _loop, clear EDS address mapping, etc. + net->open( hostname, port, stype ); + } else { + join(); // This is safe: transparent if no _loop, and wait it if one exist + net->open( hostname, port, stype ); + } - if ( net->good() ) { - // _net_ns = rar_map( ns_addr, __ns_at + hostname ); - // addr_type zero_object = rar_map( 0, __at + hostname ); - detail::transport tr( static_cast<NetTransport_base *>(this), detail::transport::socket_tcp, 10 ); - // addr_type zero_object = manager()->SubscribeRemote( tr, src ); - _thr.launch( _loop, this, 0, PTHREAD_STACK_MIN * 2 ); // start thread here - return 0; // zero_object; + if ( net->good() ) { + // _net_ns = rar_map( ns_addr, __ns_at + hostname ); + // addr_type zero_object = rar_map( 0, __at + hostname ); + + Event ev( EV_STEM_TRANSPORT ); + gaddr_type dst; + gaddr_type src; + addr_type xsrc = badaddr; + push( ev, gaddr_type(), self_glid() ); + if ( pop( ev, dst, src ) ) { + if ( ev.code() == EV_STEM_TRANSPORT_ACK ) { + src.addr = ns_addr; + xsrc = manager()->reflect( src ); + if ( xsrc == badaddr ) { + manager()->SubscribeRemote( detail::transport( static_cast<NetTransport_base *>(this), detail::transport::socket_tcp, 10 ), src ); + } + src.addr = default_addr; + xsrc = manager()->reflect( src ); + if ( xsrc == badaddr ) { + xsrc = manager()->SubscribeRemote( detail::transport( static_cast<NetTransport_base *>(this), detail::transport::socket_tcp, 10 ), src ); + } + } else { + throw runtime_error( "net handshake error" ); + } + } else { + throw runtime_error( "net error or net handshake error" ); + } + _thr.launch( _loop, this, 0, PTHREAD_STACK_MIN * 2 ); // start thread here + return xsrc; // zero_object; + } } + catch ( runtime_error& err ) { + cerr << err.what() << endl; + } return badaddr; } @@ -331,8 +390,7 @@ ev.dest( xdst ); addr_type xsrc = manager()->reflect( src ); if ( xsrc == badaddr ) { - detail::transport tr( static_cast<NetTransport_base *>(&me), detail::transport::socket_tcp, 10 ); - ev.src( manager()->SubscribeRemote( tr, src ) ); + ev.src( manager()->SubscribeRemote( detail::transport( static_cast<NetTransport_base *>(&me), detail::transport::socket_tcp, 10 ), src ) ); } else { ev.src( xsrc ); } Modified: trunk/complement/explore/lib/stem/_EventHandler.cc =================================================================== --- trunk/complement/explore/lib/stem/_EventHandler.cc 2006-11-27 08:03:33 UTC (rev 1409) +++ trunk/complement/explore/lib/stem/_EventHandler.cc 2006-11-27 08:15:11 UTC (rev 1410) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/24 20:59:03 ptr> +// -*- C++ -*- Time-stamp: <06/11/26 12:22:42 ptr> /* * Copyright (c) 1995-1999, 2002, 2003, 2005, 2006 @@ -21,13 +21,8 @@ #include "stem/Names.h" #include "mt/xmt.h" -#if defined(__TRACE) || defined(__WARN) +#include <unistd.h> -// DIAG_DEFINE_GROUP(EventHandler,0,4); -// DIAG_DEFINE_GROUP(EventDispatch,0,3); - -#endif // __TRACE || __WARN - namespace stem { char *Init_buf[32]; Modified: trunk/complement/explore/test/libstem/unit/unit_test.cc =================================================================== --- trunk/complement/explore/test/libstem/unit/unit_test.cc 2006-11-27 08:03:33 UTC (rev 1409) +++ trunk/complement/explore/test/libstem/unit/unit_test.cc 2006-11-27 08:15:11 UTC (rev 1410) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/24 21:05:01 ptr> +// -*- C++ -*- Time-stamp: <06/11/27 11:08:36 ptr> /* * Copyright (c) 2002, 2003, 2006 @@ -47,6 +47,7 @@ void ns(); void echo(); + void echo_net(); void peer(); static xmt::Thread::ret_code thr1( void * ); @@ -259,7 +260,7 @@ stem::addr_type zero = mgr.open( "localhost", 6995 ); BOOST_CHECK( zero != stem::badaddr ); - BOOST_CHECK( zero != 0 ); + BOOST_CHECK( zero == 0 ); // NetTransportMgr should detect local delivery EchoClient node; @@ -283,9 +284,171 @@ // cerr << "Fine\n"; } +void stem_test::echo_net() +{ + xmt::__Condition<true> fcnd; + fcnd.set( false ); + + try { + xmt::Thread::fork(); + + stem::NetTransportMgr mgr; + + fcnd.try_wait(); + + stem::addr_type zero = mgr.open( "localhost", 6995 ); + + BOOST_CHECK( zero != stem::badaddr ); + BOOST_CHECK( zero != 0 ); // NetTransportMgr should detect external delivery + + EchoClient node; + + stem::Event ev( NODE_EV_ECHO ); + + ev.dest( zero ); + ev.value() = node.mess; + + node.Send( ev ); + + node.wait(); + + mgr.close(); + + exit( 0 ); + } + catch ( xmt::fork_in_parent& ) { + + } + + try { + sockmgr_stream_MP<stem::NetTransport> srv( 6995 ); + + StEMecho echo( 0, "echo service"); // <= zero! + + fcnd.set( true ); + + // mgr.join(); + + srv.close(); + srv.wait(); + } + catch ( ... ) { + } + // cerr << "Fine\n"; +} + void stem_test::peer() { + xmt::__Condition<true> fcnd; + fcnd.set( false ); + + xmt::__Condition<true> pcnd; + pcnd.set( false ); + + xmt::__Condition<true> scnd; + scnd.set( false ); + + try { + xmt::Thread::fork(); + stem::NetTransportMgr mgr; + + PeerClient c1( "c1 local" ); // c1 client + Naming nm; + + cerr << "1\n"; + fcnd.try_wait(); + + stem::addr_type zero = mgr.open( "localhost", 6995 ); // take address of 'zero' (aka default) object via net transport from server + // It done like it should on client side + + BOOST_CHECK( zero != stem::badaddr ); + BOOST_CHECK( zero != 0 ); + BOOST_CHECK( zero & stem::extbit ); // "external" address + + stem::Event ev( NODE_EV_REGME ); + ev.dest( zero ); + + ev.value() = "c1@here"; + c1.Send( ev ); // 'register' c1 client on 'echo' server + + stem::gaddr_type ga( c1.manager()->reflect( zero ) ); + + BOOST_CHECK( ga.addr == 0 ); + BOOST_CHECK( ga.pid != -1 ); + + ga.addr = stem::ns_addr; // this will be global address of ns of the same process + // as zero + + BOOST_CHECK( c1.manager()->reflect( ga ) != stem::badaddr ); + + stem::Event evname( EV_STEM_GET_NS_NAME ); + evname.dest( c1.manager()->reflect( ga ) ); + evname.value() = "c2@here"; + + pcnd.try_wait(); + + nm.Send( evname ); + nm.wait(); + + Naming::nsrecords_type::const_iterator i = find_if( nm.lst.begin(), nm.lst.end(), compose1( bind2nd( equal_to<string>(), string( "c2@here" ) ), select2nd<pair<stem::gaddr_type,string> >() ) ); + + BOOST_CHECK( i != nm.lst.end() ); + BOOST_CHECK( i->second == "c2@here" ); + + // c1.manager()->reflect( i->first ); + + cerr << "1.1\n"; + + scnd.set( true ); + exit( 0 ); + } + catch ( xmt::fork_in_parent& ) { + + } #if 0 + try { + xmt::Thread::fork(); + stem::NetTransportMgr mgr; + + cerr << "2\n"; + + PeerClient c2( "c2 local" ); // c2 client + + fcnd.try_wait(); + stem::addr_type zero = mgr.open( "localhost", 6995 ); // take address of 'zero' (aka default) object via net transport from server + // It done like it should on client side + + BOOST_CHECK( zero != stem::badaddr ); + BOOST_CHECK( zero != 0 ); + BOOST_CHECK( zero & stem::extbit ); // "external" address + + stem::Event ev( NODE_EV_REGME ); + ev.dest( zero ); + + ev.value() = "c2@here"; + c2.Send( ev ); // 'register' c2 client on 'echo' server + + cerr << "2.1\n"; + + pcnd.set( true ); + exit( 0 ); + } + catch ( xmt::fork_in_parent& ) { + + } +#endif + sockmgr_stream_MP<stem::NetTransport> srv( 6995 ); // server, it serve 'echo' + StEMecho echo( 0, "echo service"); // <= zero! 'echo' server, default ('zero' address) + cerr << "3\n"; + + fcnd.set( true ); + + scnd.try_wait(); + + srv.close(); + srv.wait(); + +#if 0 /* * Scheme: * / NetTransport / c1 @@ -404,6 +567,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 *echo_tc = BOOST_CLASS_TEST_CASE( &stem_test::echo, instance ); + test_case *echo_net_tc = BOOST_CLASS_TEST_CASE( &stem_test::echo_net, instance ); test_case *peer_tc = BOOST_CLASS_TEST_CASE( &stem_test::peer, instance ); basic2_tc->depends_on( basic1_tc ); @@ -414,6 +578,7 @@ ns_tc->depends_on( basic1_tc ); echo_tc->depends_on( basic2_tc ); + echo_net_tc->depends_on( echo_tc ); peer_tc->depends_on( echo_tc ); add( basic1_tc ); @@ -424,6 +589,7 @@ add( ns_tc ); add( echo_tc ); + add( echo_net_tc ); add( peer_tc ); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2006-11-27 08:03:42
|
Revision: 1409 http://svn.sourceforge.net/complement/?rev=1409&view=rev Author: complement Date: 2006-11-27 00:03:33 -0800 (Mon, 27 Nov 2006) Log Message: ----------- pass attributes to condition; fix condition's underlined mutex scope Modified Paths: -------------- trunk/complement/explore/include/mt/xmt.h Modified: trunk/complement/explore/include/mt/xmt.h =================================================================== --- trunk/complement/explore/include/mt/xmt.h 2006-11-24 18:53:01 UTC (rev 1408) +++ trunk/complement/explore/include/mt/xmt.h 2006-11-27 08:03:33 UTC (rev 1409) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/10/24 09:24:01 ptr> +// -*- C++ -*- Time-stamp: <06/11/27 10:30:33 ptr> /* * Copyright (c) 1997-1999, 2002-2006 @@ -1047,7 +1047,7 @@ pthread_condattr_t attr; pthread_condattr_init( &attr ); pthread_condattr_setpshared( &attr, PTHREAD_PROCESS_SHARED ); - pthread_cond_init( &_cond, 0 ); + pthread_cond_init( &_cond, &attr ); pthread_condattr_destroy( &attr ); } else { pthread_cond_init( &_cond, 0 ); @@ -1177,7 +1177,7 @@ return 0; #endif #if defined(_PTHREADS) || defined(__FIT_UITHREADS) - MT_REENTRANT( _lock, _x1 ); + __Locker<__Mutex<false,SCOPE> > lk( _lock ); _val = false; int ret; while ( !_val ) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2006-11-24 18:56:32
|
Revision: 1408 http://svn.sourceforge.net/complement/?rev=1408&view=rev Author: complement Date: 2006-11-24 10:53:01 -0800 (Fri, 24 Nov 2006) Log Message: ----------- local delivery work fine; local nameservice work too; polish global id usage Modified Paths: -------------- trunk/complement/explore/include/stem/Event.h trunk/complement/explore/include/stem/EventHandler.h trunk/complement/explore/lib/stem/ChangeLog trunk/complement/explore/lib/stem/EvManager.cc trunk/complement/explore/lib/stem/Names.cc trunk/complement/explore/lib/stem/NetTransport.cc trunk/complement/explore/lib/stem/_EventHandler.cc trunk/complement/explore/test/libstem/unit/NameService.cc trunk/complement/explore/test/libstem/unit/NameService.h trunk/complement/explore/test/libstem/unit/unit_test.cc Modified: trunk/complement/explore/include/stem/Event.h =================================================================== --- trunk/complement/explore/include/stem/Event.h 2006-11-24 18:47:01 UTC (rev 1407) +++ trunk/complement/explore/include/stem/Event.h 2006-11-24 18:53:01 UTC (rev 1408) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/24 14:50:06 ptr> +// -*- C++ -*- Time-stamp: <06/11/24 20:57:55 ptr> /* * @@ -109,6 +109,24 @@ struct gaddr_type : public __pack_base { + gaddr_type() : + hid(), + pid( -1 ), + addr( badaddr ) + { } + + gaddr_type( const xmt::uuid_type& _hid, pid_t _pid, stem::addr_type _addr ) : + hid( _hid ), + pid( _pid ), + addr( _addr ) + { } + + gaddr_type( const gaddr_type& g ) : + hid( g.hid ), + pid( g.pid ), + addr( g.addr ) + { } + xmt::uuid_type hid; int64_t pid; // pid_t defined as int, so it may be int64_t stem::addr_type addr; @@ -118,6 +136,9 @@ __FIT_DECLSPEC virtual void net_pack( std::ostream& ) const; __FIT_DECLSPEC virtual void net_unpack( std::istream& ); + gaddr_type& operator =( const gaddr_type& g ) + { hid = g.hid; pid = g.pid; addr = g.addr; return *this; } + bool operator ==( const gaddr_type& ga ) const { return hid == ga.hid && pid == ga.pid && addr == ga.addr; } bool operator !=( const gaddr_type& ga ) const Modified: trunk/complement/explore/include/stem/EventHandler.h =================================================================== --- trunk/complement/explore/include/stem/EventHandler.h 2006-11-24 18:47:01 UTC (rev 1407) +++ trunk/complement/explore/include/stem/EventHandler.h 2006-11-24 18:53:01 UTC (rev 1408) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/10/12 14:12:15 ptr> +// -*- C++ -*- Time-stamp: <06/11/24 20:32:06 ptr> /* * Copyright (c) 1995-1999, 2002, 2003, 2005, 2006 @@ -636,6 +636,8 @@ addr_type self_id() const { return _id; } + __FIT_DECLSPEC gaddr_type self_glid() const; + void State( state_type state ) { PushState( state ); } __FIT_DECLSPEC void PushState( state_type state ); Modified: trunk/complement/explore/lib/stem/ChangeLog =================================================================== --- trunk/complement/explore/lib/stem/ChangeLog 2006-11-24 18:47:01 UTC (rev 1407) +++ trunk/complement/explore/lib/stem/ChangeLog 2006-11-24 18:53:01 UTC (rev 1408) @@ -9,9 +9,13 @@ addresses and message routing logic. * Names.cc, Names.h, EDSEv.h: return gloabal addresses - list; remove obsolete requests/responses; + list, addresses not associated with communication channel; + remove obsolete NS requests/responses; + + * _EventHandler.cc, EventHandler.h: object can return + own global id. - * Makefile.inc: _EvSession.cc, _SessionMgr.cc removed + * Makefile.inc: _EvSession.cc and _SessionMgr.cc removed from compilation; library version 4.2.0 2006-10-12 Petr Ovtchenkov <pt...@is...> Modified: trunk/complement/explore/lib/stem/EvManager.cc =================================================================== --- trunk/complement/explore/lib/stem/EvManager.cc 2006-11-24 18:47:01 UTC (rev 1407) +++ trunk/complement/explore/lib/stem/EvManager.cc 2006-11-24 18:53:01 UTC (rev 1408) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/24 17:17:05 ptr> +// -*- C++ -*- Time-stamp: <06/11/24 20:11:46 ptr> /* * @@ -112,15 +112,22 @@ { addr_type id; { - Locker _x1( _lock_heap ); + Locker lk( _lock_heap ); id = create_unique(); heap[id] = object; } { - Locker _x1( _lock_iheap ); - iheap[id] = info; + Locker lk( _lock_xheap ); + gaddr_type& gaddr = _ex_heap[id]; + gaddr.hid = xmt::hostid(); + gaddr.pid = getpid(); + gaddr.addr = id; + _ui_heap[gaddr] = id; } + Locker lk( _lock_iheap ); + iheap[id] = info; + return id; } @@ -133,6 +140,14 @@ id = create_unique(); heap[id] = object; } + { + Locker lk( _lock_xheap ); + gaddr_type& gaddr = _ex_heap[id]; + gaddr.hid = xmt::hostid(); + gaddr.pid = getpid(); + gaddr.addr = id; + _ui_heap[gaddr] = id; + } if ( info ) { Locker _x1( _lock_iheap ); iheap[id] = info; @@ -154,6 +169,14 @@ } heap[id] = object; } + { + Locker lk( _lock_xheap ); + gaddr_type& gaddr = _ex_heap[id]; + gaddr.hid = xmt::hostid(); + gaddr.pid = getpid(); + gaddr.addr = id; + _ui_heap[gaddr] = id; + } Locker _x1( _lock_iheap ); iheap[id] = info; @@ -174,6 +197,14 @@ } heap[id] = object; } + { + Locker lk( _lock_xheap ); + gaddr_type& gaddr = _ex_heap[id]; + gaddr.hid = xmt::hostid(); + gaddr.pid = getpid(); + gaddr.addr = id; + _ui_heap[gaddr] = id; + } if ( info ) { Locker _x1( _lock_iheap ); iheap[id] = info; Modified: trunk/complement/explore/lib/stem/Names.cc =================================================================== --- trunk/complement/explore/lib/stem/Names.cc 2006-11-24 18:47:01 UTC (rev 1407) +++ trunk/complement/explore/lib/stem/Names.cc 2006-11-24 18:53:01 UTC (rev 1408) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/24 18:19:55 ptr> +// -*- C++ -*- Time-stamp: <06/11/24 20:17:46 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 @@ -22,6 +22,8 @@ #include <list> #include <mt/xmt.h> +#include <iostream> + namespace stem { using namespace std; Modified: trunk/complement/explore/lib/stem/NetTransport.cc =================================================================== --- trunk/complement/explore/lib/stem/NetTransport.cc 2006-11-24 18:47:01 UTC (rev 1407) +++ trunk/complement/explore/lib/stem/NetTransport.cc 2006-11-24 18:53:01 UTC (rev 1408) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/24 17:09:01 ptr> +// -*- C++ -*- Time-stamp: <06/11/24 21:44:47 ptr> /* * @@ -288,6 +288,8 @@ if ( net->good() ) { // _net_ns = rar_map( ns_addr, __ns_at + hostname ); // addr_type zero_object = rar_map( 0, __at + hostname ); + detail::transport tr( static_cast<NetTransport_base *>(this), detail::transport::socket_tcp, 10 ); + // addr_type zero_object = manager()->SubscribeRemote( tr, src ); _thr.launch( _loop, this, 0, PTHREAD_STACK_MIN * 2 ); // start thread here return 0; // zero_object; } Modified: trunk/complement/explore/lib/stem/_EventHandler.cc =================================================================== --- trunk/complement/explore/lib/stem/_EventHandler.cc 2006-11-24 18:47:01 UTC (rev 1407) +++ trunk/complement/explore/lib/stem/_EventHandler.cc 2006-11-24 18:53:01 UTC (rev 1408) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/10/12 14:09:20 ptr> +// -*- C++ -*- Time-stamp: <06/11/24 20:59:03 ptr> /* * Copyright (c) 1995-1999, 2002, 2003, 2005, 2006 @@ -41,7 +41,7 @@ EventHandler::Init::Init() { MT_REENTRANT_RS( _init_lock, _x ); - if ( _count++ == 0 ) { + if ( _count++ == 0 ) { EventHandler::_mgr = new EvManager(); stem::_ns = new Names( ns_addr, _ns_name ); } @@ -236,4 +236,10 @@ out << endl; } +__FIT_DECLSPEC +gaddr_type EventHandler::self_glid() const +{ + return gaddr_type(xmt::hostid(), getpid(), _id ); +} + } // namespace stem Modified: trunk/complement/explore/test/libstem/unit/NameService.cc =================================================================== --- trunk/complement/explore/test/libstem/unit/NameService.cc 2006-11-24 18:47:01 UTC (rev 1407) +++ trunk/complement/explore/test/libstem/unit/NameService.cc 2006-11-24 18:53:01 UTC (rev 1408) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/10/04 10:57:46 ptr> +// -*- C++ -*- Time-stamp: <06/11/24 20:14:45 ptr> /* * Copyright (c) 2006 @@ -40,40 +40,18 @@ // cnd.wait(); } -void Naming::names_list( const stem::NameRecord& nr ) +void Naming::names_list( const nsrecords_type& nr ) { // std::cerr << hex << nr.addr << " " << nr.record << dec << endl; + copy( nr.container.begin(), nr.container.end(), back_insert_iterator<nsrecords_type::container_type>(lst) ); - if ( nr.addr == stem::badaddr ) { // the last record - cnd.set(true); - } else { - lst.push_back( nr ); - } -} - -void Naming::names_name( const stem::NameRecord& nr ) -{ - // std::cerr << hex << nr.addr << dec << endl; - - if ( nr.addr == stem::badaddr ) { // the last record - cnd.set(true); - } else { - lst.push_back( nr ); - } -} - -void Naming::names_list1( const nsrecords_type& nr ) -{ - // std::cerr << hex << nr.addr << " " << nr.record << dec << endl; - copy( nr.container.begin(), nr.container.end(), back_insert_iterator<nsrecords_type::container_type>(lst1) ); - cnd.set(true); } -void Naming::names_name1( const nsrecords_type& nr ) +void Naming::names_name( const nsrecords_type& nr ) { // std::cerr << hex << nr.addr << dec << endl; - copy( nr.container.begin(), nr.container.end(), back_insert_iterator<nsrecords_type::container_type>(lst1) ); + copy( nr.container.begin(), nr.container.end(), back_insert_iterator<nsrecords_type::container_type>(lst) ); cnd.set(true); } @@ -84,8 +62,6 @@ } DEFINE_RESPONSE_TABLE( Naming ) - EV_T_(0,EV_EDS_NM_LIST,names_list,stem::NameRecord) - EV_T_(0,EV_EDS_NS_ADDR,names_name,stem::NameRecord) - EV_T_(0,EV_STEM_NS1_LIST,names_list1,nsrecords_type) - EV_T_(0,EV_STEM_NS1_NAME,names_name1,nsrecords_type) + EV_T_(0,EV_STEM_NS_LIST,names_list,nsrecords_type) + EV_T_(0,EV_STEM_NS_NAME,names_name,nsrecords_type) END_RESPONSE_TABLE Modified: trunk/complement/explore/test/libstem/unit/NameService.h =================================================================== --- trunk/complement/explore/test/libstem/unit/NameService.h 2006-11-24 18:47:01 UTC (rev 1407) +++ trunk/complement/explore/test/libstem/unit/NameService.h 2006-11-24 18:53:01 UTC (rev 1408) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/10/04 10:55:44 ptr> +// -*- C++ -*- Time-stamp: <06/11/24 19:33:11 ptr> /* * Copyright (c) 2006 @@ -24,20 +24,16 @@ Naming( stem::addr_type id ); ~Naming(); - void names_list( const stem::NameRecord& ); - void names_name( const stem::NameRecord& ); + typedef stem::NameRecords<stem::gaddr_type,std::string> nsrecords_type; - typedef stem::NameRecords<stem::addr_type,std::string> nsrecords_type; + void names_list( const nsrecords_type& ); + void names_name( const nsrecords_type& ); - void names_list1( const nsrecords_type& ); - void names_name1( const nsrecords_type& ); - void wait(); void reset() { cnd.set( false ); } - std::list<stem::NameRecord> lst; - nsrecords_type::container_type lst1; + nsrecords_type::container_type lst; private: xmt::Condition cnd; Modified: trunk/complement/explore/test/libstem/unit/unit_test.cc =================================================================== --- trunk/complement/explore/test/libstem/unit/unit_test.cc 2006-11-24 18:47:01 UTC (rev 1407) +++ trunk/complement/explore/test/libstem/unit/unit_test.cc 2006-11-24 18:53:01 UTC (rev 1408) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/10/12 15:15:13 ptr> +// -*- C++ -*- Time-stamp: <06/11/24 21:05:01 ptr> /* * Copyright (c) 2002, 2003, 2006 @@ -45,7 +45,6 @@ void basic2new(); void dl(); void ns(); - void ns1(); void echo(); void peer(); @@ -176,53 +175,63 @@ Node node( 2003, "Node" ); Naming nm; - stem::Event ev( EV_EDS_RQ_ADDR_LIST ); + stem::Event ev( EV_STEM_GET_NS_LIST ); ev.dest( stem::ns_addr ); nm.Send( ev ); nm.wait(); - list<stem::NameRecord>::const_iterator i = find( nm.lst.begin(), nm.lst.end(), string( "ns" ) ); + // this is sample of all inline find: + Naming::nsrecords_type::const_iterator i = find_if( nm.lst.begin(), nm.lst.end(), compose1( bind2nd( equal_to<string>(), string( "ns" ) ), select2nd<pair<stem::gaddr_type,string> >() ) ); BOOST_CHECK( i != nm.lst.end() ); - BOOST_CHECK( i->record == "ns" ); - BOOST_CHECK( i->addr == stem::ns_addr ); + BOOST_CHECK( i->second == "ns" ); + BOOST_CHECK( i->first.hid == xmt::hostid() ); + BOOST_CHECK( i->first.pid == getpid() ); + BOOST_CHECK( i->first.addr == stem::ns_addr ); - i = find( nm.lst.begin(), nm.lst.end(), string( "Node" ) ); + // well, but for few seaches declare and reuse functors: + equal_to<string> eq; + equal_to<stem::gaddr_type> eqa; + select1st<pair<stem::gaddr_type,string> > first; + select2nd<pair<stem::gaddr_type,string> > second; + + i = find_if( nm.lst.begin(), nm.lst.end(), compose1( bind2nd( eq, string( "Node" ) ), second ) ); + BOOST_CHECK( i != nm.lst.end() ); - BOOST_CHECK( i->record == "Node" ); - BOOST_CHECK( i->addr == 2003 ); + BOOST_CHECK( i->second == "Node" ); + BOOST_CHECK( i->first.addr == 2003 ); - i = find( nm.lst.begin(), nm.lst.end(), nm.self_id() ); + i = find_if( nm.lst.begin(), nm.lst.end(), compose1( bind2nd( eqa, nm.self_glid() ), first ) ); BOOST_CHECK( i != nm.lst.end() ); - BOOST_CHECK( i->addr == nm.self_id() ); - BOOST_CHECK( i->record.length() == 0 ); + BOOST_CHECK( i->first == nm.self_glid() ); + BOOST_CHECK( i->second.length() == 0 ); nm.lst.clear(); nm.reset(); BOOST_CHECK( nm.lst.empty() ); - stem::Event evname( EV_EDS_RQ_ADDR_BY_NAME ); + stem::Event evname( EV_STEM_GET_NS_NAME ); evname.dest( stem::ns_addr ); evname.value() = "Node"; nm.Send( evname ); nm.wait(); - i = find( nm.lst.begin(), nm.lst.end(), string( "ns" ) ); + i = find_if( nm.lst.begin(), nm.lst.end(), compose1( bind2nd( eq, string( "ns" ) ), second ) ); BOOST_CHECK( i == nm.lst.end() ); - i = find( nm.lst.begin(), nm.lst.end(), string( "Node" ) ); + i = find_if( nm.lst.begin(), nm.lst.end(), compose1( bind2nd( eq, string( "Node" ) ), second ) ); BOOST_CHECK( i != nm.lst.end() ); - BOOST_CHECK( i->record == "Node" ); - BOOST_CHECK( i->addr == 2003 ); + BOOST_CHECK( i->second == "Node" ); + BOOST_CHECK( i->first.addr == 2003 ); - i = find( nm.lst.begin(), nm.lst.end(), nm.self_id() ); + i = find_if( nm.lst.begin(), nm.lst.end(), compose1( bind2nd( eqa, nm.self_glid() ), first ) ); BOOST_CHECK( i == nm.lst.end() ); @@ -239,82 +248,6 @@ BOOST_CHECK( nm.lst.empty() ); } -void stem_test::ns1() -{ - Node node( 2003, "Node" ); - Naming nm; - - stem::Event ev( EV_STEM_RQ_ADDR_LIST1 ); - ev.dest( stem::ns_addr ); - nm.Send( ev ); - - nm.wait(); - - // this is sample of all inline find: - Naming::nsrecords_type::const_iterator i = find_if( nm.lst1.begin(), nm.lst1.end(), compose1( bind2nd( equal_to<string>(), string( "ns" ) ), select2nd<pair<stem::addr_type,string> >() ) ); - - BOOST_CHECK( i != nm.lst1.end() ); - BOOST_CHECK( i->second == "ns" ); - BOOST_CHECK( i->first == stem::ns_addr ); - - // well, but for few seaches declare and reuse functors: - equal_to<string> eq; - equal_to<stem::addr_type> eqa; - - select1st<pair<stem::addr_type,string> > first; - select2nd<pair<stem::addr_type,string> > second; - - i = find_if( nm.lst1.begin(), nm.lst1.end(), compose1( bind2nd( eq, string( "Node" ) ), second ) ); - - BOOST_CHECK( i != nm.lst1.end() ); - BOOST_CHECK( i->second == "Node" ); - BOOST_CHECK( i->first == 2003 ); - - i = find_if( nm.lst1.begin(), nm.lst1.end(), compose1( bind2nd( eqa, nm.self_id() ), first ) ); - - BOOST_CHECK( i != nm.lst1.end() ); - BOOST_CHECK( i->first == nm.self_id() ); - BOOST_CHECK( i->second.length() == 0 ); - - nm.lst1.clear(); - nm.reset(); - - BOOST_CHECK( nm.lst1.empty() ); - - stem::Event evname( EV_STEM_RQ_ADDR_BY_NAME1 ); - evname.dest( stem::ns_addr ); - evname.value() = "Node"; - nm.Send( evname ); - - nm.wait(); - - i = find_if( nm.lst1.begin(), nm.lst1.end(), compose1( bind2nd( eq, string( "ns" ) ), second ) ); - - BOOST_CHECK( i == nm.lst1.end() ); - - i = find_if( nm.lst1.begin(), nm.lst1.end(), compose1( bind2nd( eq, string( "Node" ) ), second ) ); - - BOOST_CHECK( i != nm.lst1.end() ); - BOOST_CHECK( i->second == "Node" ); - BOOST_CHECK( i->first == 2003 ); - - i = find_if( nm.lst1.begin(), nm.lst1.end(), compose1( bind2nd( eqa, nm.self_id() ), first ) ); - - BOOST_CHECK( i == nm.lst1.end() ); - - nm.lst1.clear(); - nm.reset(); - - BOOST_CHECK( nm.lst1.empty() ); - - evname.value() = "No-such-name"; - nm.Send( evname ); - - nm.wait(); - - BOOST_CHECK( nm.lst1.empty() ); -} - void stem_test::echo() { try { @@ -352,7 +285,7 @@ void stem_test::peer() { - +#if 0 /* * Scheme: * / NetTransport / c1 @@ -449,6 +382,7 @@ srv.close(); srv.wait(); +#endif } struct stem_test_suite : @@ -469,7 +403,6 @@ test_case *basic2n_tc = BOOST_CLASS_TEST_CASE( &stem_test::basic2new, instance ); 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 ); test_case *peer_tc = BOOST_CLASS_TEST_CASE( &stem_test::peer, instance ); @@ -479,7 +412,6 @@ basic2n_tc->depends_on( basic1n_tc ); dl_tc->depends_on( basic2n_tc ); ns_tc->depends_on( basic1_tc ); - ns1_tc->depends_on( basic1_tc ); echo_tc->depends_on( basic2_tc ); peer_tc->depends_on( echo_tc ); @@ -490,7 +422,6 @@ add( basic2n_tc ); add( dl_tc ); add( ns_tc ); - add( ns1_tc ); add( echo_tc ); add( peer_tc ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2006-11-24 18:56:30
|
Revision: 1407 http://svn.sourceforge.net/complement/?rev=1407&view=rev Author: complement Date: 2006-11-24 10:47:01 -0800 (Fri, 24 Nov 2006) Log Message: ----------- add copy constructor, assignment, etc. Modified Paths: -------------- trunk/complement/explore/include/mt/uid.h Modified: trunk/complement/explore/include/mt/uid.h =================================================================== --- trunk/complement/explore/include/mt/uid.h 2006-11-24 16:03:22 UTC (rev 1406) +++ trunk/complement/explore/include/mt/uid.h 2006-11-24 18:47:01 UTC (rev 1407) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/23 23:34:55 ptr> +// -*- C++ -*- Time-stamp: <06/11/24 20:50:19 ptr> /* * Copyright (c) 2006 @@ -23,23 +23,25 @@ struct uuid_type { - union { - uint8_t b[16]; - uint32_t i[4]; - uint64_t l[2]; - } u; + union { + uint8_t b[16]; + uint32_t i[4]; + uint64_t l[2]; + } u; - uuid_type() - {} + uuid_type() + { u.l[0] = 0; u.l[1] = 0; } - uuid_type( const uuid_type& uid ) - { - // u.i[0] = uid.u.i[0]; u.i[1] = uid.u.i[1]; - // u.i[2] = uid.u.i[2]; u.i[3] = uid.u.i[3]; - u.l[0] = uid.u.l[0]; u.l[1] = uid.u.l[1]; - } + uuid_type( const uuid_type& uid ) + { + // u.i[0] = uid.u.i[0]; u.i[1] = uid.u.i[1]; + // u.i[2] = uid.u.i[2]; u.i[3] = uid.u.i[3]; + u.l[0] = uid.u.l[0]; u.l[1] = uid.u.l[1]; + } + uuid_type& operator =( const uuid_type& uid ) + { u.l[0] = uid.u.l[0]; u.l[1] = uid.u.l[1]; return *this; } bool operator ==( const uuid_type& uid ) const { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2006-11-24 16:03:28
|
Revision: 1406 http://svn.sourceforge.net/complement/?rev=1406&view=rev Author: complement Date: 2006-11-24 08:03:22 -0800 (Fri, 24 Nov 2006) Log Message: ----------- rewritten scheme of mapping between internal and external addresses and message routing logic; just compile, not checked Modified Paths: -------------- trunk/complement/explore/include/stem/EDSEv.h trunk/complement/explore/include/stem/EvManager.h trunk/complement/explore/include/stem/Event.h trunk/complement/explore/include/stem/Names.h trunk/complement/explore/include/stem/NetTransport.h trunk/complement/explore/lib/stem/ChangeLog trunk/complement/explore/lib/stem/EvManager.cc trunk/complement/explore/lib/stem/EvPack.cc trunk/complement/explore/lib/stem/Names.cc trunk/complement/explore/lib/stem/NetTransport.cc Modified: trunk/complement/explore/include/stem/EDSEv.h =================================================================== --- trunk/complement/explore/include/stem/EDSEv.h 2006-11-24 10:21:44 UTC (rev 1405) +++ trunk/complement/explore/include/stem/EDSEv.h 2006-11-24 16:03:22 UTC (rev 1406) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/10/04 09:36:24 ptr> +// -*- C++ -*- Time-stamp: <06/11/24 17:39:23 ptr> /* * Copyright (c) 1995-1999, 2002, 2003, 2005, 2006 @@ -19,31 +19,23 @@ #define EV_EDS_CONNECT 0x06 #define EV_EDS_DISCONNECT 0x07 #define EV_EDS_ANNOUNCE 0x08 -#define EV_EDS_RQ_SESSION 0x10 -#define EV_EDS_RRQ_SESSION 0x11 -#define EV_EDS_RS_SESSION 0x12 -#define EV_EDS_CL_SESSION 0x13 +#define EV_EDS_RQ_SESSION 0x09 +#define EV_EDS_RRQ_SESSION 0x10 +#define EV_EDS_RS_SESSION 0x11 +#define EV_EDS_CL_SESSION 0x12 // Name Service -#define EV_EDS_NM_LIST 0x14 -#define EV_EDS_NS_ADDR 0x1c -#define EV_EDS_RQ_ADDR_LIST 0x15 -#define EV_EDS_RQ_EXT_ADDR_LIST 0x16 -#define EV_EDS_RQ_ADDR_BY_NAME 0x1b +#define EV_STEM_GET_NS_LIST 0x13 +#define EV_STEM_GET_NS_NAME 0x14 +#define EV_STEM_NS_LIST 0x15 +#define EV_STEM_NS_NAME 0x16 - -#define EV_STEM_NS1_LIST 0x1e -#define EV_STEM_NS1_NAME 0x1f -#define EV_STEM_RQ_ADDR_LIST1 0x20 -#define EV_STEM_RQ_EXT_ADDR_LIST1 0x21 -#define EV_STEM_RQ_ADDR_BY_NAME1 0x22 - // Cron Service #define EV_EDS_CRON_ADD 0x17 #define EV_EDS_CRON_REMOVE 0x18 -#define EV_EDS_CRON_REMOVE_ARG 0x1d -#define EV_EDS_CRON_START 0x19 -#define EV_EDS_CRON_STOP 0x1a +#define EV_EDS_CRON_REMOVE_ARG 0x19 +#define EV_EDS_CRON_START 0x1a +#define EV_EDS_CRON_STOP 0x1b } // namespace stem Modified: trunk/complement/explore/include/stem/EvManager.h =================================================================== --- trunk/complement/explore/include/stem/EvManager.h 2006-11-24 10:21:44 UTC (rev 1405) +++ trunk/complement/explore/include/stem/EvManager.h 2006-11-24 16:03:22 UTC (rev 1406) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/24 13:03:42 ptr> +// -*- C++ -*- Time-stamp: <06/11/24 17:11:52 ptr> /* * Copyright (c) 1995-1999, 2002, 2003, 2005, 2006 @@ -49,7 +49,7 @@ kind( unknown ) { } - transport( transport_entry *l, kind_type k, int m = 0 ) : + transport( transport_entry l, kind_type k, int m = 0 ) : link( l ), metric( m ), kind( k ) @@ -106,6 +106,7 @@ const gaddr_type& addr, const char *info = 0 ); __FIT_DECLSPEC bool Unsubscribe( addr_type id ); + __FIT_DECLSPEC addr_type reflect( const gaddr_type& addr ) const; bool is_avail( addr_type id ) const { Modified: trunk/complement/explore/include/stem/Event.h =================================================================== --- trunk/complement/explore/include/stem/Event.h 2006-11-24 10:21:44 UTC (rev 1405) +++ trunk/complement/explore/include/stem/Event.h 2006-11-24 16:03:22 UTC (rev 1406) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/24 13:07:19 ptr> +// -*- C++ -*- Time-stamp: <06/11/24 14:50:06 ptr> /* * @@ -123,6 +123,10 @@ bool operator !=( const gaddr_type& ga ) const { return hid != ga.hid || pid != ga.pid || addr != ga.addr; } __FIT_DECLSPEC bool operator <( const gaddr_type& ga ) const; + + + __FIT_DECLSPEC void _xnet_pack( char *buf ) const; + __FIT_DECLSPEC void _xnet_unpack( const char *buf ); }; class __Event_Base Modified: trunk/complement/explore/include/stem/Names.h =================================================================== --- trunk/complement/explore/include/stem/Names.h 2006-11-24 10:21:44 UTC (rev 1405) +++ trunk/complement/explore/include/stem/Names.h 2006-11-24 16:03:22 UTC (rev 1406) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/10/04 09:35:52 ptr> +// -*- C++ -*- Time-stamp: <06/11/24 18:23:55 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 @@ -41,9 +41,8 @@ explicit __FIT_DECLSPEC Names( addr_type id, const char *info = 0 ); __FIT_DECLSPEC ~Names(); - __FIT_DECLSPEC void get_list( const Event& ); - __FIT_DECLSPEC void get_ext_list( const Event& ); - __FIT_DECLSPEC void get_by_name( const Event& ); + __FIT_DECLSPEC void ns_list( const Event& ); + __FIT_DECLSPEC void ns_name( const Event& ); private: DECLARE_RESPONSE_TABLE( Names, EventHandler ); @@ -52,8 +51,7 @@ struct NameRecord : public __pack_base { - NameRecord() : - addr( badaddr ) + NameRecord() { } NameRecord( const NameRecord& nr ) : @@ -61,12 +59,12 @@ record( nr.record ) { } - NameRecord( addr_type a, const std::string& r ) : + NameRecord( const gaddr_type& a, const std::string& r ) : addr( a ), record( r ) { } - addr_type addr; + gaddr_type addr; std::string record; virtual __FIT_DECLSPEC void pack( std::ostream& s ) const; @@ -81,7 +79,7 @@ // bool operator == ( const std::string& s, const NameRecord& nr ) // { return nr.record == s; } -inline bool operator == ( const NameRecord& nr, addr_type a ) +inline bool operator == ( const NameRecord& nr, const gaddr_type& a ) { return nr.addr == a; } // bool operator == ( addr_type a, const NameRecord& nr ) @@ -118,7 +116,8 @@ { __pack( s, container.size() ); for ( const_iterator i = container.begin(); i != container.end(); ++i ) { - __pack( s, i->first ); + // __pack( s, i->first ); + i->first.pack( s ); __pack( s, i->second ); } } @@ -128,7 +127,8 @@ { __net_pack( s, static_cast<uint32_t>(container.size()) ); for ( const_iterator i = container.begin(); i != container.end(); ++i ) { - __net_pack( s, i->first ); + // __net_pack( s, i->first ); + i->first.net_pack( s ); __net_pack( s, i->second ); } } @@ -145,7 +145,8 @@ Info i; while ( sz-- > 0 ) { - __unpack( s, a ); + // __unpack( s, a ); + a.unpack( s ); __unpack( s, i ); container.push_back( std::make_pair(a, i) ); } @@ -163,7 +164,8 @@ Info i; while ( sz-- > 0 ) { - __net_unpack( s, a ); + // __net_unpack( s, a ); + a.net_unpack( s ); __net_unpack( s, i ); container.push_back( std::make_pair(a, i) ); } Modified: trunk/complement/explore/include/stem/NetTransport.h =================================================================== --- trunk/complement/explore/include/stem/NetTransport.h 2006-11-24 10:21:44 UTC (rev 1405) +++ trunk/complement/explore/include/stem/NetTransport.h 2006-11-24 16:03:22 UTC (rev 1406) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/24 13:07:32 ptr> +// -*- C++ -*- Time-stamp: <06/11/24 15:29:19 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 @@ -63,7 +63,7 @@ __FIT_DECLSPEC bool push( const Event&, const gaddr_type& dst, const gaddr_type& src ); protected: - bool pop( Event& ); + bool pop( Event&, gaddr_type& dst, gaddr_type& src ); std::sockstream *net; uint32_t _count; @@ -78,9 +78,6 @@ __FIT_DECLSPEC void connect( std::sockstream& ); - - private: - std::string _at_hostname; }; class NetTransportMgr : Modified: trunk/complement/explore/lib/stem/ChangeLog =================================================================== --- trunk/complement/explore/lib/stem/ChangeLog 2006-11-24 10:21:44 UTC (rev 1405) +++ trunk/complement/explore/lib/stem/ChangeLog 2006-11-24 16:03:22 UTC (rev 1406) @@ -1,3 +1,19 @@ +2006-11-24 Petr Ovtchenkov <pt...@is...> + + * Event.h, EvPack.h, EvPack.cc: introduce 'global + address'---unique object address as composition + of hostid, pid adn local address; + + * NetTransport.h, NetTransport.cc, EvManager.h, EvManager.cc: + rewritten scheme of mapping between internal and external + addresses and message routing logic. + + * Names.cc, Names.h, EDSEv.h: return gloabal addresses + list; remove obsolete requests/responses; + + * Makefile.inc: _EvSession.cc, _SessionMgr.cc removed + from compilation; library version 4.2.0 + 2006-10-12 Petr Ovtchenkov <pt...@is...> * NetTransport.h, NetTransport.cc: remove make_map, Modified: trunk/complement/explore/lib/stem/EvManager.cc =================================================================== --- trunk/complement/explore/lib/stem/EvManager.cc 2006-11-24 10:21:44 UTC (rev 1405) +++ trunk/complement/explore/lib/stem/EvManager.cc 2006-11-24 16:03:22 UTC (rev 1406) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/24 11:59:21 ptr> +// -*- C++ -*- Time-stamp: <06/11/24 17:17:05 ptr> /* * @@ -20,9 +20,13 @@ #include "stem/EvManager.h" #include "stem/NetTransport.h" #include <iomanip> +#include <mt/xmt.h> namespace stem { +using namespace std; +using namespace xmt; + #ifndef WIN32 const addr_type badaddr = 0xffffffff; const key_type badkey = 0xffffffff; @@ -202,7 +206,7 @@ __FIT_DECLSPEC addr_type EvManager::SubscribeRemote( const detail::transport& tr, - const gaddr_type addr, + const gaddr_type& addr, const char *info ) { addr_type id; @@ -231,7 +235,7 @@ pair<uuid_tr_heap_type::iterator,uuid_tr_heap_type::iterator> range = _tr_heap.equal_range( addr ); for ( uuid_tr_heap_type::iterator i = range.first; i != range.second; ++i ) { - pair<tr_uuid_heap_type::iterator,tr_uuid_heap_type::iterator> ch_range = _ch_heap.equal_range( i->link ); + pair<tr_uuid_heap_type::iterator,tr_uuid_heap_type::iterator> ch_range = _ch_heap.equal_range( i->second.link ); for ( tr_uuid_heap_type::iterator j = ch_range.first; j != ch_range.second; ) { if ( j->second == i->first ) { _ch_heap.erase( j++ ); @@ -256,6 +260,27 @@ } __FIT_DECLSPEC +addr_type EvManager::reflect( const gaddr_type& addr ) const +{ + if ( addr.hid == xmt::hostid() && addr.pid == getpid() ) { // this host, this process + if ( (addr.addr & extbit) == 0 ) { // looks like local object + Locker _x1( _lock_heap ); + local_heap_type::const_iterator l = heap.find( addr.addr ); + if ( l != heap.end() ) { + return addr.addr; // l->first + } + } + } + + Locker _x1( _lock_xheap ); + uuid_ext_heap_type::const_iterator i = _ui_heap.find( addr ); + if ( i == _ui_heap.end() ) { + return badaddr; + } + return i->second; +} + +__FIT_DECLSPEC void EvManager::Remove( void *channel ) { Locker _x1( _lock_xheap ); @@ -285,15 +310,15 @@ { Locker _x1( _lock_xheap ); if ( (id & extbit) != 0 ) { - ext_uuid_heap_type::iterator i = _ex_heap.find( id ); + ext_uuid_heap_type::const_iterator i = _ex_heap.find( id ); if ( i == _ex_heap.end() ) { throw range_error( string( "no such address" ) ); } - pair<uuid_tr_heap_type::iterator,uuid_tr_heap_type::iterator> range = _tr_heap.equal_range( i->second ); + pair<uuid_tr_heap_type::const_iterator,uuid_tr_heap_type::const_iterator> range = _tr_heap.equal_range( i->second ); if ( range.first == _tr_heap.end() ) { throw range_error( string( "no transport" ) ); } - return min_element( range.first, range.second, tr_compare ).second; + return min_element( range.first, range.second, tr_compare )->second; } throw range_error( string( "internal address" ) ); } @@ -318,11 +343,11 @@ if ( range.first == _tr_heap.end() ) { throw range_error( string( "no transport" ) ); } - detail::transport& tr = min_element( range.first, range.second, tr_compare ).second; + detail::transport& tr = min_element( range.first, range.second, tr_compare )->second; detail::transport::kind_type k = tr.kind; void *link = tr.link; - uuid_type gaddr_dst( i->second ); - uuid_type gaddr_src; + gaddr_type gaddr_dst( i->second ); + gaddr_type gaddr_src; ext_uuid_heap_type::iterator j = _ex_heap.find( e.src() ); if ( j == _ex_heap.end() ) { @@ -340,7 +365,7 @@ _lock_xheap.unlock(); switch ( k ) { - detail::transport::socket_tcp: + case detail::transport::socket_tcp: if ( reinterpret_cast<NetTransport_base *>(link)->push( e, gaddr_dst, gaddr_src) ) { // if I detect bad connection during writing to net // (in the push), I remove this connetion related entries. @@ -349,7 +374,7 @@ unsafe_Remove( link ); } break; - detail::transport::unknown: + case detail::transport::unknown: break; default: break; Modified: trunk/complement/explore/lib/stem/EvPack.cc =================================================================== --- trunk/complement/explore/lib/stem/EvPack.cc 2006-11-24 10:21:44 UTC (rev 1405) +++ trunk/complement/explore/lib/stem/EvPack.cc 2006-11-24 16:03:22 UTC (rev 1406) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/24 13:06:12 ptr> +// -*- C++ -*- Time-stamp: <06/11/24 17:19:05 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 @@ -12,7 +12,7 @@ */ #include <config/feature.h> -#include "stem/EvPack.h" +#include "stem/Event.h" #include <iterator> #include <iostream> #include <string> @@ -121,6 +121,26 @@ __net_unpack( s, addr ); } +__FIT_DECLSPEC void gaddr_type::_xnet_pack( char *buf ) const +{ + uint64_t _pid = to_net( pid ); + addr_type _addr = to_net( addr ); + + // copy( (char *)hid.u.b, (char *)hid.u.b + 16, buf ); + memcpy( (void *)buf, (const void *)hid.u.b, 16 ); + memcpy( (void *)(buf + 16), &_pid, sizeof(pid) ); + memcpy( (void *)(buf + 16 + sizeof(pid)), &_addr, sizeof(addr_type) ); +} + +__FIT_DECLSPEC void gaddr_type::_xnet_unpack( const char *buf ) +{ + memcpy( (void *)hid.u.b, (const void *)buf, 16 ); + memcpy( (void *)&pid, (const void *)(buf + 16), sizeof(pid) ); + memcpy( (void *)&addr, (const void *)(buf + 16 + sizeof(pid)), sizeof(addr_type) ); + pid = from_net( pid ); + addr = from_net( addr ); +} + __FIT_DECLSPEC bool gaddr_type::operator <( const gaddr_type& ga ) const { if ( hid < ga.hid ) { Modified: trunk/complement/explore/lib/stem/Names.cc =================================================================== --- trunk/complement/explore/lib/stem/Names.cc 2006-11-24 10:21:44 UTC (rev 1405) +++ trunk/complement/explore/lib/stem/Names.cc 2006-11-24 16:03:22 UTC (rev 1406) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/10/04 09:51:02 ptr> +// -*- C++ -*- Time-stamp: <06/11/24 18:19:55 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 @@ -20,10 +20,12 @@ #include "stem/EvManager.h" #include "stem/EDSEv.h" #include <list> +#include <mt/xmt.h> namespace stem { using namespace std; +using namespace xmt; __FIT_DECLSPEC Names::Names() : EventHandler() @@ -44,139 +46,93 @@ { } -void __FIT_DECLSPEC Names::get_list( const Event& rq ) +void __FIT_DECLSPEC Names::ns_list( const Event& rq ) { - typedef NameRecords<addr_type,string> Seq; - Event_base<Seq> rs( EV_STEM_NS1_LIST ); + typedef NameRecords<gaddr_type,string> Seq; + Event_base<Seq> rs( EV_STEM_NS_LIST ); Seq::container_type& lst = rs.value().container; - manager()->_lock_heap.lock(); - for ( EvManager::heap_type::iterator i = manager()->heap.begin(); i != manager()->heap.end(); ++i ) { - if ( ((*i).first & extbit) == 0 ) { // only local... - lst.push_back( make_pair((*i).first, (*i).second.info) ); + manager()->_lock_xheap.lock(); + manager()->_lock_iheap.lock(); + for ( EvManager::uuid_ext_heap_type::const_iterator i = manager()->_ui_heap.begin(); i != manager()->_ui_heap.end(); ++i ) { + EvManager::info_heap_type::const_iterator j = manager()->iheap.find( i->second ); + if ( j != manager()->iheap.end() ) { + lst.push_back( make_pair( i->first, j->second ) ); + } else { + lst.push_back( make_pair( i->first, string() ) ); } } - manager()->_lock_heap.unlock(); + manager()->_lock_iheap.unlock(); + manager()->_lock_xheap.unlock(); - if ( rq.code() == EV_STEM_RQ_ADDR_LIST1 ) { - rs.dest( rq.src() ); - Send( rs ); - } else { - Event_base<NameRecord> rs_( EV_EDS_NM_LIST ); - - rs_.dest( rq.src() ); - for ( Seq::const_iterator i = lst.begin(); i != lst.end(); ++i ) { - rs_.value().addr = i->first; - rs_.value().record = i->second; - Send( Event_convert<NameRecord>()( rs_ ) ); - } - // end of table - rs_.value().addr = badaddr; - rs_.value().record.clear(); - Send( Event_convert<NameRecord>()( rs_ ) ); - } + rs.dest( rq.src() ); + Send( rs ); } -void __FIT_DECLSPEC Names::get_ext_list( const Event& rq ) +void __FIT_DECLSPEC Names::ns_name( const Event& rq ) { - typedef NameRecords<addr_type,string> Seq; - Event_base<Seq> rs( EV_STEM_NS1_LIST ); + typedef NameRecords<gaddr_type,string> Seq; + Event_base<Seq> rs( EV_STEM_NS_NAME ); Seq::container_type& lst = rs.value().container; - manager()->_lock_heap.lock(); - for ( EvManager::heap_type::const_iterator i = manager()->heap.begin(); i != manager()->heap.end(); ++i ) { - if ( ((*i).first & extbit) != 0 ) { // only external... - lst.push_back( make_pair((*i).first, (*i).second.info) ); + manager()->_lock_iheap.lock(); + for ( EvManager::info_heap_type::const_iterator i = manager()->iheap.begin(); i != manager()->iheap.end(); ++i ) { + if ( i->second == rq.value() ) { + if ( /* i->first & extbit */ true ) { + Locker lk( manager()->_lock_xheap ); + EvManager::ext_uuid_heap_type::const_iterator j = manager()->_ex_heap.find( i->first ); + if ( j != manager()->_ex_heap.end() ) { + lst.push_back( make_pair( j->second, i->second ) ); + } + } else { + Locker lk( manager()->_lock_heap ); + EvManager::local_heap_type::const_iterator j = manager()->heap.find( i->first ); + if ( j != manager()->heap.end() ) { + gaddr_type gaddr; + gaddr.hid = xmt::hostid(); + gaddr.pid = getpid(); + gaddr.addr = j->first; + lst.push_back( make_pair( gaddr, i->second ) ); + } + } } } - manager()->_lock_heap.unlock(); + manager()->_lock_iheap.unlock(); - if ( rq.code() == EV_STEM_RQ_EXT_ADDR_LIST1 ) { - rs.dest( rq.src() ); - Send( rs ); - } else { - Event_base<NameRecord> rs_( EV_EDS_NM_LIST ); - - rs_.dest( rq.src() ); - for ( Seq::const_iterator i = lst.begin(); i != lst.end(); ++i ) { - rs_.value().addr = i->first; - rs_.value().record = i->second; - Send( Event_convert<NameRecord>()( rs_ ) ); - } - // end of table - rs_.value().addr = badaddr; - rs_.value().record.clear(); - Send( Event_convert<NameRecord>()( rs_ ) ); - } + rs.dest( rq.src() ); + Send( rs ); } -void __FIT_DECLSPEC Names::get_by_name( const Event& rq ) -{ - typedef NameRecords<addr_type,string> Seq; - Event_base<Seq> rs( EV_STEM_NS1_NAME ); - Seq::container_type& lst = rs.value().container; - - manager()->_lock_heap.lock(); - for ( EvManager::heap_type::const_iterator i = manager()->heap.begin(); i != manager()->heap.end(); ++i ) { - if ( ((*i).first & extbit) == 0 && (*i).second.info == rq.value() ) { // only local... - lst.push_back( make_pair((*i).first, (*i).second.info) ); - } - } - manager()->_lock_heap.unlock(); - - if ( rq.code() == EV_STEM_RQ_ADDR_BY_NAME1 ) { - rs.dest( rq.src() ); - Send( rs ); - } else { - Event_base<NameRecord> rs_( EV_EDS_NS_ADDR ); - - rs_.dest( rq.src() ); - for ( Seq::const_iterator i = lst.begin(); i != lst.end(); ++i ) { - rs_.value().addr = i->first; - rs_.value().record = i->second; - Send( Event_convert<NameRecord>()( rs_ ) ); - } - // end of table - rs_.value().addr = badaddr; - rs_.value().record.clear(); - Send( Event_convert<NameRecord>()( rs_ ) ); - } -} - DEFINE_RESPONSE_TABLE( Names ) - EV_EDS(ST_NULL,EV_EDS_RQ_ADDR_LIST,get_list) - EV_EDS(ST_NULL,EV_STEM_RQ_ADDR_LIST1,get_list) - EV_EDS(ST_NULL,EV_EDS_RQ_EXT_ADDR_LIST,get_ext_list) - EV_EDS(ST_NULL,EV_STEM_RQ_EXT_ADDR_LIST1,get_ext_list) - EV_EDS(ST_NULL,EV_EDS_RQ_ADDR_BY_NAME,get_by_name) - EV_EDS(ST_NULL,EV_STEM_RQ_ADDR_BY_NAME1,get_by_name) + EV_EDS(ST_NULL,EV_STEM_GET_NS_LIST,ns_list) + EV_EDS(ST_NULL,EV_STEM_GET_NS_NAME,ns_name) END_RESPONSE_TABLE __FIT_DECLSPEC void NameRecord::pack( std::ostream& s ) const { - __pack( s, addr ); + addr.pack( s ); __pack( s, record ); } __FIT_DECLSPEC void NameRecord::net_pack( std::ostream& s ) const { - __net_pack( s, addr ); + addr.net_pack( s ); __net_pack( s, record ); } __FIT_DECLSPEC void NameRecord::unpack( std::istream& s ) { - __unpack( s, addr ); + addr.unpack( s ); __unpack( s, record ); } __FIT_DECLSPEC void NameRecord::net_unpack( std::istream& s ) { - __net_unpack( s, addr ); + addr.net_unpack( s ); __net_unpack( s, record ); } Modified: trunk/complement/explore/lib/stem/NetTransport.cc =================================================================== --- trunk/complement/explore/lib/stem/NetTransport.cc 2006-11-24 10:21:44 UTC (rev 1405) +++ trunk/complement/explore/lib/stem/NetTransport.cc 2006-11-24 16:03:22 UTC (rev 1406) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/24 13:09:57 ptr> +// -*- C++ -*- Time-stamp: <06/11/24 17:09:01 ptr> /* * @@ -105,13 +105,12 @@ } } -bool NetTransport_base::pop( Event& _rs ) +bool NetTransport_base::pop( Event& _rs, gaddr_type& dst, gaddr_type& src ) { - uint32_t buf[8]; + const int bsz = 2+(4+2+1)*2+4; + uint32_t buf[bsz]; using namespace std; - // _STLP_ASSERT( net != 0 ); - // cerr << __FILE__ << ":" << __LINE__ << endl; MT_IO_REENTRANT( *net ) @@ -120,22 +119,21 @@ } // cerr << __FILE__ << ":" << __LINE__ << endl; - // if ( from_net( buf[0] ) != EDS_MAGIC ) { if ( buf[0] != EDS_MAGIC ) { cerr << "EDS Magic fail" << endl; NetTransport_base::close(); return false; } - if ( !net->read( (char *)&buf[1], sizeof(uint32_t) * 7 ).good() ) { + if ( !net->read( (char *)&buf[1], sizeof(uint32_t) * (bsz-1) ).good() ) { return false; } _rs.code( from_net( buf[1] ) ); - _rs.dest( from_net( buf[2] ) ); - _rs.src( from_net( buf[3] ) ); - uint32_t _x_count = from_net( buf[4] ); - uint32_t _x_time = from_net( buf[5] ); // time? - uint32_t sz = from_net( buf[6] ); + dst._xnet_unpack( (const char *)&buf[2] ); + src._xnet_unpack( (const char *)&buf[9] ); + uint32_t _x_count = from_net( buf[16] ); + uint32_t _x_time = from_net( buf[17] ); // time? + uint32_t sz = from_net( buf[18] ); if ( sz >= EDS_MSG_LIMIT ) { cerr << "EDS Message size too big: " << sz << endl; @@ -143,8 +141,8 @@ return false; } - adler32_type adler = adler32( (unsigned char *)buf, sizeof(uint32_t) * 7 ); - if ( adler != from_net( buf[7] ) ) { + adler32_type adler = adler32( (unsigned char *)buf, sizeof(uint32_t) * 19 ); + if ( adler != from_net( buf[19] ) ) { cerr << "EDS Adler-32 fail" << endl; NetTransport_base::close(); return false; @@ -152,18 +150,10 @@ string& str = _rs.value(); - str.erase(); // str.clear(); absent in VC's STL + str.erase(); str.reserve( sz ); -#if defined(_MSC_VER) && (_MSC_VER < 1200) - char ch; -#endif while ( sz-- > 0 ) { -#if defined(_MSC_VER) && (_MSC_VER < 1200) - net->get( ch ); - str += ch; -#else str += (char)net->get(); -#endif } return net->good(); @@ -173,29 +163,28 @@ __FIT_DECLSPEC bool NetTransport_base::push( const Event& _rs, const gaddr_type& dst, const gaddr_type& src ) { - // _STLP_ASSERT( net != 0 ); if ( !net->good() ) { return false; } - // const int bsz = 8-2+(4+2+1)*2; - // uint32_t buf[bsz]; + const int bsz = 2+(4+2+1)*2+4; + uint32_t buf[bsz]; - ostringstream sbuf; // 4 bytes - sbuf.write( (const char *)&EDS_MAGIC, sizeof(EDS_MAGIC) ); // 0 - __pack_base::__net_pack( sbuf, _rs.code() ); // 1 - dst.net_pack( sbuf ); // 2-8 - src.net_pack( sbuf ); // 9-15 + // ostringstream sbuf; // 4 bytes + buf[0] = EDS_MAGIC; + buf[1] = to_net( _rs.code() ); + dst._xnet_pack( reinterpret_cast<char *>(buf + 2) ); + src._xnet_pack( reinterpret_cast<char *>(buf + 9) ); // MT_IO_REENTRANT_W( *net ) MT_IO_LOCK_W( *net ) - __pack_base::__net_pack( sbuf, ++_count ); // 16 - __pack_base::__net_pack( sbuf, 0 ); // 17 time? - __pack_base::__net_pack( sbuf, static_cast<uint32_t>(_rs.value().size()) ); // 18 - __pack_base::__net_pack( sbuf, adler32( (unsigned char *)sbuf.str().c_str(), sizeof(uint32_t) * 19 ) ); // 19 crc + buf[16] = to_net( ++_count ); + buf[17] = 0; // time? + buf[18] = to_net( static_cast<uint32_t>(_rs.value().size()) ); + buf[19] = to_net( adler32( (unsigned char *)buf, sizeof(uint32_t) * 19 )); // crc try { - net->write( sbuf.str().c_str(), sizeof(uint32_t) * 20 ); + net->write( (const char *)buf, sizeof(uint32_t) * 20 ); copy( _rs.value().begin(), _rs.value().end(), ostream_iterator<char,char,char_traits<char> >(*net) ); @@ -207,7 +196,6 @@ } catch ( ios_base::failure& ) { if ( net != 0 ) { // clear connection: required by non-Solaris OS - rar.clear(); // for MP connection policy net->close(); } } @@ -230,10 +218,23 @@ void NetTransport::connect( sockstream& s ) { Event ev; + gaddr_type dst; + gaddr_type src; try { - if ( pop( ev ) ) { - ev.src( rar_map( ev.src(), _at_hostname ) ); // substitute my local id + if ( pop( ev, dst, src ) ) { + addr_type xdst = manager()->reflect( dst ); + if ( xdst == badaddr ) { + return; + } + ev.dest( xdst ); + addr_type xsrc = manager()->reflect( src ); + if ( xsrc == badaddr ) { + detail::transport tr( static_cast<NetTransport_base *>(this), detail::transport::socket_tcp, 10 ); + ev.src( manager()->SubscribeRemote( tr, src ) ); + } else { + ev.src( xsrc ); + } manager()->push( ev ); } } @@ -285,10 +286,10 @@ } if ( net->good() ) { - _net_ns = rar_map( ns_addr, __ns_at + hostname ); - addr_type zero_object = rar_map( 0, __at + hostname ); + // _net_ns = rar_map( ns_addr, __ns_at + hostname ); + // addr_type zero_object = rar_map( 0, __at + hostname ); _thr.launch( _loop, this, 0, PTHREAD_STACK_MIN * 2 ); // start thread here - return zero_object; + return 0; // zero_object; } return badaddr; } @@ -313,14 +314,26 @@ xmt::Thread::ret_code NetTransportMgr::_loop( void *p ) { NetTransportMgr& me = *reinterpret_cast<NetTransportMgr *>(p); - heap_type::iterator r; Event ev; xmt::Thread::ret_code rt; rt.iword = 0; + gaddr_type dst; + gaddr_type src; try { - while ( me.pop( ev ) ) { - ev.src( me.rar_map( ev.src(), __at + hostname( me.net->rdbuf()->inet_addr()) ) ); // substitute my local id + while ( me.pop( ev, dst, src ) ) { + addr_type xdst = manager()->reflect( dst ); + if ( xdst == badaddr ) { + continue; + } + ev.dest( xdst ); + addr_type xsrc = manager()->reflect( src ); + if ( xsrc == badaddr ) { + detail::transport tr( static_cast<NetTransport_base *>(&me), detail::transport::socket_tcp, 10 ); + ev.src( manager()->SubscribeRemote( tr, src ) ); + } else { + ev.src( xsrc ); + } manager()->push( ev ); } // cerr << __FILE__ << ":" << __LINE__ << endl; @@ -338,15 +351,25 @@ __FIT_DECLSPEC 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; - Event ev; // cerr << "Connected: " << _hostname << endl; + gaddr_type dst; + gaddr_type src; try { - if ( pop( ev ) ) { - ev.src( rar_map( ev.src(), __at + _hostname ) ); // substitute my local id + if ( pop( ev, dst, src ) ) { + addr_type xdst = manager()->reflect( dst ); + if ( xdst == badaddr ) { + return; + } + ev.dest( xdst ); + addr_type xsrc = manager()->reflect( src ); + if ( xsrc == badaddr ) { + detail::transport tr( static_cast<NetTransport_base *>(this), detail::transport::socket_tcp, 10 ); + ev.src( manager()->SubscribeRemote( tr, src ) ); + } else { + ev.src( xsrc ); + } manager()->push( ev ); } if ( !s.good() ) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2006-11-24 10:21:46
|
Revision: 1405 http://svn.sourceforge.net/complement/?rev=1405&view=rev Author: complement Date: 2006-11-24 02:21:44 -0800 (Fri, 24 Nov 2006) Log Message: ----------- general revision of external address consept; not work yet Modified Paths: -------------- trunk/complement/explore/include/stem/EvManager.h trunk/complement/explore/include/stem/EvPack.h trunk/complement/explore/include/stem/Event.h trunk/complement/explore/include/stem/NetTransport.h trunk/complement/explore/lib/stem/EvManager.cc trunk/complement/explore/lib/stem/EvPack.cc trunk/complement/explore/lib/stem/Makefile.inc trunk/complement/explore/lib/stem/NetTransport.cc Modified: trunk/complement/explore/include/stem/EvManager.h =================================================================== --- trunk/complement/explore/include/stem/EvManager.h 2006-11-24 10:15:25 UTC (rev 1404) +++ trunk/complement/explore/include/stem/EvManager.h 2006-11-24 10:21:44 UTC (rev 1405) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/10/12 15:10:18 ptr> +// -*- C++ -*- Time-stamp: <06/11/24 13:03:42 ptr> /* * Copyright (c) 1995-1999, 2002, 2003, 2005, 2006 @@ -18,85 +18,76 @@ #include <config/feature.h> #endif +#include <stdint.h> + #include <string> #include <map> #include <queue> -#ifndef __stem_Event_h +#include <mt/xmt.h> +#include <mt/uid.h> + #include <stem/Event.h> -#endif - -#ifndef __stem_EventHandler_h #include <stem/EventHandler.h> -#endif -#ifndef __stem_EvSession_h -#include <stem/EvSession.h> -#endif +namespace stem { -#ifndef __XMT_H -#include <mt/xmt.h> -#endif +namespace detail { -#ifndef __SOCKSTREAM__ -#include <sockios/sockstream> -#endif +typedef void * transport_entry; -namespace stem { +struct transport +{ + enum kind_type { + unknown = -1, + socket_tcp = 0 + }; -class NetTransport_base; -class NetTransport; -class NetTransportMgr; + transport() : + link( 0 ), + metric( 0 ), + kind( unknown ) + { } -struct __Remote_Object_Entry -{ - __Remote_Object_Entry() : - key( 0 ), - channel( 0 ) + transport( transport_entry *l, kind_type k, int m = 0 ) : + link( l ), + metric( m ), + kind( k ) { } - __Remote_Object_Entry( key_type __k, NetTransport_base *__c ) : - key( __k ), - channel( __c ) + transport( const transport& t ) : + link( t.link ), + metric( t.metric ), + kind( t.kind ) { } - key_type key; - NetTransport_base *channel; + transport_entry link; + int metric; + + kind_type kind; }; -struct __Object_Entry +inline bool operator <( const transport& l, const transport& r ) +{ return l.metric < r.metric; } + +} // namespace detail + +class EvManager { - __Object_Entry() : - ref( 0 ), - remote( 0 ) - { } + private: + typedef std::map<addr_type,EventHandler *> local_heap_type; + typedef std::map<addr_type,std::string> info_heap_type; - ~__Object_Entry() - { delete remote; } + typedef std::map<gaddr_type,addr_type> uuid_ext_heap_type; + typedef std::map<addr_type,gaddr_type> ext_uuid_heap_type; - void addremote( key_type key, NetTransport_base *channel ) - { remote = new __Remote_Object_Entry( key, channel ); } - - EventHandler *ref; // system dependent? for Win may be WND HANDLER? - std::string info; // even IDL interface... - __Remote_Object_Entry *remote; - // string location; // if ref invalid; - // int refcount; // references on object -}; + typedef std::multimap<gaddr_type,detail::transport> uuid_tr_heap_type; + typedef std::multimap<detail::transport_entry,gaddr_type> tr_uuid_heap_type; -#ifdef _MSC_VER -} // namespace stem -namespace std { -typedef stem::__Object_Entry __Object_Entry; -} // namespace std -namespace stem { -#endif + static bool tr_compare( const std::pair<gaddr_type,detail::transport>& l, const std::pair<gaddr_type,detail::transport>& r ) + { return l.second < r.second; } -class EvManager -{ public: -// typedef std::map<key_type,__Object_Entry,std::less<key_type>> heap_type; - typedef std::map<key_type,__Object_Entry> heap_type; typedef std::queue< Event > queue_type; __FIT_DECLSPEC EvManager(); @@ -105,15 +96,15 @@ __FIT_DECLSPEC addr_type Subscribe( EventHandler *object, const std::string& info ); __FIT_DECLSPEC addr_type Subscribe( EventHandler *object, const char *info = 0 ); __FIT_DECLSPEC addr_type SubscribeID( addr_type id, EventHandler *object, - const std::string& info ); + const std::string& info ); __FIT_DECLSPEC addr_type SubscribeID( addr_type id, EventHandler *object, - const char *info = 0 ); - __FIT_DECLSPEC addr_type SubscribeRemote( NetTransport_base *channel, - addr_type rmkey, - const std::string& info ); - __FIT_DECLSPEC addr_type SubscribeRemote( NetTransport_base *channel, - addr_type rmkey, - const char *info = 0 ); + const char *info = 0 ); + __FIT_DECLSPEC addr_type SubscribeRemote( const detail::transport& tr, + const gaddr_type& addr, + const std::string& info ); + __FIT_DECLSPEC addr_type SubscribeRemote( const detail::transport& tr, + const gaddr_type& addr, + const char *info = 0 ); __FIT_DECLSPEC bool Unsubscribe( addr_type id ); bool is_avail( addr_type id ) const @@ -124,29 +115,29 @@ const std::string who_is( addr_type id ) const { - MT_REENTRANT( _lock_heap, _x1 ); + MT_REENTRANT( _lock_iheap, _x1 ); return unsafe_who_is( id ); } const std::string annotate( addr_type id ) const { - MT_REENTRANT( _lock_heap, _x1 ); + MT_REENTRANT( _lock_iheap, _x1 ); return unsafe_annotate( id ); } void change_announce( addr_type id, const std::string& info ) { - MT_REENTRANT( _lock_heap, _x1 ); + MT_REENTRANT( _lock_iheap, _x1 ); unsafe_change_announce( id, info ); } void change_announce( addr_type id, const char *info ) { - MT_REENTRANT( _lock_heap, _x1 ); + MT_REENTRANT( _lock_iheap, _x1 ); unsafe_change_announce( id, info ); } - __FIT_DECLSPEC NetTransport_base *transport( addr_type object_id ) const; + __FIT_DECLSPEC const detail::transport& transport( addr_type object_id ) const; void push( const Event& e ) { @@ -155,42 +146,47 @@ _cnd_queue.set( true ); } - __FIT_DECLSPEC void Remove( NetTransport_base * ); + __FIT_DECLSPEC void Remove( void * ); protected: bool unsafe_is_avail( addr_type id ) const - { return heap.find( id ) != heap.end(); } + { + if ( id & extbit ) { + return _ex_heap.find( id ) != _ex_heap.end(); + } + return heap.find( id ) != heap.end(); + } const std::string& unsafe_who_is( addr_type id ) const { - heap_type::const_iterator i = heap.find( id ); - return i == heap.end() ? inv_key_str : (*i).second.info; + info_heap_type::const_iterator i = iheap.find( id ); + return i == iheap.end() ? inv_key_str : (*i).second; } const std::string& unsafe_annotate( addr_type id ) const { - heap_type::const_iterator i = heap.find( id ); - return i == heap.end() ? inv_key_str : (*i).second.info; + info_heap_type::const_iterator i = iheap.find( id ); + return i == iheap.end() ? inv_key_str : (*i).second; } void unsafe_change_announce( addr_type id, const std::string& info ) { - heap_type::iterator i = heap.find( id ); - if ( i != heap.end() ) { - i->second.info = info; + info_heap_type::iterator i = iheap.find( id ); + if ( i != iheap.end() ) { + i->second = info; } } void unsafe_change_announce( addr_type id, const char *info ) { - heap_type::iterator i = heap.find( id ); - if ( i != heap.end() ) { - i->second.info = info; + info_heap_type::iterator i = iheap.find( id ); + if ( i != iheap.end() ) { + i->second = info; } } private: void Send( const Event& e ); - __FIT_DECLSPEC void unsafe_Remove( NetTransport_base * ); + __FIT_DECLSPEC void unsafe_Remove( void * ); addr_type create_unique(); addr_type create_unique_x(); @@ -198,7 +194,15 @@ const addr_type _low; const addr_type _high; addr_type _id; - heap_type heap; + + local_heap_type heap; // address -> EventHandler * + info_heap_type iheap; // address -> info string (both local and external) + + uuid_ext_heap_type _ui_heap; // gloabal address -> address + ext_uuid_heap_type _ex_heap; // address -> global address + uuid_tr_heap_type _tr_heap; // global address -> transport + tr_uuid_heap_type _ch_heap; // transport channel -> global address + queue_type in_ev_queue; queue_type out_ev_queue; @@ -216,6 +220,9 @@ xmt::Spinlock _ev_queue_dispatch_guard; xmt::Mutex _lock_heap; + xmt::Mutex _lock_iheap; + xmt::Mutex _lock_xheap; + xmt::Mutex _lock_queue; xmt::Condition _cnd_queue; Modified: trunk/complement/explore/include/stem/EvPack.h =================================================================== --- trunk/complement/explore/include/stem/EvPack.h 2006-11-24 10:15:25 UTC (rev 1404) +++ trunk/complement/explore/include/stem/EvPack.h 2006-11-24 10:21:44 UTC (rev 1405) @@ -1,23 +1,15 @@ -// -*- C++ -*- Time-stamp: <05/12/29 23:57:13 ptr> +// -*- C++ -*- Time-stamp: <06/11/23 22:19:50 ptr> /* * - * Copyright (c) 1997-1999, 2002, 2003, 2005 + * Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 * Petr Ovtchenkov * * Copyright (c) 1999-2001 * ParallelGraphics Ltd. * - * Licensed under the Academic Free License version 2.1 + * Licensed under the Academic Free License version 3.0 * - * This material is provided "as is", with absolutely no warranty expressed - * or implied. Any use is at your own risk. - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. */ #ifndef __stem_EvPack_h @@ -222,6 +214,7 @@ // basic types +#if 0 // string static __FIT_DECLSPEC void __net_unpack( std::istream& s, std::string& str ); static __FIT_DECLSPEC void __net_pack( std::ostream& s, const std::string& str ); @@ -287,6 +280,36 @@ { s.read( (char *)&x, sizeof(unsigned long) ); } static void __pack( std::ostream& s, unsigned long x ) { s.write( (const char *)&x, sizeof(unsigned long) ); } + // long long + static void __net_unpack( std::istream& s, long long& x ) + { + s.read( (char *)&x, sizeof(long long) ); + x = stem::from_net( x ); + } + static void __net_pack( std::ostream& s, long long x ) + { + x = stem::to_net( x ); + s.write( (const char *)&x, sizeof(long long) ); + } + static void __unpack( std::istream& s, long long& x ) + { s.read( (char *)&x, sizeof(long long) ); } + static void __pack( std::ostream& s, long long x ) + { s.write( (const char *)&x, sizeof(long long) ); } + // unsigned long long + static void __net_unpack( std::istream& s, unsigned long long& x ) + { + s.read( (char *)&x, sizeof(unsigned long long) ); + x = stem::from_net( x ); + } + static void __net_pack( std::ostream& s, unsigned long long x ) + { + x = stem::to_net( x ); + s.write( (const char *)&x, sizeof(unsigned long long) ); + } + static void __unpack( std::istream& s, unsigned long long& x ) + { s.read( (char *)&x, sizeof(unsigned long long) ); } + static void __pack( std::ostream& s, unsigned long long x ) + { s.write( (const char *)&x, sizeof(unsigned long long) ); } // char static void __net_unpack( std::istream& s, char& x ) { s.read( (char *)&x, sizeof(char) ); } @@ -344,6 +367,31 @@ { s.read( (char *)&x, sizeof(unsigned short) ); } static void __pack( std::ostream& s, unsigned short x ) { s.write( (const char *)&x, sizeof(unsigned short) ); } +#else + template <class T> + static void __net_unpack( std::istream& s, T& x ) + { + s.read( (char *)&x, sizeof(T) ); + x = stem::from_net( x ); + } + template <class T> + static void __net_pack( std::ostream& s, T x ) + { + x = stem::to_net( x ); + s.write( (const char *)&x, sizeof(T) ); + } + template <class T> + static void __unpack( std::istream& s, T& x ) + { s.read( (char *)&x, sizeof(T) ); } + template <class T> + static void __pack( std::ostream& s, T x ) + { s.write( (const char *)&x, sizeof(T) ); } + + static __FIT_DECLSPEC void __net_unpack( std::istream& s, std::string& str ); + static __FIT_DECLSPEC void __net_pack( std::ostream& s, const std::string& str ); + static __FIT_DECLSPEC void __unpack( std::istream& s, std::string& str ); + static __FIT_DECLSPEC void __pack( std::ostream& s, const std::string& str ); +#endif }; } // stem Modified: trunk/complement/explore/include/stem/Event.h =================================================================== --- trunk/complement/explore/include/stem/Event.h 2006-11-24 10:15:25 UTC (rev 1404) +++ trunk/complement/explore/include/stem/Event.h 2006-11-24 10:21:44 UTC (rev 1405) @@ -1,22 +1,15 @@ -// -*- C++ -*- Time-stamp: <06/07/20 10:26:33 ptr> +// -*- C++ -*- Time-stamp: <06/11/24 13:07:19 ptr> /* + * * Copyright (c) 1995-1999, 2002, 2003, 2005, 2006 * Petr Ovtchenkov * * Copyright (c) 1999-2001 * ParallelGraphics Ltd. * - * Licensed under the Academic Free License version 2.1 + * Licensed under the Academic Free License version 3.0 * - * This material is provided "as is", with absolutely no warranty expressed - * or implied. Any use is at your own risk. - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. */ #ifndef __stem_Event_h @@ -33,9 +26,8 @@ #include <sstream> #include <stdint.h> -#ifndef __EvPack_h #include <stem/EvPack.h> -#endif +#include <mt/uid.h> #ifndef STLPORT #include <bits/cpp_type_traits.h> @@ -114,6 +106,25 @@ using ::__type_traits; #endif +struct gaddr_type : + public __pack_base +{ + xmt::uuid_type hid; + int64_t pid; // pid_t defined as int, so it may be int64_t + stem::addr_type addr; + + __FIT_DECLSPEC virtual void pack( std::ostream& ) const; + __FIT_DECLSPEC virtual void unpack( std::istream& ); + __FIT_DECLSPEC virtual void net_pack( std::ostream& ) const; + __FIT_DECLSPEC virtual void net_unpack( std::istream& ); + + bool operator ==( const gaddr_type& ga ) const + { return hid == ga.hid && pid == ga.pid && addr == ga.addr; } + bool operator !=( const gaddr_type& ga ) const + { return hid != ga.hid || pid != ga.pid || addr != ga.addr; } + __FIT_DECLSPEC bool operator <( const gaddr_type& ga ) const; +}; + class __Event_Base { public: Modified: trunk/complement/explore/include/stem/NetTransport.h =================================================================== --- trunk/complement/explore/include/stem/NetTransport.h 2006-11-24 10:15:25 UTC (rev 1404) +++ trunk/complement/explore/include/stem/NetTransport.h 2006-11-24 10:21:44 UTC (rev 1405) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/10/12 14:24:02 ptr> +// -*- C++ -*- Time-stamp: <06/11/24 13:07:32 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 @@ -18,29 +18,16 @@ #include <config/feature.h> #endif -#ifndef __SOCKSTREAM__ #include <sockios/sockstream> -#endif -#ifndef __XMT_H #include <mt/xmt.h> -#endif #include <string> #include <sstream> #include <map> -#ifndef __stem_Event_h #include <stem/Event.h> -#endif - -#ifndef __stem_EvSession_h -#include <stem/EvSession.h> -#endif - -#ifndef __stem_EventHandler_h #include <stem/EventHandler.h> -#endif namespace stem { @@ -50,21 +37,15 @@ public EventHandler // to avoid dependence from creation order { public: - typedef std::map<key_type,key_type> heap_type; -// typedef std::map<key_type,key_type,std::less<key_type>, -// __STL_DEFAULT_ALLOCATOR(key_type) > heap_type; - NetTransport_base() : _count( 0 ), - net( 0 ), - _net_ns( badaddr ) + net( 0 ) { } NetTransport_base( const char *info ) : EventHandler( info ), _count( 0 ), - net( 0 ), - _net_ns( badaddr ) + net( 0 ) { } __FIT_DECLSPEC ~NetTransport_base(); @@ -79,21 +60,13 @@ { return net != 0 && net->is_open(); } virtual __FIT_DECLSPEC void close(); - __FIT_DECLSPEC bool push( const Event& ); + __FIT_DECLSPEC bool push( const Event&, const gaddr_type& dst, const gaddr_type& src ); - addr_type ns() const - { return _net_ns; } - protected: - addr_type rar_map( addr_type k, const std::string& name ); bool pop( Event& ); std::sockstream *net; 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 }; class NetTransport : Modified: trunk/complement/explore/lib/stem/EvManager.cc =================================================================== --- trunk/complement/explore/lib/stem/EvManager.cc 2006-11-24 10:15:25 UTC (rev 1404) +++ trunk/complement/explore/lib/stem/EvManager.cc 2006-11-24 10:21:44 UTC (rev 1405) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/10/10 18:11:29 ptr> +// -*- C++ -*- Time-stamp: <06/11/24 11:59:21 ptr> /* * @@ -106,11 +106,16 @@ __FIT_DECLSPEC addr_type EvManager::Subscribe( EventHandler *object, const std::string& info ) { - MT_REENTRANT( _lock_heap, _x1 ); - addr_type id = create_unique(); - __Object_Entry& record = heap[id]; - record.ref = object; - record.info = info; + addr_type id; + { + Locker _x1( _lock_heap ); + id = create_unique(); + heap[id] = object; + } + { + Locker _x1( _lock_iheap ); + iheap[id] = info; + } return id; } @@ -118,12 +123,15 @@ __FIT_DECLSPEC addr_type EvManager::Subscribe( EventHandler *object, const char *info ) { - MT_REENTRANT( _lock_heap, _x1 ); - addr_type id = create_unique(); - __Object_Entry& record = heap[id]; - record.ref = object; + addr_type id; + { + Locker _x1( _lock_heap ); + id = create_unique(); + heap[id] = object; + } if ( info ) { - record.info = info; + Locker _x1( _lock_iheap ); + iheap[id] = info; } return id; @@ -133,14 +141,19 @@ addr_type EvManager::SubscribeID( addr_type id, EventHandler *object, const std::string& info ) { - MT_REENTRANT( _lock_heap, _x1 ); - if ( (id & extbit) || unsafe_is_avail( id ) ) { + if ( (id & extbit) ) { return badaddr; + } else { + Locker _x1( _lock_heap ); + if ( unsafe_is_avail( id ) ) { + return badaddr; + } + heap[id] = object; } - __Object_Entry& record = heap[id]; - record.ref = object; - record.info = info; + Locker _x1( _lock_iheap ); + iheap[id] = info; + return id; } @@ -148,49 +161,63 @@ addr_type EvManager::SubscribeID( addr_type id, EventHandler *object, const char *info ) { - MT_REENTRANT( _lock_heap, _x1 ); - if ( (id & extbit) || unsafe_is_avail( id ) ) { + if ( (id & extbit) ) { return badaddr; + } else { + Locker _x1( _lock_heap ); + if ( unsafe_is_avail( id ) ) { + return badaddr; + } + heap[id] = object; } - __Object_Entry& record = heap[id]; - record.ref = object; if ( info ) { - record.info = info; + Locker _x1( _lock_iheap ); + iheap[id] = info; } return id; } __FIT_DECLSPEC -addr_type EvManager::SubscribeRemote( NetTransport_base *channel, - addr_type rmkey, +addr_type EvManager::SubscribeRemote( const detail::transport& tr, + const gaddr_type& addr, const std::string& info ) { - MT_REENTRANT( _lock_heap, _x1 ); - addr_type id = create_unique_x(); - __Object_Entry& record = heap[id]; - // record.ref = object; - record.info = info; - // _STLP_ASSERT( channel != 0 ); - record.addremote( rmkey, channel ); + addr_type id; + { + Locker _x1( _lock_xheap ); + id = create_unique_x(); + _ex_heap[id] = addr; + _ui_heap[addr] = id; + _tr_heap.insert( make_pair( addr, tr ) ); + _ch_heap.insert( make_pair( tr.link, addr ) ); + } + { + Locker _x1( _lock_iheap ); + iheap[id] = info; + } return id; } __FIT_DECLSPEC -addr_type EvManager::SubscribeRemote( NetTransport_base *channel, - addr_type rmkey, +addr_type EvManager::SubscribeRemote( const detail::transport& tr, + const gaddr_type addr, const char *info ) { - MT_REENTRANT( _lock_heap, _x1 ); - addr_type id = create_unique_x(); - __Object_Entry& record = heap[id]; - // record.ref = object; + addr_type id; + { + Locker _x1( _lock_xheap ); + id = create_unique_x(); + _ex_heap[id] = addr; + _ui_heap[addr] = id; + _tr_heap.insert( make_pair( addr, tr ) ); + _ch_heap.insert( make_pair( tr.link, addr ) ); + } if ( info ) { - record.info = info; + Locker _x1( _lock_iheap ); + iheap[id] = info; } - // _STLP_ASSERT( channel != 0 ); - record.addremote( rmkey, channel ); return id; } @@ -198,15 +225,41 @@ __FIT_DECLSPEC bool EvManager::Unsubscribe( addr_type id ) { - MT_REENTRANT( _lock_heap, _x1 ); - heap.erase( /* (const heap_type::key_type&)*/ id ); - return true; // may be here check object's reference count + if ( (id & extbit) ) { + Locker _x1( _lock_xheap ); + gaddr_type& addr = _ex_heap[id]; + + pair<uuid_tr_heap_type::iterator,uuid_tr_heap_type::iterator> range = _tr_heap.equal_range( addr ); + for ( uuid_tr_heap_type::iterator i = range.first; i != range.second; ++i ) { + pair<tr_uuid_heap_type::iterator,tr_uuid_heap_type::iterator> ch_range = _ch_heap.equal_range( i->link ); + for ( tr_uuid_heap_type::iterator j = ch_range.first; j != ch_range.second; ) { + if ( j->second == i->first ) { + _ch_heap.erase( j++ ); + continue; + } + ++j; + } + } + _tr_heap.erase( range.first, range.second ); + _ui_heap.erase( addr ); + _ex_heap.erase( id ); + } else { + Locker _x1( _lock_heap ); + heap.erase( id ); + + // Notify remotes? + } + Locker _x1( _lock_iheap ); + iheap.erase( id ); + + return true; } __FIT_DECLSPEC -void EvManager::Remove( NetTransport_base *channel ) +void EvManager::Remove( void *channel ) { - MT_REENTRANT( _lock_heap, _x1 ); + Locker _x1( _lock_xheap ); + Locker _x2( _lock_iheap ); unsafe_Remove( channel ); } @@ -215,100 +268,116 @@ // from [remote name -> local name] mapping table, and mark related session as // 'disconnected'. __FIT_DECLSPEC -void EvManager::unsafe_Remove( NetTransport_base *channel ) +void EvManager::unsafe_Remove( void *channel ) { - heap_type::iterator i = heap.begin(); - - while ( i != heap.end() ) { - if ( (*i).second.remote != 0 && (*i).second.remote->channel == channel ) { - heap.erase( i++ ); - } else { - ++i; - } + pair<tr_uuid_heap_type::iterator,tr_uuid_heap_type::iterator> ch_range = _ch_heap.equal_range( channel ); + for (tr_uuid_heap_type::iterator i = ch_range.first; i != ch_range.second; ++i ) { + _tr_heap.erase( i->second ); + addr_type address = _ui_heap[i->second]; + _ex_heap.erase( address ); + iheap.erase( address ); + _ui_heap.erase( i->second ); } + _ch_heap.erase( ch_range.first, ch_range.second ); } -__FIT_DECLSPEC NetTransport_base *EvManager::transport( addr_type id ) const +__FIT_DECLSPEC const detail::transport& EvManager::transport( 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 0; + Locker _x1( _lock_xheap ); + if ( (id & extbit) != 0 ) { + ext_uuid_heap_type::iterator i = _ex_heap.find( id ); + if ( i == _ex_heap.end() ) { + throw range_error( string( "no such address" ) ); + } + pair<uuid_tr_heap_type::iterator,uuid_tr_heap_type::iterator> range = _tr_heap.equal_range( i->second ); + if ( range.first == _tr_heap.end() ) { + throw range_error( string( "no transport" ) ); + } + return min_element( range.first, range.second, tr_compare ).second; } - return (*i).second.remote->channel; + throw range_error( string( "internal address" ) ); } -#if 0 -#define _XMB( msg ) \ -{ \ - ostringstream ss; \ - ss << msg << "\n" \ - << __FILE__ << ":" << __LINE__ << endl; \ - MessageBox( 0, ss.str().c_str(), "Planet Problem", MB_OK ); \ -} - -#endif - // Resolve Address -> Object Reference, call Object's dispatcher in case // of local object, or call appropriate channel delivery function for // remote object. All outgoing events, and incoming remote events -// (this method allow to forward remote-object-event to another remote-object +// (this method allow to forward event from remote object to another remote object, +// i.e. work as 'proxy' with 'transit objects') + void EvManager::Send( const Event& e ) { - try { - // Will be useful to block on erase/insert operations... - MT_LOCK( _lock_heap ); -// _XMB( "MT_LOCK" ) - heap_type::iterator i = heap.find( e.dest() ); - if ( i != heap.end() ) { - if ( (*i).second.ref != 0 ) { // local delivery - EventHandler *object = (*i).second.ref; -// std::cerr << "Local\n"; -// _XMB( "MT_UNLOCK" ) - MT_UNLOCK( _lock_heap ); - try { - object->Dispatch( e ); - } - catch ( ... ) { - } - } else { // remote delivery -// std::cerr << "Remote\n"; - __Remote_Object_Entry *remote = (*i).second.remote; - // _STLP_ASSERT( remote != 0 ); - addr_type save_dest = e.dest(); - e.dest( remote->key ); // substitute address on remote system - if ( !remote->channel->push( e ) ) { - // if I detect bad connection during writing to net - // (in the push), I remove this connetion related entries. - // Required by non-Solaris OS. Unsafe variant allow avoid - // deadlock here. - unsafe_Remove( remote->channel ); - } - e.dest( save_dest ); // restore original (may be used more) -// _XMB( "MT_UNLOCK" ) - MT_UNLOCK( _lock_heap ); + if ( e.dest() & extbit ) { // external object + try { + _lock_xheap.lock(); + ext_uuid_heap_type::iterator i = _ex_heap.find( e.dest() ); + if ( i == _ex_heap.end() ) { // destination not found + throw invalid_argument( string("external address unknown") ); } - } else { -// _XMB( "MT_UNLOCK" ) - MT_UNLOCK( _lock_heap ); -#if 0 - try { - std::cerr << "===== stem: " - << std::hex - << std::setiosflags(std::ios_base::showbase) - << e.dest() - << " not found, source: " << e.src() - << ", code " << e.code() << std::dec << endl; + + pair<uuid_tr_heap_type::iterator,uuid_tr_heap_type::iterator> range = _tr_heap.equal_range( i->second ); + if ( range.first == _tr_heap.end() ) { + throw range_error( string( "no transport" ) ); } - catch ( ... ) { + detail::transport& tr = min_element( range.first, range.second, tr_compare ).second; + detail::transport::kind_type k = tr.kind; + void *link = tr.link; + uuid_type gaddr_dst( i->second ); + uuid_type gaddr_src; + + ext_uuid_heap_type::iterator j = _ex_heap.find( e.src() ); + if ( j == _ex_heap.end() ) { + gaddr_type& _gaddr_src = _ex_heap[e.src()]; + _gaddr_src.hid = xmt::hostid(); + _gaddr_src.pid = getpid(); + _gaddr_src.addr = e.src(); // it may be as local as foreign; if e.src() + // is foreign, the object is 'transit object' + _ui_heap[_gaddr_src] = e.src(); + gaddr_src = _gaddr_src; + } else { + gaddr_src = j->second; } -#endif + + _lock_xheap.unlock(); + + switch ( k ) { + detail::transport::socket_tcp: + if ( reinterpret_cast<NetTransport_base *>(link)->push( e, gaddr_dst, gaddr_src) ) { + // if I detect bad connection during writing to net + // (in the push), I remove this connetion related entries. + // Required by non-Solaris OS. Unsafe variant allow avoid + // deadlock here. + unsafe_Remove( link ); + } + break; + detail::transport::unknown: + break; + default: + break; + } } + catch ( ... ) { + _lock_xheap.unlock(); + } + } else { // local object + try { + _lock_heap.lock(); + local_heap_type::iterator i = heap.find( e.dest() ); + if ( i == heap.end() ) { // destination not found + throw invalid_argument( string("address unknown") ); + } + EventHandler *object = i->second; // target object + _lock_heap.unlock(); + + try { + object->Dispatch( e ); // call dispatcher + } + catch ( ... ) { + } + } + catch ( ... ) { + _lock_heap.unlock(); + } } - catch ( ... ) { -// _XMB( "MT_UNLOCK" ) - MT_UNLOCK( _lock_heap ); - } } addr_type EvManager::create_unique() Modified: trunk/complement/explore/lib/stem/EvPack.cc =================================================================== --- trunk/complement/explore/lib/stem/EvPack.cc 2006-11-24 10:15:25 UTC (rev 1404) +++ trunk/complement/explore/lib/stem/EvPack.cc 2006-11-24 10:21:44 UTC (rev 1405) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/10/04 11:13:07 ptr> +// -*- C++ -*- Time-stamp: <06/11/24 13:06:12 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 @@ -93,4 +93,50 @@ #endif } +__FIT_DECLSPEC void gaddr_type::pack( std::ostream& s ) const +{ + s.write( (const char *)hid.u.b, 16 ); + __pack( s, pid ); + __pack( s, addr ); +} + +__FIT_DECLSPEC void gaddr_type::unpack( std::istream& s ) +{ + s.read( (char *)hid.u.b, 16 ); + __unpack( s, pid ); + __unpack( s, addr ); +} + +__FIT_DECLSPEC void gaddr_type::net_pack( std::ostream& s ) const +{ + s.write( (const char *)hid.u.b, 16 ); + __net_pack( s, pid ); + __net_pack( s, addr ); +} + +__FIT_DECLSPEC void gaddr_type::net_unpack( std::istream& s ) +{ + s.read( (char *)hid.u.b, 16 ); + __net_unpack( s, pid ); + __net_unpack( s, addr ); +} + +__FIT_DECLSPEC bool gaddr_type::operator <( const gaddr_type& ga ) const +{ + if ( hid < ga.hid ) { + return true; + } else if ( ga.hid < hid ) { + return false; + } + if ( pid < ga.pid ) { + return true; + } else if ( ga.pid < pid ) { + return false; + } + if ( addr < ga.addr ) { + return true; + } + return false; +} + } // namespace stem Modified: trunk/complement/explore/lib/stem/Makefile.inc =================================================================== --- trunk/complement/explore/lib/stem/Makefile.inc 2006-11-24 10:15:25 UTC (rev 1404) +++ trunk/complement/explore/lib/stem/Makefile.inc 2006-11-24 10:21:44 UTC (rev 1405) @@ -1,9 +1,9 @@ -# -*- Makefile -*- Time-stamp: <01/07/27 14:54:18 ptr> +# -*- Makefile -*- Time-stamp: <06/11/23 23:37:53 ptr> LIBNAME = stem MAJOR = 4 -MINOR = 1 +MINOR = 2 PATCH = 0 SRC_CC = _EventHandler.cc NetTransport.cc EvManager.cc EvPack.cc crc.cc \ - _SessionMgr.cc Names.cc Cron.cc _EvSession.cc + Names.cc Cron.cc Modified: trunk/complement/explore/lib/stem/NetTransport.cc =================================================================== --- trunk/complement/explore/lib/stem/NetTransport.cc 2006-11-24 10:15:25 UTC (rev 1404) +++ trunk/complement/explore/lib/stem/NetTransport.cc 2006-11-24 10:21:44 UTC (rev 1405) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/10/12 14:24:31 ptr> +// -*- C++ -*- Time-stamp: <06/11/24 13:09:57 ptr> /* * @@ -19,6 +19,7 @@ #include <config/feature.h> #include <iterator> #include <iomanip> +#include <sstream> #include "stem/NetTransport.h" #include "stem/EventHandler.h" #include "stem/EvManager.h" @@ -30,9 +31,7 @@ namespace stem { -#ifndef _MSC_VER using namespace std; -#endif #ifdef _BIG_ENDIAN static const uint32_t EDS_MAGIC = 0xc2454453U; @@ -100,28 +99,12 @@ // cerr << __FILE__ << ":" << __LINE__ << endl; if ( net != 0 ) { manager()->Remove( this ); - rar.clear(); net->close(); // cerr << __FILE__ << ":" << __LINE__ << endl; net = 0; } } -const string __ns_at( "ns@" ); -const string __at( "@" ); - -addr_type NetTransport_base::rar_map( addr_type k, const string& name ) -{ - heap_type::iterator r = rar.find( k ); - if ( r == rar.end() ) { - r = rar.insert( - heap_type::value_type( k, - manager()->SubscribeRemote( this, k, name ) ) ).first; - } - - return (*r).second; -} - bool NetTransport_base::pop( Event& _rs ) { uint32_t buf[8]; @@ -188,30 +171,31 @@ __FIT_DECLSPEC -bool NetTransport_base::push( const Event& _rs ) +bool NetTransport_base::push( const Event& _rs, const gaddr_type& dst, const gaddr_type& src ) { // _STLP_ASSERT( net != 0 ); if ( !net->good() ) { return false; } - uint32_t buf[8]; + // const int bsz = 8-2+(4+2+1)*2; + // uint32_t buf[bsz]; - // buf[0] = to_net( EDS_MAGIC ); - buf[0] = EDS_MAGIC; - buf[1] = to_net( _rs.code() ); - buf[2] = to_net( _rs.dest() ); - buf[3] = to_net( _rs.src() ); + ostringstream sbuf; // 4 bytes + sbuf.write( (const char *)&EDS_MAGIC, sizeof(EDS_MAGIC) ); // 0 + __pack_base::__net_pack( sbuf, _rs.code() ); // 1 + dst.net_pack( sbuf ); // 2-8 + src.net_pack( sbuf ); // 9-15 // MT_IO_REENTRANT_W( *net ) MT_IO_LOCK_W( *net ) - buf[4] = to_net( ++_count ); - buf[5] = 0; // time? - buf[6] = to_net( static_cast<uint32_t>(_rs.value().size()) ); - buf[7] = to_net( adler32( (unsigned char *)buf, sizeof(uint32_t) * 7 ) ); // crc + __pack_base::__net_pack( sbuf, ++_count ); // 16 + __pack_base::__net_pack( sbuf, 0 ); // 17 time? + __pack_base::__net_pack( sbuf, static_cast<uint32_t>(_rs.value().size()) ); // 18 + __pack_base::__net_pack( sbuf, adler32( (unsigned char *)sbuf.str().c_str(), sizeof(uint32_t) * 19 ) ); // 19 crc try { - net->write( (const char *)buf, sizeof(uint32_t) * 8 ); + net->write( sbuf.str().c_str(), sizeof(uint32_t) * 20 ); copy( _rs.value().begin(), _rs.value().end(), ostream_iterator<char,char,char_traits<char> >(*net) ); @@ -240,18 +224,6 @@ NetTransport::NetTransport( std::sockstream& s ) : NetTransport_base( "stem::NetTransport" ) { - const string& _hostname = hostname( s.rdbuf()->inet_addr() ); - // cerr << "Connected: " << _hostname << endl; - - net = &s; - _at_hostname = __at + _hostname; - - try { - _net_ns = rar_map( ns_addr, __ns_at + _hostname ); - } - catch ( std::domain_error& ex ) { - cerr << ex.what() << endl; - } } __FIT_DECLSPEC This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2006-11-24 10:15:26
|
Revision: 1404 http://svn.sourceforge.net/complement/?rev=1404&view=rev Author: complement Date: 2006-11-24 02:15:25 -0800 (Fri, 24 Nov 2006) Log Message: ----------- use int64_t to reduce comparisons Modified Paths: -------------- trunk/complement/explore/include/mt/uid.h Modified: trunk/complement/explore/include/mt/uid.h =================================================================== --- trunk/complement/explore/include/mt/uid.h 2006-11-24 10:14:24 UTC (rev 1403) +++ trunk/complement/explore/include/mt/uid.h 2006-11-24 10:15:25 UTC (rev 1404) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/23 16:51:52 ptr> +// -*- C++ -*- Time-stamp: <06/11/23 23:34:55 ptr> /* * Copyright (c) 2006 @@ -16,6 +16,7 @@ #endif #include <string> +// #include <algorithm> #include <stdint.h> namespace xmt { @@ -25,6 +26,7 @@ union { uint8_t b[16]; uint32_t i[4]; + uint64_t l[2]; } u; @@ -33,19 +35,29 @@ uuid_type( const uuid_type& uid ) { - u.i[0] = uid.u.i[0]; - u.i[1] = uid.u.i[1]; - u.i[2] = uid.u.i[2]; - u.i[3] = uid.u.i[3]; + // u.i[0] = uid.u.i[0]; u.i[1] = uid.u.i[1]; + // u.i[2] = uid.u.i[2]; u.i[3] = uid.u.i[3]; + u.l[0] = uid.u.l[0]; u.l[1] = uid.u.l[1]; } - bool operator ==( const uuid_type& uid ) - { return u.i[0] == uid.u.i[0] && u.i[1] == uid.u.i[1] && u.i[2] == uid.u.i[2] && u.i[3] == uid.u.i[3]; } + bool operator ==( const uuid_type& uid ) const + { + // return u.i[0] == uid.u.i[0] && u.i[1] == uid.u.i[1] && u.i[2] == uid.u.i[2] && u.i[3] == uid.u.i[3]; + return u.l[0] == uid.u.l[0] && u.l[1] == uid.u.l[1]; + } + + bool operator !=( const uuid_type& uid ) const + { + // return u.i[0] != uid.u.i[0] || u.i[1] != uid.u.i[1] || u.i[2] != uid.u.i[2] || u.i[3] != uid.u.i[3]; + return u.l[0] != uid.u.l[0] || u.l[1] != uid.u.l[1]; + } - bool operator !=( const uuid_type& uid ) - { return u.i[0] != uid.u.i[0] || u.i[1] != uid.u.i[1] || u.i[2] != uid.u.i[2] || u.i[3] != uid.u.i[3]; } - + bool operator <( const uuid_type& uid ) const + { + // return std::lexicographical_compare( u.i, u.i + 4, uid.u.i, uid.u.i + 4 ); + return u.l < uid.u.l ? true : u.l > uid.u.l ? false : (u.l[1] < uid.u.l[1]); + } }; const std::string& hostid_str(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |