[complement-svn] SF.net SVN: complement: [1838] branches/complement-sockios/explore
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2008-03-28 21:09:46
|
Revision: 1838 http://complement.svn.sourceforge.net/complement/?rev=1838&view=rev Author: complement Date: 2008-03-28 14:09:36 -0700 (Fri, 28 Mar 2008) Log Message: ----------- debug Modified Paths: -------------- branches/complement-sockios/explore/include/sockios/sockstream2 branches/complement-sockios/explore/include/sockios/sp.h branches/complement-sockios/explore/lib/sockios/ut/Makefile Modified: branches/complement-sockios/explore/include/sockios/sockstream2 =================================================================== --- branches/complement-sockios/explore/include/sockios/sockstream2 2008-03-27 12:19:58 UTC (rev 1837) +++ branches/complement-sockios/explore/include/sockios/sockstream2 2008-03-28 21:09:36 UTC (rev 1838) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/03/27 08:52:14 ptr> +// -*- C++ -*- Time-stamp: <08/03/27 17:18:22 yeti> /* * Copyright (c) 1997-1999, 2002, 2003, 2005-2008 @@ -315,6 +315,9 @@ } else { std::tr2::lock_guard<std::tr2::mutex> lk( _init_lock ); if ( --_count == 0 ) { + if ( basic_socket<charT,traits,_Alloc>::mgr == 0 ) { + std::cerr << __FILE__ << ":" << __LINE__ << " shit happens\n"; + } delete basic_socket<charT,traits,_Alloc>::mgr; basic_socket<charT,traits,_Alloc>::mgr = 0; } @@ -331,6 +334,7 @@ { if ( _count != 0 ) { // stop mgr + _count = 1; delete basic_socket<charT,traits,_Alloc>::mgr; basic_socket<charT,traits,_Alloc>::mgr = new detail::sockmgr<charT,traits,_Alloc>(); } Modified: branches/complement-sockios/explore/include/sockios/sp.h =================================================================== --- branches/complement-sockios/explore/include/sockios/sp.h 2008-03-27 12:19:58 UTC (rev 1837) +++ branches/complement-sockios/explore/include/sockios/sp.h 2008-03-28 21:09:36 UTC (rev 1838) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/03/27 09:28:41 ptr> +// -*- C++ -*- Time-stamp: <08/03/27 17:53:40 yeti> /* * Copyright (c) 2008 @@ -294,6 +294,7 @@ static void __at_fork_child(); static void __at_fork_parent(); static int _count; + static bool _at_fork; }; static char Init_buf[]; @@ -312,7 +313,7 @@ ploop( loop, this ) { new( Init_buf ) Init(); } - ~connect_processor() + virtual ~connect_processor() { connect_processor::close(); if ( ploop.joinable() ) { @@ -338,6 +339,13 @@ void worker(); private: + connect_processor( const connect_processor& ) + { } + + connect_processor& operator =( const connect_processor& ) + { return *this; } + + struct processor { processor() : @@ -401,7 +409,7 @@ worker_pool_t worker_pool; ready_pool_t ready_pool; - volatile bool _in_work; + bool _in_work; std::tr2::mutex wklock; std::tr2::mutex rdlock; std::tr2::condition_variable cnd; @@ -416,6 +424,9 @@ int connect_processor<Connect, charT, traits, _Alloc, C>::Init::_count = 0; template<class Connect, class charT, class traits, class _Alloc, void (Connect::*C)( std::basic_sockstream2<charT,traits,_Alloc>& )> +bool connect_processor<Connect, charT, traits, _Alloc, C>::Init::_at_fork = false; + +template<class Connect, class charT, class traits, class _Alloc, void (Connect::*C)( std::basic_sockstream2<charT,traits,_Alloc>& )> void connect_processor<Connect, charT, traits, _Alloc, C>::Init::_guard( int direction ) { static std::tr2::mutex _init_lock; @@ -423,10 +434,14 @@ if ( direction ) { std::tr2::lock_guard<std::tr2::mutex> lk( _init_lock ); if ( _count++ == 0 ) { - -// #ifdef __FIT__PTHREADS -// pthread_atfork( __at_fork_prepare, __at_fork_parent, __at_fork_child ); -// #endif +#ifdef __FIT_PTHREADS + if ( !_at_fork ) { // call only once + if ( pthread_atfork( __at_fork_prepare, __at_fork_parent, __at_fork_child ) ) { + // throw system_error + } + _at_fork = true; + } +#endif // _sock_processor_base::_idx = std::tr2::this_thread::xalloc(); } } else { @@ -444,6 +459,8 @@ template<class Connect, class charT, class traits, class _Alloc, void (Connect::*C)( std::basic_sockstream2<charT,traits,_Alloc>& )> void connect_processor<Connect, charT, traits, _Alloc, C>::Init::__at_fork_child() { + std::cerr << "SHOULD NEVER HAPPEN!!!!\n"; + if ( _count != 0 ) { } @@ -633,8 +650,13 @@ efd = epoll_create( hint ); if ( efd < 0 ) { // throw system_error( errno ) + throw std::runtime_error( "epoll_create" ); } - pipe( pipefd ); // check err + if ( pipe( pipefd ) < 0 ) { // check err + ::close( efd ); + // throw system_error; + throw std::runtime_error( "pipe" ); + } // cfd = pipefd[1]; epoll_event ev_add; @@ -656,13 +678,13 @@ ctl _ctl; _ctl.cmd = rqstop; - write( pipefd[1], &_ctl, sizeof(ctl) ); + ::write( pipefd[1], &_ctl, sizeof(ctl) ); _worker->join(); } - close( pipefd[1] ); - close( pipefd[0] ); - close( efd ); + ::close( pipefd[1] ); + ::close( pipefd[0] ); + ::close( efd ); delete _worker; } @@ -672,7 +694,10 @@ _ctl.cmd = listener; _ctl.data.ptr = static_cast<void *>(&p); - write( pipefd[1], &_ctl, sizeof(ctl) ); + int r = ::write( pipefd[1], &_ctl, sizeof(ctl) ); + if ( r < 0 || r != sizeof(ctl) ) { + throw std::runtime_error( "can't write to pipe" ); + } } #if 0 @@ -693,7 +718,10 @@ _ctl.data.ptr = static_cast<void *>(&s); errno = 0; - int r = write( pipefd[1], &_ctl, sizeof(ctl) ); + int r = ::write( pipefd[1], &_ctl, sizeof(ctl) ); + if ( r < 0 || r != sizeof(ctl) ) { + throw std::runtime_error( "can't write to pipe" ); + } } void exit_notify( sockbuf_t* b, int fd ) Modified: branches/complement-sockios/explore/lib/sockios/ut/Makefile =================================================================== --- branches/complement-sockios/explore/lib/sockios/ut/Makefile 2008-03-27 12:19:58 UTC (rev 1837) +++ branches/complement-sockios/explore/lib/sockios/ut/Makefile 2008-03-28 21:09:36 UTC (rev 1838) @@ -23,6 +23,8 @@ stldbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_STLDBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} endif dbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_DBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_DBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} + +dbg-shared: CXXFLAGS += -fkeep-inline-functions endif release-shared : LDLIBS = -lxmt -lsockios -lexam This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |