[complement-svn] SF.net SVN: complement: [1405] trunk/complement/explore
Status: Pre-Alpha
Brought to you by:
complement
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. |