Thread: [complement-svn] SF.net SVN: complement: [1846] branches/complement-sockios/explore/include/ sockio
Status: Pre-Alpha
Brought to you by:
complement
[complement-svn] SF.net SVN: complement: [1846]
branches/complement-sockios/explore/include/ sockios
From: <com...@us...> - 2008-04-11 18:15:55
|
Revision: 1846 http://complement.svn.sourceforge.net/complement/?rev=1846&view=rev Author: complement Date: 2008-04-11 11:15:28 -0700 (Fri, 11 Apr 2008) Log Message: ----------- under construction; Modified Paths: -------------- branches/complement-sockios/explore/include/sockios/sp.cc branches/complement-sockios/explore/include/sockios/sp.h Modified: branches/complement-sockios/explore/include/sockios/sp.cc =================================================================== --- branches/complement-sockios/explore/include/sockios/sp.cc 2008-04-09 17:35:43 UTC (rev 1845) +++ branches/complement-sockios/explore/include/sockios/sp.cc 2008-04-11 18:15:28 UTC (rev 1846) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/04/09 20:17:13 yeti> +// -*- C++ -*- Time-stamp: <08/04/11 21:52:28 yeti> /* * Copyright (c) 2008 @@ -199,9 +199,12 @@ } 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>::operator ()( typename connect_processor<Connect, charT, traits, _Alloc, C>::base_t::sockstream_t& s, const typename connect_processor<Connect, charT, traits, _Alloc, C>::base_t::adopt_new_t& ) +void connect_processor<Connect, charT, traits, _Alloc, C>::operator ()( int fd, const typename connect_processor<Connect, charT, traits, _Alloc, C>::base_t::adopt_new_t& ) { - Connect* c = new Connect( s ); + typename base_t::sockstream_t* s = base_t::create_stream( fd ); + + Connect* c = new Connect( s ); // bad point! I can't read from s in ctor indeed! + if ( s.rdbuf()->in_avail() ) { std::tr2::lock_guard<std::tr2::mutex> lk( rdlock ); ready_pool.push_back( processor( c, &s ) ); @@ -213,13 +216,14 @@ } 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>::operator ()( typename connect_processor<Connect, charT, traits, _Alloc, C>::base_t::sockstream_t& s, const typename connect_processor<Connect, charT, traits, _Alloc, C>::base_t::adopt_close_t& ) +void connect_processor<Connect, charT, traits, _Alloc, C>::operator ()( int fd, const typename connect_processor<Connect, charT, traits, _Alloc, C>::base_t::adopt_close_t& ) { { std::tr2::lock_guard<std::tr2::mutex> lk( wklock ); - typename worker_pool_t::iterator i = worker_pool.find( &s ); + typename worker_pool_t::iterator i = worker_pool.find( fd ); if ( i != worker_pool.end() ) { - delete i->second; + delete i->second.s; + delete i->second.c; // std::cerr << "oops\n"; worker_pool.erase( i ); return; @@ -229,7 +233,7 @@ Connect* c = 0; { std::tr2::lock_guard<std::tr2::mutex> lk( rdlock ); - typename ready_pool_t::iterator j = std::find( ready_pool.begin(), ready_pool.end(), /* std::bind2nd( typename processor::equal_to(), &s ) */ &s ); + typename ready_pool_t::iterator j = std::find( ready_pool.begin(), ready_pool.end(), /* std::bind2nd( typename processor::equal_to(), &s ) */ fd ); if ( j != ready_pool.end() ) { // std::cerr << "oops 2\n"; c = j->c; @@ -243,22 +247,22 @@ } 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>::operator ()( typename connect_processor<Connect, charT, traits, _Alloc, C>::base_t::sockstream_t& s, const typename connect_processor<Connect, charT, traits, _Alloc, C>::base_t::adopt_data_t& ) +void connect_processor<Connect, charT, traits, _Alloc, C>::operator ()( int fd, const typename connect_processor<Connect, charT, traits, _Alloc, C>::base_t::adopt_data_t& ) { - Connect* c; + processor p; { std::tr2::lock_guard<std::tr2::mutex> lk( wklock ); - typename worker_pool_t::const_iterator i = worker_pool.find( &s ); + typename worker_pool_t::const_iterator i = worker_pool.find( fd ); if ( i == worker_pool.end() ) { return; } - c = i->second; + p = i->second; worker_pool.erase( i ); } std::tr2::lock_guard<std::tr2::mutex> lk( rdlock ); - ready_pool.push_back( processor( c, &s ) ); + ready_pool.push_back( p ); cnd.notify_one(); // std::cerr << "notify data " << (void *)c << " " << ready_pool.size() << std::endl; } @@ -489,45 +493,35 @@ if ( fcntl( fd, F_SETFL, fcntl( fd, F_GETFL ) | O_NONBLOCK ) != 0 ) { throw std::runtime_error( "can't establish nonblock mode" ); } - sockstream_t* s; try { - s = new sockstream_t(); - std::cerr << __FILE__ << ":" << __LINE__ << " new sockstream_t: " << (void*)s << std::endl; - if ( s->rdbuf()->_open_sockmgr( fd, addr ) ) { - epoll_event ev_add; - ev_add.events = EPOLLIN | EPOLLRDHUP | EPOLLERR | EPOLLHUP | EPOLLET | EPOLLONESHOT; - ev_add.data.fd = fd; - fd_info new_info = { fd_info::owner, s, info.p }; - descr[fd] = new_info; + std::cerr << __FILE__ << ":" << __LINE__ << " new sockstream_t" << std::endl; + (*info.p)( fd, typename socks_processor_t::adopt_new_t() ); - if ( epoll_ctl( efd, EPOLL_CTL_ADD, fd, &ev_add ) < 0 ) { - std::cerr << "Accept, add " << fd << ", errno " << errno << std::endl; - descr.erase( fd ); - // throw system_error - } - std::cerr << __FILE__ << ":" << __LINE__ << " adopt_new_t()\n"; - bool in_closed = false; - { - std::tr2::lock_guard<std::tr2::mutex> lk( cll ); - typename fd_container_type::iterator closed_ifd = closed_queue.begin(); - for ( ; closed_ifd != closed_queue.end(); ++closed_ifd ) { - if ( closed_ifd->second.p == info.p ) { - in_closed = true; - std::cerr << "@@@ 1\n" << std::endl; - break; - } + epoll_event ev_add; + ev_add.events = EPOLLIN | EPOLLRDHUP | EPOLLERR | EPOLLHUP | EPOLLET | EPOLLONESHOT; + ev_add.data.fd = fd; + fd_info new_info = { fd_info::owner, s, info.p }; + descr[fd] = new_info; + + if ( epoll_ctl( efd, EPOLL_CTL_ADD, fd, &ev_add ) < 0 ) { + std::cerr << "Accept, add " << fd << ", errno " << errno << std::endl; + descr.erase( fd ); + // throw system_error + } + + std::cerr << __FILE__ << ":" << __LINE__ << " adopt_new_t()\n"; + bool in_closed = false; + { + std::tr2::lock_guard<std::tr2::mutex> lk( cll ); + typename fd_container_type::iterator closed_ifd = closed_queue.begin(); + for ( ; closed_ifd != closed_queue.end(); ++closed_ifd ) { + if ( closed_ifd->second.p == info.p ) { + in_closed = true; + std::cerr << "@@@ 1\n" << std::endl; + break; } } - if ( !in_closed ) { - std::cerr << __FILE__ << ":" << __LINE__ << " " << (void*)s << std::endl; - (*info.p)( *s, typename socks_processor_t::adopt_new_t() ); - std::cerr << __FILE__ << ":" << __LINE__ << " " << (void*)s << std::endl; - } - } else { - std::cerr << "Accept, delete " << fd << std::endl; - std::cerr << __FILE__ << ":" << __LINE__ << " " << (void*)s << std::endl; - delete s; } } catch ( const std::bad_alloc& ) { @@ -535,7 +529,6 @@ } catch ( ... ) { descr.erase( fd ); - delete s; } } } else { Modified: branches/complement-sockios/explore/include/sockios/sp.h =================================================================== --- branches/complement-sockios/explore/include/sockios/sp.h 2008-04-09 17:35:43 UTC (rev 1845) +++ branches/complement-sockios/explore/include/sockios/sp.h 2008-04-11 18:15:28 UTC (rev 1846) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/04/09 20:14:14 yeti> +// -*- C++ -*- Time-stamp: <08/04/11 22:14:39 yeti> /* * Copyright (c) 2008 @@ -100,9 +100,9 @@ virtual void close(); - virtual void operator ()( sockstream_t& s, const adopt_new_t& ) = 0; - virtual void operator ()( sockstream_t& s, const adopt_close_t& ) = 0; - virtual void operator ()( sockstream_t& s, const adopt_data_t& ) = 0; + virtual void operator ()( int fd, const adopt_new_t& ) = 0; + virtual void operator ()( int fd, const adopt_close_t& ) = 0; + virtual void operator ()( int fd, const adopt_data_t& ) = 0; private: sock_processor_base( const sock_processor_base& ); @@ -110,6 +110,12 @@ protected: void setoptions_unsafe( sock_base2::so_t optname, bool on_off = true, int __v = 0 ); + sockstream_t* create_stream( int fd ) + { + typename base_t::sockstream_t* s = new typename base_t::sockstream_t(); + s->rdbuf()->_open_sockmgr( fd, addr ); + return s; + } public: bool is_open() const @@ -208,11 +214,10 @@ { if ( ploop.joinable() ) { ploop.join(); } } private: - virtual void operator ()( typename base_t::sockstream_t& s, const typename base_t::adopt_new_t& ); - virtual void operator ()( typename base_t::sockstream_t& s, const typename base_t::adopt_close_t& ); - virtual void operator ()( typename base_t::sockstream_t& s, const typename base_t::adopt_data_t& ); + virtual void operator ()( int fd, const typename base_t::adopt_new_t& ); + virtual void operator ()( int fd, const typename base_t::adopt_close_t& ); + virtual void operator ()( int fd, const typename base_t::adopt_data_t& ); - static void loop( connect_processor* me ) { me->worker(); } @@ -251,6 +256,13 @@ { return s == p.s; } bool operator ==( const typename sock_processor_base<charT,traits,_Alloc>::sockstream_t* st ) const { return const_cast<const typename sock_processor_base<charT,traits,_Alloc>::sockstream_t*>(s) == st; } + bool operator ==( int fd ) const + { + if ( s == 0 ) { + return fd == -1; + } + return s->rdbuf()->fd() == fd; + } /* struct equal_to : @@ -265,13 +277,13 @@ bool pop_ready( processor& ); #ifdef __USE_STLPORT_HASH - typedef std::hash_map<typename base_t::sockstream_t*,Connect*> worker_pool_t; + typedef std::hash_map<int,processor> worker_pool_t; #endif #ifdef __USE_STD_HASH - typedef __gnu_cxx::hash_map<typename base_t::sockstream_t*,Connect*> worker_pool_t; + typedef __gnu_cxx::hash_map<int,processor> worker_pool_t; #endif #if defined(__USE_STLPORT_TR1) || defined(__USE_STD_TR1) - typedef std::tr1::unordered_map<typename base_t::sockstream_t*,Connect*> worker_pool_t; + typedef std::tr1::unordered_map<int,processor> worker_pool_t; #endif typedef std::deque<processor> ready_pool_t; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
[complement-svn] SF.net SVN: complement: [1913]
branches/complement-sockios/explore/include/ sockios
From: <com...@us...> - 2008-06-26 05:45:16
|
Revision: 1913 http://complement.svn.sourceforge.net/complement/?rev=1913&view=rev Author: complement Date: 2008-06-25 22:45:14 -0700 (Wed, 25 Jun 2008) Log Message: ----------- Try to resolve problem: I don't see event on closed listener's descriptor Modified Paths: -------------- branches/complement-sockios/explore/include/sockios/socksrv.cc branches/complement-sockios/explore/include/sockios/socksrv.h branches/complement-sockios/explore/include/sockios/sp.cc branches/complement-sockios/explore/include/sockios/sp.h Modified: branches/complement-sockios/explore/include/sockios/socksrv.cc =================================================================== --- branches/complement-sockios/explore/include/sockios/socksrv.cc 2008-06-26 05:44:53 UTC (rev 1912) +++ branches/complement-sockios/explore/include/sockios/socksrv.cc 2008-06-26 05:45:14 UTC (rev 1913) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/17 14:54:16 yeti> +// -*- C++ -*- Time-stamp: <08/06/18 22:25:39 yeti> /* * Copyright (c) 2008 @@ -72,19 +72,23 @@ if ( !basic_socket_t::is_open_unsafe() ) { return; } - basic_socket<charT,traits,_Alloc>::mgr->pop( *this, basic_socket_t::_fd ); + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + #ifdef WIN32 ::closesocket( basic_socket_t::_fd ); #else ::shutdown( basic_socket_t::_fd, 2 ); ::close( basic_socket_t::_fd ); #endif + basic_socket<charT,traits,_Alloc>::mgr->pop( *this, basic_socket_t::_fd ); basic_socket_t::_fd = -1; } template<class charT, class traits, class _Alloc> void sock_processor_base<charT,traits,_Alloc>::shutdown( sock_base::shutdownflg dir ) { + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + std::tr2::lock_guard<std::tr2::mutex> lk(_fd_lck); if ( basic_socket_t::is_open_unsafe() ) { if ( (dir & (sock_base::stop_in | sock_base::stop_out)) == @@ -185,8 +189,10 @@ template <class Connect, class charT, class traits, class _Alloc, void (Connect::*C)( std::basic_sockstream<charT,traits,_Alloc>& )> void connect_processor<Connect, charT, traits, _Alloc, C>::close() { + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; base_t::close(); +#if 0 { std::tr2::lock_guard<std::tr2::mutex> lk(inwlock); _in_work = false; // <--- set before cnd.notify_one(); (below in this func) @@ -198,6 +204,7 @@ // std::cerr << "=== " << ready_pool.size() << std::endl; cnd.notify_one(); } +#endif } template <class Connect, class charT, class traits, class _Alloc, void (Connect::*C)( std::basic_sockstream<charT,traits,_Alloc>& )> @@ -286,9 +293,11 @@ p = ready_pool.front(); // it may contain p.c == 0, p.s == 0, if !in_work() ready_pool.pop_front(); // std::cerr << "pop 1\n"; +#if 0 if ( p.c == 0 ) { // wake up, but _in_work may be still true here (in processor pipe?), return false; // even I know that _in_work <- false before notification... } // so, check twice +#endif } // std::cerr << "pop 2\n"; @@ -319,4 +328,18 @@ } } + +template <class Connect, class charT, class traits, class _Alloc, void (Connect::*C)( std::basic_sockstream<charT,traits,_Alloc>& )> +void connect_processor<Connect, charT, traits, _Alloc, C>::stop() +{ + std::tr2::lock_guard<std::tr2::mutex> lk(inwlock); + _in_work = false; // <--- set before cnd.notify_one(); (below in this func) + + std::tr2::lock_guard<std::tr2::mutex> lk2( rdlock ); + ready_pool.push_back( processor() ); // make ready_pool not empty + // std::cerr << "=== " << ready_pool.size() << std::endl; + cnd.notify_one(); + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; +} + } // namespace std Modified: branches/complement-sockios/explore/include/sockios/socksrv.h =================================================================== --- branches/complement-sockios/explore/include/sockios/socksrv.h 2008-06-26 05:44:53 UTC (rev 1912) +++ branches/complement-sockios/explore/include/sockios/socksrv.h 2008-06-26 05:45:14 UTC (rev 1913) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/17 15:44:44 yeti> +// -*- C++ -*- Time-stamp: <08/06/18 22:25:25 yeti> /* * Copyright (c) 2008 @@ -86,6 +86,14 @@ { sock_processor_base::open(INADDR_ANY, port, type, prot); } virtual void close(); +#if 0 + virtual void stop() = 0; +#else + virtual void stop() + { /* abort(); */ } + // void stop() + // { (this->*_real_stop)(); } +#endif #if 0 virtual sockbuf_t* operator ()( sock_base::socket_type fd, const sockaddr& ) = 0; @@ -99,7 +107,6 @@ virtual void operator ()( sock_base::socket_type fd ) { abort(); } #endif - private: sock_processor_base( const sock_processor_base& ); sock_processor_base& operator =( const sock_processor_base& ); @@ -115,6 +122,8 @@ return s; } + void (sock_processor_base::*_real_stop)(); + public: bool is_open() const { std::tr2::lock_guard<std::tr2::mutex> lk(_fd_lck); return basic_socket_t::is_open_unsafe(); } @@ -173,14 +182,14 @@ not_empty( *this ), _in_work( false ), ploop( loop, this ) - { new( Init_buf ) Init(); } + { new( Init_buf ) Init(); /* base_t::_real_stop = &connect_processor::_xstop; */ } explicit connect_processor( int port ) : base_t( port, sock_base::sock_stream ), not_empty( *this ), _in_work( false ), ploop( loop, this ) - { new( Init_buf ) Init(); } + { new( Init_buf ) Init(); /* base_t::_real_stop = &connect_processor::_xstop; */ } virtual ~connect_processor() { @@ -190,9 +199,24 @@ ploop.join(); } - basic_socket<charT,traits,_Alloc>::mgr->final( *this ); + // basic_socket<charT,traits,_Alloc>::mgr->final( *this ); +#if 0 { + std::tr2::lock_guard<std::tr2::mutex> lk( wklock ); + std::tr2::lock_guard<std::tr2::mutex> lk( rdlock ); + if ( worker_pool.empty() && ready_pool.empty() ) { + break; + } + + for ( ; ; ) { + + } + } +#endif + + + { std::tr2::lock_guard<std::tr2::mutex> lk2( rdlock ); cerr << __FILE__ << ":" << __LINE__ << " " << ready_pool.size() << endl; } @@ -200,16 +224,19 @@ { std::tr2::lock_guard<std::tr2::mutex> lk2( wklock ); cerr << __FILE__ << ":" << __LINE__ << " " << worker_pool.size() << endl; +#if 0 for ( typename worker_pool_t::iterator i = worker_pool.begin(); i != worker_pool.end(); ++i ) { delete i->second.c; delete i->second.s; } +#endif } ((Init *)Init_buf)->~Init(); } virtual void close(); + virtual void stop(); void wait() { if ( ploop.joinable() ) { ploop.join(); } } Modified: branches/complement-sockios/explore/include/sockios/sp.cc =================================================================== --- branches/complement-sockios/explore/include/sockios/sp.cc 2008-06-26 05:44:53 UTC (rev 1912) +++ branches/complement-sockios/explore/include/sockios/sp.cc 2008-06-26 05:45:14 UTC (rev 1913) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/17 17:41:00 yeti> +// -*- C++ -*- Time-stamp: <08/06/18 22:37:15 yeti> /* * Copyright (c) 2008 @@ -45,6 +45,19 @@ for ( int i = 0; i < n; ++i ) { // std::cerr << "epoll i = " << i << std::endl; + std::tr2::lock_guard<std::tr2::mutex> lck( cll ); + for ( typename fd_container_type::iterator closed_ifd = closed_queue.begin(); closed_ifd != closed_queue.end(); ++closed_ifd ) { + if ( epoll_ctl( efd, EPOLL_CTL_DEL, closed_ifd->first, 0 ) < 0 ) { + // ignore + } + if ( closed_ifd->first == ev[i].data.fd ) { + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + } + // descr.erase( closed_ifd->first ); + } + closed_queue.clear(); + // at this point closed queue empty + if ( ev[i].data.fd == pipefd[0] ) { // std::cerr << "on pipe\n"; cmd_from_pipe(); @@ -118,25 +131,22 @@ if ( ev_add.data.fd >= 0 ) { fd_info new_info = { 0, static_cast<sockbuf_t*>(_ctl.data.ptr), 0 }; descr[ev_add.data.fd] = new_info; - - std::tr2::lock_guard<std::tr2::mutex> lck( cll ); - - typename fd_container_type::iterator closed_ifd = closed_queue.find( ev_add.data.fd ); - if ( closed_ifd != closed_queue.end() ) { // reuse same fd? - closed_queue.erase( closed_ifd ); - if ( epoll_ctl( efd, EPOLL_CTL_DEL, ev_add.data.fd, 0 ) < 0 ) { - // throw system_error - std::cerr << __FILE__ << ":" << __LINE__ << std::endl; - } - // descr.erase( ifd ); - } - if ( epoll_ctl( efd, EPOLL_CTL_ADD, ev_add.data.fd, &ev_add ) < 0 ) { descr.erase( ev_add.data.fd ); // throw system_error } } break; + case listener_on_exit: + listeners_final.insert( _ctl.data.ptr ); + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + { + int lfd = check_closed_listener( reinterpret_cast<socks_processor_t*>(_ctl.data.ptr) ); + if ( lfd != -1 ) { + descr.erase( -1 ); + } + } + break; case rqstop: // std::cerr << "Stop request\n"; throw std::detail::stop_request(); // runtime_error( "Stop request (normal flow)" ); @@ -147,6 +157,7 @@ template<class charT, class traits, class _Alloc> void sockmgr<charT,traits,_Alloc>::process_listener( epoll_event& ev, typename sockmgr<charT,traits,_Alloc>::fd_container_type::iterator ifd ) { + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; if ( ev.events & EPOLLRDHUP ) { if ( epoll_ctl( efd, EPOLL_CTL_DEL, ifd->first, 0 ) < 0 ) { // throw system_error @@ -161,36 +172,21 @@ } } + listeners_final.insert(static_cast<void *>(ifd->second.p)); + + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + check_closed_listener( ifd->second.p ); + descr.erase( ifd ); - std::tr2::lock_guard<std::tr2::mutex> lck( cll ); - typename fd_container_type::iterator closed_ifd = closed_queue.find( ev.data.fd ); - if ( closed_ifd != closed_queue.end() && closed_ifd->second.p == ifd->second.p ) { - // listener in process of close - closed_queue.erase( closed_ifd ); - } - return; } if ( (ev.events & EPOLLIN) == 0 ) { + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; return; // I don't know what to do this case... } - // { - std::tr2::lock_guard<std::tr2::mutex> lck( cll ); - for ( typename fd_container_type::iterator closed_ifd = closed_queue.begin(); closed_ifd != closed_queue.end(); ++closed_ifd ) { - if ( epoll_ctl( efd, EPOLL_CTL_DEL, closed_ifd->first, 0 ) < 0 ) { - // ignore - } - if ( closed_ifd->first == ifd->first ) { - std::cerr << __FILE__ << ":" << __LINE__ << std::endl; - } - descr.erase( closed_ifd->first ); - } - closed_queue.clear(); - // at this point closed queue empty - sockaddr addr; socklen_t sz = sizeof( sockaddr_in ); @@ -223,16 +219,14 @@ } } + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + + listeners_final.insert(static_cast<void *>(ifd->second.p)); + + check_closed_listener( ifd->second.p ); + descr.erase( ifd ); - // check closed_queue, due to ifd->second.p->close(); add record in it -// std::tr2::lock_guard<std::tr2::mutex> lck( cll ); - typename fd_container_type::iterator closed_ifd = closed_queue.find( ev.data.fd ); - if ( closed_ifd != closed_queue.end() && closed_ifd->second.p == ifd->second.p ) { - // listener in process of close - closed_queue.erase( closed_ifd ); - } - // throw system_error ? std::cerr << __FILE__ << ":" << __LINE__ << std::endl; } else { // back to listen errno = 0; @@ -287,20 +281,6 @@ fd_info& info = ifd->second; - std::tr2::lock_guard<std::tr2::mutex> lck( cll ); - - for ( typename fd_container_type::iterator closed_ifd = closed_queue.begin(); closed_ifd != closed_queue.end(); ++closed_ifd ) { - if ( epoll_ctl( efd, EPOLL_CTL_DEL, closed_ifd->first, 0 ) < 0 ) { - // ignore - } - if ( closed_ifd->first == ifd->first ) { - std::cerr << __FILE__ << ":" << __LINE__ << std::endl; - } - descr.erase( closed_ifd->first ); - } - closed_queue.clear(); - // at this point closed queue empty - sockbuf_t* b = info.b; if ( b == 0 ) { // marginal case: sockbuf wasn't created by processor... if ( epoll_ctl( efd, EPOLL_CTL_DEL, ifd->first, 0 ) < 0 ) { @@ -308,6 +288,8 @@ } if ( info.p != 0 ) { // ... but controlled by processor (*info.p)( ifd->first, typename socks_processor_t::adopt_close_t() ); + + check_closed_listener( info.p ); } descr.erase( ifd ); std::cerr << __FILE__ << ":" << __LINE__ << std::endl; @@ -390,7 +372,7 @@ (*info.p)( ev.data.fd ); } } else { - std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + std::cerr << __FILE__ << ":" << __LINE__ << " " << ev.data.fd << std::endl; // std::cerr << "K " << ev.data.fd << ", " << errno << std::endl; // EPOLLRDHUP may be missed in kernel, but offset 0 is the same ev.events |= EPOLLRDHUP; // will be processed below @@ -410,11 +392,12 @@ if ( info.p != 0 ) { std::cerr << __FILE__ << ":" << __LINE__ << std::endl; (*info.p)( ifd->first, typename socks_processor_t::adopt_close_t() ); + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + check_closed_listener( info.p ); } else { std::cerr << __FILE__ << ":" << __LINE__ << std::endl; b->close(); } - // std::tr2::lock_guard<std::tr2::mutex> lck( cll ); closed_queue.erase( ev.data.fd ); descr.erase( ifd ); } @@ -457,7 +440,6 @@ ++ifd; } } -#endif std::tr2::lock_guard<std::tr2::mutex> lk( cll ); @@ -469,8 +451,42 @@ ++closed_ifd; } } +#endif } +template<class charT, class traits, class _Alloc> +int sockmgr<charT,traits,_Alloc>::check_closed_listener( socks_processor_t* p ) +{ + int myfd = -1; + + if ( !listeners_final.empty() ) { + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + if ( listeners_final.find( static_cast<void*>(p) ) != listeners_final.end() ) { + for ( typename fd_container_type::iterator i = descr.begin(); i != descr.end(); ++i ) { + if ( i->second.p == p ) { + if ( (i->second.flags & fd_info::listener) == 0 ) { // it's not me! + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + return -1; + } + myfd = i->first; + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + } + } + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + + // no more connection with this listener + listeners_final.erase( static_cast<void*>(p) ); + + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + + p->stop(); + } + } + + return myfd; +} + + } // namespace detail } // namespace std Modified: branches/complement-sockios/explore/include/sockios/sp.h =================================================================== --- branches/complement-sockios/explore/include/sockios/sp.h 2008-06-26 05:44:53 UTC (rev 1912) +++ branches/complement-sockios/explore/include/sockios/sp.h 2008-06-26 05:45:14 UTC (rev 1913) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/17 15:09:45 yeti> +// -*- C++ -*- Time-stamp: <08/06/18 22:36:24 yeti> /* * Copyright (c) 2008 @@ -80,7 +80,8 @@ listener, tcp_buffer, rqstop, - rqstart + rqstart, + listener_on_exit }; struct fd_info @@ -180,9 +181,18 @@ void pop( socks_processor_t& p, sock_base::socket_type _fd ) { - fd_info info = { fd_info::listener, 0, &p }; - std::tr2::lock_guard<std::tr2::mutex> lk( cll ); - closed_queue[_fd] = info; + ctl _ctl; + _ctl.cmd = listener_on_exit; + _ctl.data.ptr = reinterpret_cast<void *>(&p); + + int r = ::write( pipefd[1], &_ctl, sizeof(ctl) ); + if ( r < 0 || r != sizeof(ctl) ) { + throw std::runtime_error( "can't write to pipe" ); + } + +// fd_info info = { fd_info::listener, 0, &p }; +// std::tr2::lock_guard<std::tr2::mutex> lk( cll ); +// closed_queue[_fd] = info; } void final( socks_processor_t& p ); @@ -200,15 +210,19 @@ sockmgr& operator =( const sockmgr& ) { return *this; } + int check_closed_listener( socks_processor_t* p ); #ifdef __USE_STLPORT_HASH typedef std::hash_map<sock_base::socket_type,fd_info> fd_container_type; + typedef std::hash_set<void *> listener_container_type; #endif #ifdef __USE_STD_HASH typedef __gnu_cxx::hash_map<sock_base::socket_type, fd_info> fd_container_type; + typedef __gnu_cxx::hash_set<void *> listener_container_type; #endif #if defined(__USE_STLPORT_TR1) || defined(__USE_STD_TR1) typedef std::tr1::unordered_map<sock_base::socket_type, fd_info> fd_container_type; + typedef std::tr1::unordered_set<void *> listener_container_type; #endif void io_worker(); @@ -223,6 +237,7 @@ fd_container_type descr; fd_container_type closed_queue; + listener_container_type listeners_final; std::tr2::mutex cll; std::tr2::mutex dll; }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
[complement-svn] SF.net SVN: complement: [1914]
branches/complement-sockios/explore/include/ sockios
From: <com...@us...> - 2008-06-26 05:45:31
|
Revision: 1914 http://complement.svn.sourceforge.net/complement/?rev=1914&view=rev Author: complement Date: 2008-06-25 22:45:30 -0700 (Wed, 25 Jun 2008) Log Message: ----------- Change condition processing for loop in connect_processor Fix check listener and related with listener connections. Not finished. Not work properly. Modified Paths: -------------- branches/complement-sockios/explore/include/sockios/socksrv.cc branches/complement-sockios/explore/include/sockios/socksrv.h branches/complement-sockios/explore/include/sockios/sp.cc branches/complement-sockios/explore/include/sockios/sp.h Modified: branches/complement-sockios/explore/include/sockios/socksrv.cc =================================================================== --- branches/complement-sockios/explore/include/sockios/socksrv.cc 2008-06-26 05:45:14 UTC (rev 1913) +++ branches/complement-sockios/explore/include/sockios/socksrv.cc 2008-06-26 05:45:30 UTC (rev 1914) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/18 22:25:39 yeti> +// -*- C++ -*- Time-stamp: <08/06/19 21:01:20 yeti> /* * Copyright (c) 2008 @@ -286,24 +286,27 @@ template <class Connect, class charT, class traits, class _Alloc, void (Connect::*C)( std::basic_sockstream<charT,traits,_Alloc>& )> bool connect_processor<Connect, charT, traits, _Alloc, C>::pop_ready( processor& p ) { - { - std::tr2::unique_lock<std::tr2::mutex> lk( rdlock ); + std::tr2::unique_lock<std::tr2::mutex> lk( rdlock ); - cnd.wait( lk, not_empty ); - p = ready_pool.front(); // it may contain p.c == 0, p.s == 0, if !in_work() - ready_pool.pop_front(); - // std::cerr << "pop 1\n"; + if ( !_in_work && ready_pool.empty() ) { + return false; + } + + cnd.wait( lk, not_empty ); + p = ready_pool.front(); // it may contain p.c == 0, p.s == 0, if !in_work() + ready_pool.pop_front(); + // std::cerr << "pop 1\n"; #if 0 - if ( p.c == 0 ) { // wake up, but _in_work may be still true here (in processor pipe?), - return false; // even I know that _in_work <- false before notification... - } // so, check twice + if ( p.c == 0 ) { // wake up, but _in_work may be still true here (in processor pipe?), + return false; // even I know that _in_work <- false before notification... + } // so, check twice #endif + + if ( _in_work ) { + return true; } - // std::cerr << "pop 2\n"; - - std::tr2::lock_guard<std::tr2::mutex> lk(inwlock); - return _in_work ? true : false; + return !ready_pool.empty(); // if !_in_work && ready_pool.empty() return false } template <class Connect, class charT, class traits, class _Alloc, void (Connect::*C)( std::basic_sockstream<charT,traits,_Alloc>& )> @@ -315,16 +318,21 @@ while ( pop_ready( p ) ) { // std::cerr << "worker 1\n"; - (p.c->*C)( *p.s ); - // std::cerr << "worker 2\n"; - if ( p.s->rdbuf()->in_avail() ) { - std::tr2::lock_guard<std::tr2::mutex> lk( rdlock ); - ready_pool.push_back( p ); + if ( p.c != 0 ) { + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + (p.c->*C)( *p.s ); + // std::cerr << "worker 2\n"; + if ( p.s->rdbuf()->in_avail() ) { + std::tr2::lock_guard<std::tr2::mutex> lk( rdlock ); + ready_pool.push_back( p ); + } else { + std::tr2::lock_guard<std::tr2::mutex> lk( wklock ); + worker_pool[p.s->rdbuf()->fd()] = p; + } + // std::cerr << "worker 3\n"; } else { - std::tr2::lock_guard<std::tr2::mutex> lk( wklock ); - worker_pool[p.s->rdbuf()->fd()] = p; + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; } - // std::cerr << "worker 3\n"; } } @@ -332,13 +340,14 @@ template <class Connect, class charT, class traits, class _Alloc, void (Connect::*C)( std::basic_sockstream<charT,traits,_Alloc>& )> void connect_processor<Connect, charT, traits, _Alloc, C>::stop() { - std::tr2::lock_guard<std::tr2::mutex> lk(inwlock); + std::tr2::lock_guard<std::tr2::mutex> lk2( rdlock ); + _in_work = false; // <--- set before cnd.notify_one(); (below in this func) - - std::tr2::lock_guard<std::tr2::mutex> lk2( rdlock ); - ready_pool.push_back( processor() ); // make ready_pool not empty - // std::cerr << "=== " << ready_pool.size() << std::endl; - cnd.notify_one(); + if ( ready_pool.empty() ) { + ready_pool.push_back( processor() ); // make ready_pool not empty + cnd.notify_one(); + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + } std::cerr << __FILE__ << ":" << __LINE__ << std::endl; } Modified: branches/complement-sockios/explore/include/sockios/socksrv.h =================================================================== --- branches/complement-sockios/explore/include/sockios/socksrv.h 2008-06-26 05:45:14 UTC (rev 1913) +++ branches/complement-sockios/explore/include/sockios/socksrv.h 2008-06-26 05:45:30 UTC (rev 1914) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/18 22:25:25 yeti> +// -*- C++ -*- Time-stamp: <08/06/19 20:14:01 yeti> /* * Copyright (c) 2008 @@ -328,7 +328,6 @@ std::tr2::mutex wklock; std::tr2::mutex rdlock; std::tr2::condition_variable cnd; - std::tr2::mutex inwlock; std::tr2::condition_variable cnd_inwk; std::tr2::thread ploop; Modified: branches/complement-sockios/explore/include/sockios/sp.cc =================================================================== --- branches/complement-sockios/explore/include/sockios/sp.cc 2008-06-26 05:45:14 UTC (rev 1913) +++ branches/complement-sockios/explore/include/sockios/sp.cc 2008-06-26 05:45:30 UTC (rev 1914) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/18 22:37:15 yeti> +// -*- C++ -*- Time-stamp: <08/06/19 21:28:42 yeti> /* * Copyright (c) 2008 @@ -143,8 +143,9 @@ { int lfd = check_closed_listener( reinterpret_cast<socks_processor_t*>(_ctl.data.ptr) ); if ( lfd != -1 ) { - descr.erase( -1 ); + descr.erase( lfd ); } + dump_descr(); } break; case rqstop: @@ -175,10 +176,19 @@ listeners_final.insert(static_cast<void *>(ifd->second.p)); std::cerr << __FILE__ << ":" << __LINE__ << std::endl; - check_closed_listener( ifd->second.p ); - + + socks_processor_t* p = ifd->second.p; + descr.erase( ifd ); + int lfd = check_closed_listener( p ); + + if ( lfd != -1 ) { + descr.erase( lfd ); + } + + dump_descr(); + return; } @@ -221,13 +231,15 @@ std::cerr << __FILE__ << ":" << __LINE__ << std::endl; - listeners_final.insert(static_cast<void *>(ifd->second.p)); + socks_processor_t* p = ifd->second.p; + listeners_final.insert( static_cast<void *>(p) ); - check_closed_listener( ifd->second.p ); - descr.erase( ifd ); + check_closed_listener( p ); + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + dump_descr(); } else { // back to listen errno = 0; epoll_event xev; @@ -289,10 +301,17 @@ if ( info.p != 0 ) { // ... but controlled by processor (*info.p)( ifd->first, typename socks_processor_t::adopt_close_t() ); - check_closed_listener( info.p ); + socks_processor_t* p = info.p; + descr.erase( ifd ); + int lfd = check_closed_listener( p ); + if ( lfd != -1 ) { + descr.erase( lfd ); + } + } else { + descr.erase( ifd ); } - descr.erase( ifd ); std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + dump_descr(); return; } @@ -393,13 +412,23 @@ std::cerr << __FILE__ << ":" << __LINE__ << std::endl; (*info.p)( ifd->first, typename socks_processor_t::adopt_close_t() ); std::cerr << __FILE__ << ":" << __LINE__ << std::endl; - check_closed_listener( info.p ); + + socks_processor_t* p = info.p; + + closed_queue.erase( ev.data.fd ); + descr.erase( ifd ); + + int lfd = check_closed_listener( p ); + if ( lfd != -1 ) { + descr.erase( lfd ); + } } else { std::cerr << __FILE__ << ":" << __LINE__ << std::endl; b->close(); + closed_queue.erase( ev.data.fd ); + descr.erase( ifd ); } - closed_queue.erase( ev.data.fd ); - descr.erase( ifd ); + dump_descr(); } // if ( ev.events & EPOLLHUP ) { // std::cerr << "Poll HUP" << std::endl; @@ -486,7 +515,23 @@ return myfd; } +template<class charT, class traits, class _Alloc> +void sockmgr<charT,traits,_Alloc>::dump_descr() +{ + for ( typename fd_container_type::iterator i = descr.begin(); i != descr.end(); ++i ) { + std::cerr << i->first + << std::hex + << i->second.flags + << " " + << (void*)i->second.b + << " " + << (void*)i->second.p + << std::dec + << endl; + } +} + } // namespace detail } // namespace std Modified: branches/complement-sockios/explore/include/sockios/sp.h =================================================================== --- branches/complement-sockios/explore/include/sockios/sp.h 2008-06-26 05:45:14 UTC (rev 1913) +++ branches/complement-sockios/explore/include/sockios/sp.h 2008-06-26 05:45:30 UTC (rev 1914) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/18 22:36:24 yeti> +// -*- C++ -*- Time-stamp: <08/06/19 20:30:48 yeti> /* * Copyright (c) 2008 @@ -211,6 +211,7 @@ { return *this; } int check_closed_listener( socks_processor_t* p ); + void dump_descr(); #ifdef __USE_STLPORT_HASH typedef std::hash_map<sock_base::socket_type,fd_info> fd_container_type; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
[complement-svn] SF.net SVN: complement: [1915]
branches/complement-sockios/explore/include/ sockios
From: <com...@us...> - 2008-06-26 05:45:46
|
Revision: 1915 http://complement.svn.sourceforge.net/complement/?rev=1915&view=rev Author: complement Date: 2008-06-25 22:45:45 -0700 (Wed, 25 Jun 2008) Log Message: ----------- worker's loop may run after signal: fix end-of-loop var The body of loop may be reached after I send signal and set _in_work to false, so it may turn on _in_work to true again. Fixed. Modified Paths: -------------- branches/complement-sockios/explore/include/sockios/socksrv.cc branches/complement-sockios/explore/include/sockios/socksrv.h branches/complement-sockios/explore/include/sockios/sockstream Modified: branches/complement-sockios/explore/include/sockios/socksrv.cc =================================================================== --- branches/complement-sockios/explore/include/sockios/socksrv.cc 2008-06-26 05:45:30 UTC (rev 1914) +++ branches/complement-sockios/explore/include/sockios/socksrv.cc 2008-06-26 05:45:45 UTC (rev 1915) @@ -295,7 +295,6 @@ cnd.wait( lk, not_empty ); p = ready_pool.front(); // it may contain p.c == 0, p.s == 0, if !in_work() ready_pool.pop_front(); - // std::cerr << "pop 1\n"; #if 0 if ( p.c == 0 ) { // wake up, but _in_work may be still true here (in processor pipe?), return false; // even I know that _in_work <- false before notification... @@ -312,16 +311,12 @@ template <class Connect, class charT, class traits, class _Alloc, void (Connect::*C)( std::basic_sockstream<charT,traits,_Alloc>& )> void connect_processor<Connect, charT, traits, _Alloc, C>::worker() { - _in_work = true; - processor p; while ( pop_ready( p ) ) { - // std::cerr << "worker 1\n"; if ( p.c != 0 ) { std::cerr << __FILE__ << ":" << __LINE__ << std::endl; (p.c->*C)( *p.s ); - // std::cerr << "worker 2\n"; if ( p.s->rdbuf()->in_avail() ) { std::tr2::lock_guard<std::tr2::mutex> lk( rdlock ); ready_pool.push_back( p ); @@ -329,7 +324,6 @@ std::tr2::lock_guard<std::tr2::mutex> lk( wklock ); worker_pool[p.s->rdbuf()->fd()] = p; } - // std::cerr << "worker 3\n"; } else { std::cerr << __FILE__ << ":" << __LINE__ << std::endl; } @@ -346,9 +340,7 @@ if ( ready_pool.empty() ) { ready_pool.push_back( processor() ); // make ready_pool not empty cnd.notify_one(); - std::cerr << __FILE__ << ":" << __LINE__ << std::endl; } - std::cerr << __FILE__ << ":" << __LINE__ << std::endl; } } // namespace std Modified: branches/complement-sockios/explore/include/sockios/socksrv.h =================================================================== --- branches/complement-sockios/explore/include/sockios/socksrv.h 2008-06-26 05:45:30 UTC (rev 1914) +++ branches/complement-sockios/explore/include/sockios/socksrv.h 2008-06-26 05:45:45 UTC (rev 1915) @@ -180,14 +180,14 @@ public: connect_processor() : not_empty( *this ), - _in_work( false ), + _in_work( true ), ploop( loop, this ) { new( Init_buf ) Init(); /* base_t::_real_stop = &connect_processor::_xstop; */ } explicit connect_processor( int port ) : base_t( port, sock_base::sock_stream ), not_empty( *this ), - _in_work( false ), + _in_work( true ), ploop( loop, this ) { new( Init_buf ) Init(); /* base_t::_real_stop = &connect_processor::_xstop; */ } Modified: branches/complement-sockios/explore/include/sockios/sockstream =================================================================== --- branches/complement-sockios/explore/include/sockios/sockstream 2008-06-26 05:45:30 UTC (rev 1914) +++ branches/complement-sockios/explore/include/sockios/sockstream 2008-06-26 05:45:45 UTC (rev 1915) @@ -451,7 +451,6 @@ std::cerr << __FILE__ << ":" << __LINE__ << " " << basic_socket_t::_fd << std::endl; close(); _M_deallocate_block(); - std::cerr << __FILE__ << ":" << __LINE__ << " " << basic_socket_t::_fd << std::endl; } sockbuf_type *open( const char *hostname, int port, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
[complement-svn] SF.net SVN: complement: [1917]
branches/complement-sockios/explore/include/ sockios
From: <com...@us...> - 2008-06-26 05:46:18
|
Revision: 1917 http://complement.svn.sourceforge.net/complement/?rev=1917&view=rev Author: complement Date: 2008-06-25 22:46:17 -0700 (Wed, 25 Jun 2008) Log Message: ----------- process EPOLLHUP for listener; ctors for fd_info When binded socket (i.e. listener) see EPOLLHUP, looks like I should treat it as close; I will do close procedure on EPOLLERR too. Modified Paths: -------------- branches/complement-sockios/explore/include/sockios/sp.cc branches/complement-sockios/explore/include/sockios/sp.h Modified: branches/complement-sockios/explore/include/sockios/sp.cc =================================================================== --- branches/complement-sockios/explore/include/sockios/sp.cc 2008-06-26 05:46:02 UTC (rev 1916) +++ branches/complement-sockios/explore/include/sockios/sp.cc 2008-06-26 05:46:17 UTC (rev 1917) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/19 21:28:42 yeti> +// -*- C++ -*- Time-stamp: <08/06/25 12:00:59 ptr> /* * Copyright (c) 2008 @@ -117,8 +117,7 @@ // std::cerr << "xxx " << errno << " " << std::tr2::getpid() << std::endl; throw std::runtime_error( "can't establish nonblock mode on listener" ); } - fd_info new_info = { fd_info::listener, 0, static_cast<socks_processor_t*>(_ctl.data.ptr) }; - descr[ev_add.data.fd] = new_info; + descr[ev_add.data.fd] = fd_info( static_cast<socks_processor_t*>(_ctl.data.ptr) ); if ( epoll_ctl( efd, EPOLL_CTL_ADD, ev_add.data.fd, &ev_add ) < 0 ) { descr.erase( ev_add.data.fd ); // throw system_error @@ -129,8 +128,7 @@ ev_add.events = EPOLLIN | EPOLLRDHUP | EPOLLERR | EPOLLHUP | EPOLLET | EPOLLONESHOT; ev_add.data.fd = static_cast<sockbuf_t*>(_ctl.data.ptr)->fd(); if ( ev_add.data.fd >= 0 ) { - fd_info new_info = { 0, static_cast<sockbuf_t*>(_ctl.data.ptr), 0 }; - descr[ev_add.data.fd] = new_info; + descr[ev_add.data.fd] = fd_info( static_cast<sockbuf_t*>(_ctl.data.ptr) ); if ( epoll_ctl( efd, EPOLL_CTL_ADD, ev_add.data.fd, &ev_add ) < 0 ) { descr.erase( ev_add.data.fd ); // throw system_error @@ -159,7 +157,7 @@ void sockmgr<charT,traits,_Alloc>::process_listener( epoll_event& ev, typename sockmgr<charT,traits,_Alloc>::fd_container_type::iterator ifd ) { std::cerr << __FILE__ << ":" << __LINE__ << std::endl; - if ( ev.events & EPOLLRDHUP ) { + if ( ev.events & (EPOLLRDHUP | EPOLLHUP | EPOLLERR) ) { if ( epoll_ctl( efd, EPOLL_CTL_DEL, ifd->first, 0 ) < 0 ) { // throw system_error } @@ -193,7 +191,7 @@ } if ( (ev.events & EPOLLIN) == 0 ) { - std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + std::cerr << __FILE__ << ":" << __LINE__ << " " << std::hex << ev.events << std::dec << std::endl; return; // I don't know what to do this case... } @@ -273,8 +271,7 @@ sockbuf_t* b = (*info.p)( fd, addr ); std::cerr << __FILE__ << ":" << __LINE__ << std::endl; - fd_info new_info = { 0, b, info.p }; - descr[fd] = new_info; + descr[fd] = fd_info( b, info.p ); } catch ( const std::bad_alloc& ) { // nothing @@ -451,39 +448,6 @@ } template<class charT, class traits, class _Alloc> -void sockmgr<charT,traits,_Alloc>::final( sockmgr<charT,traits,_Alloc>::socks_processor_t& p ) -{ -#if 0 - std::tr2::lock_guard<std::tr2::mutex> lk_descr( dll ); - - for ( typename fd_container_type::iterator ifd = descr.begin(); ifd != descr.end(); ) { - if ( (ifd->second.flags & fd_info::owner) && (ifd->second.p == &p) ) { - std::cerr << __FILE__ << ":" << __LINE__ << " " << (void*)&p << " " << (void*)ifd->second.b << std::endl; - p( ifd->first, typename socks_processor_t::adopt_close_t() ); - std::cerr << __FILE__ << ":" << __LINE__ << " " << (void*)&p << " " << (void*)ifd->second.b << std::endl; - if ( epoll_ctl( efd, EPOLL_CTL_DEL, ifd->first, 0 ) < 0 ) { - // throw system_error - } - descr.erase( ifd++ ); - } else { - ++ifd; - } - } - - std::tr2::lock_guard<std::tr2::mutex> lk( cll ); - - // I can't use closed_queue.erase( p.fd() ) here: fd is -1 already - for ( typename fd_container_type::iterator closed_ifd = closed_queue.begin(); closed_ifd != closed_queue.end(); ) { - if ( closed_ifd->second.p == &p ) { - closed_queue.erase( closed_ifd++ ); - } else { - ++closed_ifd; - } - } -#endif -} - -template<class charT, class traits, class _Alloc> int sockmgr<charT,traits,_Alloc>::check_closed_listener( socks_processor_t* p ) { int myfd = -1; @@ -519,7 +483,7 @@ void sockmgr<charT,traits,_Alloc>::dump_descr() { for ( typename fd_container_type::iterator i = descr.begin(); i != descr.end(); ++i ) { - std::cerr << i->first + std::cerr << i->first << " " << std::hex << i->second.flags << " " Modified: branches/complement-sockios/explore/include/sockios/sp.h =================================================================== --- branches/complement-sockios/explore/include/sockios/sp.h 2008-06-26 05:46:02 UTC (rev 1916) +++ branches/complement-sockios/explore/include/sockios/sp.h 2008-06-26 05:46:17 UTC (rev 1917) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/19 20:30:48 yeti> +// -*- C++ -*- Time-stamp: <08/06/25 11:54:39 ptr> /* * Copyright (c) 2008 @@ -91,6 +91,42 @@ level_triggered = 0x2 }; + fd_info() : + flags(0U), + b(0), + p(0) + { } + + fd_info( unsigned f, sockbuf_t* buf, socks_processor_t* proc ) : + flags(f), + b(buf), + p(proc) + { } + + fd_info( sockbuf_t* buf, socks_processor_t* proc ) : + flags(0U), + b(buf), + p(proc) + { } + + fd_info( sockbuf_t* buf ) : + flags(0U), + b(buf), + p(0) + { } + + fd_info( socks_processor_t* proc ) : + flags(listener), + b(0), + p(proc) + { } + + fd_info( const fd_info& info ) : + flags( info.flags ), + b( info.b ), + p( info.p ) + { } + unsigned flags; sockbuf_t* b; socks_processor_t* p; @@ -195,13 +231,11 @@ // closed_queue[_fd] = info; } - void final( socks_processor_t& p ); - void exit_notify( sockbuf_t* b, sock_base::socket_type fd ) { - fd_info info = { 0, 0, 0 }; + // fd_info info = { 0, 0, 0 }; std::tr2::lock_guard<std::tr2::mutex> lk( cll ); - closed_queue[fd] = info; + closed_queue[fd] = fd_info(); } private: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |