[complement-svn] SF.net SVN: complement: [1910] branches/complement-sockios/explore
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2008-06-26 05:44:11
|
Revision: 1910 http://complement.svn.sourceforge.net/complement/?rev=1910&view=rev Author: complement Date: 2008-06-25 22:44:09 -0700 (Wed, 25 Jun 2008) Log Message: ----------- Problem with call after death looks found; deadlock still here. Looks like I need to block sockbuf destruction, when in processing of sockets: otherwise I need more checks in closed_queue, and still lock should be here; now lock added, but ones may lead to deadlock. Modified Paths: -------------- branches/complement-sockios/explore/include/sockios/socksrv.h branches/complement-sockios/explore/include/sockios/sp.cc branches/complement-sockios/explore/lib/sockios/ut/sockios2_test.cc Modified: branches/complement-sockios/explore/include/sockios/socksrv.h =================================================================== --- branches/complement-sockios/explore/include/sockios/socksrv.h 2008-06-26 05:43:48 UTC (rev 1909) +++ branches/complement-sockios/explore/include/sockios/socksrv.h 2008-06-26 05:44:09 UTC (rev 1910) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/16 22:07:54 yeti> +// -*- C++ -*- Time-stamp: <08/06/17 09:17:05 ptr> /* * Copyright (c) 2008 @@ -87,9 +87,18 @@ virtual void close(); +#if 0 virtual sockbuf_t* operator ()( sock_base::socket_type fd, const sockaddr& ) = 0; virtual void operator ()( sock_base::socket_type fd, const adopt_close_t& ) = 0; virtual void operator ()( sock_base::socket_type fd ) = 0; +#else + virtual sockbuf_t* operator ()( sock_base::socket_type fd, const sockaddr& ) + { abort(); return 0; } + virtual void operator ()( sock_base::socket_type fd, const adopt_close_t& ) + { abort(); } + virtual void operator ()( sock_base::socket_type fd ) + { abort(); } +#endif private: sock_processor_base( const sock_processor_base& ); Modified: branches/complement-sockios/explore/include/sockios/sp.cc =================================================================== --- branches/complement-sockios/explore/include/sockios/sp.cc 2008-06-26 05:43:48 UTC (rev 1909) +++ branches/complement-sockios/explore/include/sockios/sp.cc 2008-06-26 05:44:09 UTC (rev 1910) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/16 20:24:51 yeti> +// -*- C++ -*- Time-stamp: <08/06/17 10:35:40 ptr> /* * Copyright (c) 2008 @@ -34,6 +34,7 @@ if ( n < 0 ) { if ( errno == EINTR ) { + errno = 0; continue; } // throw system_error @@ -186,7 +187,7 @@ int fd = accept( ev.data.fd, &addr, &sz ); if ( fd < 0 ) { // std::cerr << "Accept, listener # " << ev.data.fd << ", errno " << errno << std::endl; - // std::cerr << __FILE__ << ":" << __LINE__ << " " << std::tr2::getpid() << std::endl; + std::cerr << __FILE__ << ":" << __LINE__ /* << " " << std::tr2::getpid() */ << std::endl; if ( (errno == EINTR) || (errno == ECONNABORTED) /* || (errno == ERESTARTSYS) */ ) { errno = 0; continue; @@ -194,6 +195,7 @@ if ( !(errno == EAGAIN /* || errno == EWOULDBLOCK */ ) ) { // EWOULDBLOCK == EAGAIN // std::cerr << "Accept, listener " << ev.data.fd << ", errno " << errno << std::endl; if ( epoll_ctl( efd, EPOLL_CTL_DEL, ifd->first, 0 ) < 0 ) { + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; // throw system_error } @@ -216,21 +218,28 @@ closed_queue.erase( closed_ifd ); } // throw system_error ? + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; } else { // back to listen errno = 0; epoll_event xev; xev.events = EPOLLIN | EPOLLRDHUP | EPOLLERR | EPOLLHUP | EPOLLET | EPOLLONESHOT; xev.data.fd = ev.data.fd; - epoll_ctl( efd, EPOLL_CTL_MOD, ev.data.fd, &xev ); + if ( epoll_ctl( efd, EPOLL_CTL_MOD, ev.data.fd, &xev ) < 0 ) { + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + } } + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; return; } if ( fcntl( fd, F_SETFL, fcntl( fd, F_GETFL ) | O_NONBLOCK ) != 0 ) { + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; throw std::runtime_error( "can't establish nonblock mode" ); } try { + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; sockbuf_t* b = (*info.p)( fd, addr ); + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; epoll_event ev_add; ev_add.events = EPOLLIN | EPOLLRDHUP | EPOLLERR | EPOLLHUP | EPOLLET | EPOLLONESHOT; @@ -258,7 +267,19 @@ { fd_info& info = ifd->second; + 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_queue.erase( closed_ifd ); + if ( epoll_ctl( efd, EPOLL_CTL_DEL, ifd->first, 0 ) < 0 ) { + // throw system_error + } + descr.erase( ifd ); + return; + } + if ( ev.events & EPOLLIN ) { +#if 0 if ( (info.flags & fd_info::owner) == 0 ) { /* marginal case: sockmgr isn't owner (registerd via push(), @@ -278,10 +299,12 @@ return; } } - sockbuf_t* b = /* (info.flags & fd_info::buffer != 0) ? info.s.b : info.s.s->rdbuf() */ info.b; +#endif + + sockbuf_t* b = info.b; errno = 0; - if ( b == 0 ) { // marginal case: sockbuf wasn't created by processor - if ( info.p != 0 ) { + if ( b == 0 ) { // marginal case: sockbuf wasn't created by processor... + if ( info.p != 0 ) { // ... but controlled by processor (*info.p)( ifd->first, typename socks_processor_t::adopt_close_t() ); } descr.erase( ifd ); @@ -367,7 +390,7 @@ if ( info.p != 0 ) { (*info.p)( ifd->first, typename socks_processor_t::adopt_close_t() ); - } + } /* else */ if ( (info.flags & fd_info::buffer) != 0 ) { info.b->close(); } Modified: branches/complement-sockios/explore/lib/sockios/ut/sockios2_test.cc =================================================================== --- branches/complement-sockios/explore/lib/sockios/ut/sockios2_test.cc 2008-06-26 05:43:48 UTC (rev 1909) +++ branches/complement-sockios/explore/lib/sockios/ut/sockios2_test.cc 2008-06-26 05:44:09 UTC (rev 1910) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/16 20:35:30 yeti> +// -*- C++ -*- Time-stamp: <08/06/17 09:11:57 ptr> /* * @@ -620,16 +620,16 @@ int n = 1; - // cerr << "align 3\n"; + cerr << "align 3\n"; bb->wait(); // <-- align 3 - // cerr << "align 3 pass\n"; + cerr << "align 3 pass\n"; s.write( (const char *)&n, sizeof( int ) ).flush(); EXAM_CHECK_ASYNC( s.good() ); } ~interrupted_writer() - { /* cerr << "~~\n"; */ } + { cerr << "~~\n"; } void connect( sockstream& s ) { } @@ -639,11 +639,12 @@ sockstream s( "localhost", 2008 ); int buff = 0; - // cerr << "align 2" << endl; + cerr << "align 2" << endl; b->wait(); // <-- align 2 - // cerr << "align pass" << endl; + cerr << "align 2 pass" << endl; EXAM_CHECK_ASYNC( s.read( (char *)&buff, sizeof(int) ).good() ); // <---- key line + cerr << "read pass" << endl; EXAM_CHECK_ASYNC( buff == 1 ); } @@ -675,12 +676,12 @@ bb.wait(); // <-- align 2 - // cerr << "system" << endl; + cerr << "system" << endl; system( "echo > /dev/null" ); // <------ key line - // cerr << "after system" << endl; + cerr << "after system" << endl; bnew.wait(); // <-- align 3 - // cerr << "after align 3" << endl; + cerr << "after align 3" << endl; t.join(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |