[complement-svn] SF.net SVN: complement: [1837] branches/complement-sockios/explore
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2008-03-27 12:20:02
|
Revision: 1837 http://complement.svn.sourceforge.net/complement/?rev=1837&view=rev Author: complement Date: 2008-03-27 05:19:58 -0700 (Thu, 27 Mar 2008) Log Message: ----------- read0 test, under debugging Modified Paths: -------------- branches/complement-sockios/explore/include/sockios/sockstream2 branches/complement-sockios/explore/include/sockios/sp.h branches/complement-sockios/explore/lib/mt/ut/mt_test_wg21.h branches/complement-sockios/explore/lib/sockios/ut/names.cc branches/complement-sockios/explore/lib/sockios/ut/sockios2_test.cc branches/complement-sockios/explore/lib/sockios/ut/sockios2_test.h branches/complement-sockios/explore/lib/sockios/ut/sockios_test_suite.cc Modified: branches/complement-sockios/explore/include/sockios/sockstream2 =================================================================== --- branches/complement-sockios/explore/include/sockios/sockstream2 2008-03-26 11:45:54 UTC (rev 1836) +++ branches/complement-sockios/explore/include/sockios/sockstream2 2008-03-27 12:19:58 UTC (rev 1837) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/03/26 09:54:59 ptr> +// -*- C++ -*- Time-stamp: <08/03/27 08:52:14 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005-2008 @@ -316,6 +316,7 @@ std::tr2::lock_guard<std::tr2::mutex> lk( _init_lock ); if ( --_count == 0 ) { delete basic_socket<charT,traits,_Alloc>::mgr; + basic_socket<charT,traits,_Alloc>::mgr = 0; } } } @@ -344,7 +345,7 @@ char basic_socket<charT,traits,_Alloc>::Init_buf[128]; template <class charT, class traits, class _Alloc> -detail::sockmgr<charT,traits,_Alloc>* basic_socket<charT,traits,_Alloc>::mgr; +detail::sockmgr<charT,traits,_Alloc>* basic_socket<charT,traits,_Alloc>::mgr = 0; #ifdef STLPORT _STLP_END_NAMESPACE Modified: branches/complement-sockios/explore/include/sockios/sp.h =================================================================== --- branches/complement-sockios/explore/include/sockios/sp.h 2008-03-26 11:45:54 UTC (rev 1836) +++ branches/complement-sockios/explore/include/sockios/sp.h 2008-03-27 12:19:58 UTC (rev 1837) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/03/26 09:55:19 ptr> +// -*- C++ -*- Time-stamp: <08/03/27 09:28:41 ptr> /* * Copyright (c) 2008 @@ -483,7 +483,7 @@ cnd.notify_one(); } else { std::tr2::lock_guard<std::tr2::mutex> lk( wklock ); - worker_pool[&s] = c; + worker_pool.insert( std::make_pair( &s, c ) ); } } @@ -768,7 +768,7 @@ // throw system_error // std::cerr << "Read pipe\n"; } else if ( r == 0 ) { - // std::cerr << "Read pipe 0\n"; + std::cerr << "Read pipe 0\n"; return; } @@ -845,6 +845,7 @@ for ( ; ; ) { int fd = accept( ev[i].data.fd, &addr, &sz ); if ( fd < 0 ) { + std::cerr << "Accept, listener # " << ev[i].data.fd << ", errno " << errno << std::endl; if ( (errno == EINTR) || (errno == ECONNABORTED) /* || (errno == ERESTARTSYS) */ ) { continue; } @@ -870,13 +871,14 @@ descr[fd] = new_info; if ( epoll_ctl( efd, EPOLL_CTL_ADD, fd, &ev_add ) < 0 ) { - // std::cerr << "Accept, add " << fd << ", errno " << errno << std::endl; + std::cerr << "Accept, add " << fd << ", errno " << errno << std::endl; descr.erase( fd ); // throw system_error } + std::cerr << "adopt_new_t()\n"; (*info.p)( *s, typename socks_processor_t::adopt_new_t() ); } else { - // std::cerr << "Accept, delete " << fd << std::endl; + std::cerr << "Accept, delete " << fd << std::endl; delete s; } } @@ -931,9 +933,11 @@ } break; } + std::cerr << "ptr " << (void *)b->egptr() << ", " << errno << std::endl; long offset = read( ev[i].data.fd, b->egptr(), sizeof(charT) * (b->_ebuf - b->egptr()) ); + std::cerr << "offset " << offset << ", " << errno << std::endl; if ( offset < 0 ) { - if ( errno == EAGAIN ) { + if ( (errno == EAGAIN) || (errno == EINTR) ) { errno = 0; epoll_event xev; xev.events = EPOLLIN | EPOLLRDHUP | EPOLLERR | EPOLLHUP | EPOLLET | EPOLLONESHOT; @@ -941,8 +945,19 @@ epoll_ctl( efd, EPOLL_CTL_MOD, ev[i].data.fd, &xev ); break; } else { - // process error - std::cerr << "not listener, other " << ev[i].data.fd << std::hex << ev[i].events << std::dec << errno << std::endl; + switch ( errno ) { + // case EINTR: // read was interrupted + // continue; + // break; + case EFAULT: // Bad address + case ECONNRESET: // Connection reset by peer + ev[i].events |= EPOLLRDHUP; // will be processed below + break; + default: + std::cerr << "not listener, other " << ev[i].data.fd << std::hex << ev[i].events << std::dec << " : " << errno << std::endl; + break; + } + break; } } else if ( offset > 0 ) { offset /= sizeof(charT); // if offset % sizeof(charT) != 0, rest will be lost! @@ -964,14 +979,16 @@ (*info.p)( *info.s.s, typename socks_processor_t::adopt_data_t() ); } } else { - // std::cerr << "K " << ev[i].data.fd << ", " << errno << std::endl; + std::cerr << "K " << ev[i].data.fd << ", " << errno << std::endl; // EPOLLRDHUP may be missed in kernel, but offset 0 is the same ev[i].events |= EPOLLRDHUP; // will be processed below break; } } + } else { + std::cerr << "Q\n"; } - if ( ev[i].events & EPOLLRDHUP ) { + if ( (ev[i].events & EPOLLRDHUP) || (ev[i].events & EPOLLHUP) || (ev[i].events & EPOLLERR) ) { // std::cerr << "Poll EPOLLRDHUP " << ev[i].data.fd << ", " << errno << std::endl; if ( epoll_ctl( efd, EPOLL_CTL_DEL, ifd->first, 0 ) < 0 ) { // throw system_error @@ -992,15 +1009,12 @@ } descr.erase( ifd ); } - if ( ev[i].events & EPOLLHUP ) { - std::cerr << "Poll HUP" << std::endl; - } - if ( ev[i].events & EPOLLERR ) { - std::cerr << "Poll ERR" << std::endl; - } - if ( ev[i].events & EPOLLERR ) { - std::cerr << "Poll ERR" << std::endl; - } + // if ( ev[i].events & EPOLLHUP ) { + // std::cerr << "Poll HUP" << std::endl; + // } + // if ( ev[i].events & EPOLLERR ) { + // std::cerr << "Poll ERR" << std::endl; + // } if ( ev[i].events & EPOLLPRI ) { std::cerr << "Poll PRI" << std::endl; } Modified: branches/complement-sockios/explore/lib/mt/ut/mt_test_wg21.h =================================================================== --- branches/complement-sockios/explore/lib/mt/ut/mt_test_wg21.h 2008-03-26 11:45:54 UTC (rev 1836) +++ branches/complement-sockios/explore/lib/mt/ut/mt_test_wg21.h 2008-03-27 12:19:58 UTC (rev 1837) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/02/25 12:12:20 ptr> +// -*- C++ -*- Time-stamp: <08/03/26 23:56:53 ptr> /* * Copyright (c) 2006-2008 Modified: branches/complement-sockios/explore/lib/sockios/ut/names.cc =================================================================== --- branches/complement-sockios/explore/lib/sockios/ut/names.cc 2008-03-26 11:45:54 UTC (rev 1836) +++ branches/complement-sockios/explore/lib/sockios/ut/names.cc 2008-03-27 12:19:58 UTC (rev 1837) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/02/07 10:28:34 ptr> +// -*- C++ -*- Time-stamp: <08/03/27 11:04:23 ptr> /* * @@ -13,13 +13,10 @@ #include <exam/suite.h> -#include <sockios/sockstream> -#include <sockios/sockmgr.h> +#include <sockios/netinfo.h> #include <list> -#include <arpa/inet.h> - using namespace std; /* ************************************************************ */ Modified: branches/complement-sockios/explore/lib/sockios/ut/sockios2_test.cc =================================================================== --- branches/complement-sockios/explore/lib/sockios/ut/sockios2_test.cc 2008-03-26 11:45:54 UTC (rev 1836) +++ branches/complement-sockios/explore/lib/sockios/ut/sockios2_test.cc 2008-03-27 12:19:58 UTC (rev 1837) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/03/26 11:48:40 ptr> +// -*- C++ -*- Time-stamp: <08/03/27 07:22:24 ptr> /* * @@ -444,3 +444,219 @@ return EXAM_RESULT; } + +class stream_reader +{ + public: + stream_reader( sockstream2& ) + { } + + ~stream_reader() + { } + + void connect( sockstream2& s ) + { + char buf[1024]; + + s.read( buf, 1024 ); + s.write( buf, 1024 ); + s.flush(); + } + + static void load_generator( barrier* b ) + { + sockstream2 s( "localhost", 2008 ); + + char buf[1024]; + + fill( buf, buf + 1024, 0 ); + + b->wait(); + + while( true ) { + s.write( buf, 1024 ); + s.flush(); + + s.read( buf, 1024 ); + this_thread::yield(); + } + } + +}; + +int EXAM_IMPL(sockios2_test::srv_sigpipe) +{ + const char fname[] = "/tmp/sockios2_test.shm"; + try { + xmt::shm_alloc<0> seg; + seg.allocate( fname, 4096, xmt::shm_base::create | xmt::shm_base::exclusive, 0660 ); + + xmt::allocator_shm<barrier_ip,0> shm; + barrier_ip& b = *new ( shm.allocate( 1 ) ) barrier_ip(); + try { + this_thread::fork(); + + b.wait(); + /* + * This process will be killed, + * so I don't care about safe termination. + */ + + const int b_count = 10; + barrier bb( b_count ); + + thread* th1 = new thread( stream_reader::load_generator, &bb ); + + for ( int i = 0; i < (b_count - 1); ++i ) { + new thread( stream_reader::load_generator, &bb ); + } + + this_thread::sleep( milliseconds( 100 ) ); + + b.wait(); + + th1->join(); // Will be interrupted! + + exit( 0 ); + } + catch ( std::tr2::fork_in_parent& child ) { + connect_processor<stream_reader> r( 2008 ); + + EXAM_CHECK( r.good() ); + EXAM_CHECK( r.is_open() ); + + b.wait(); + b.wait(); + + kill( child.pid(), SIGTERM ); + + int stat = -1; + EXAM_CHECK( waitpid( child.pid(), &stat, 0 ) == child.pid() ); + if ( WIFEXITED(stat) ) { + // EXAM_CHECK( WEXITSTATUS(stat) == 0 ); + EXAM_ERROR( "child should be interrupted" ); + } else { + EXAM_MESSAGE( "child interrupted" ); + } + + EXAM_CHECK( r.good() ); + EXAM_CHECK( r.is_open() ); + + } + shm.deallocate( &b ); + seg.deallocate(); + unlink( fname ); + } + catch ( xmt::shm_bad_alloc& err ) { + EXAM_ERROR( err.what() ); + } + + return EXAM_RESULT; +} + + +class interrupted_writer +{ + public: + interrupted_writer( sockstream2& s ) + { + EXAM_CHECK_ASYNC( s.good() ); + + int n = 1; + + cerr << "align 3\n"; + bb->wait(); // <-- align 3 + + cerr << "align 3 pass\n"; + s.write( (const char *)&n, sizeof( int ) ).flush(); + EXAM_CHECK_ASYNC( s.good() ); + } + + ~interrupted_writer() + { cerr << "~~\n"; } + + void connect( sockstream2& s ) + { } + + static void read_generator( barrier* b ) + { + sockstream2 s( "localhost", 2008 ); + + int buff = 0; + cerr << "align 2" << endl; + b->wait(); // <-- align 2 + cerr << "align pass" << endl; + + EXAM_CHECK_ASYNC( s.read( (char *)&buff, sizeof(int) ).good() ); // <---- key line + EXAM_CHECK_ASYNC( buff == 1 ); + } + + static barrier_ip* bb; +}; + +barrier_ip* interrupted_writer::bb = 0; + +int EXAM_IMPL(sockios2_test::read0) +{ + const char fname[] = "/tmp/sockios2_test.shm"; + try { + xmt::shm_alloc<0> seg; + seg.allocate( fname, 4096, xmt::shm_base::create | xmt::shm_base::exclusive, 0660 ); + + xmt::allocator_shm<barrier_ip,0> shm; + barrier_ip& b = *new ( shm.allocate( 1 ) ) barrier_ip(); + barrier_ip& bnew = *new ( shm.allocate( 1 ) ) barrier_ip(); + interrupted_writer::bb = &bnew; + + try { + this_thread::fork(); + + b.wait(); // <-- align 1 + + barrier bb; + + thread t( interrupted_writer::read_generator, &bb ); + + bb.wait(); // <-- align 2 + + cerr << "system" << endl; + system( "echo > /dev/null" ); // <------ key line + cerr << "after system" << endl; + + bnew.wait(); // <-- align 3 + cerr << "after align 3" << endl; + + t.join(); + + exit( 0 ); + } + catch ( std::tr2::fork_in_parent& child ) { + connect_processor<interrupted_writer> r( 2008 ); + + EXAM_CHECK( r.good() ); + EXAM_CHECK( r.is_open() ); + + b.wait(); // <-- align 1 + + int stat = -1; + EXAM_CHECK( waitpid( child.pid(), &stat, 0 ) == child.pid() ); + if ( WIFEXITED(stat) ) { + EXAM_CHECK( WEXITSTATUS(stat) == 0 ); + } else { + EXAM_ERROR( "child interrupted" ); + } + + EXAM_CHECK( r.good() ); + EXAM_CHECK( r.is_open() ); + } + shm.deallocate( &bnew ); + shm.deallocate( &b ); + seg.deallocate(); + unlink( fname ); + } + catch ( xmt::shm_bad_alloc& err ) { + EXAM_ERROR( err.what() ); + } + + return EXAM_RESULT; +} Modified: branches/complement-sockios/explore/lib/sockios/ut/sockios2_test.h =================================================================== --- branches/complement-sockios/explore/lib/sockios/ut/sockios2_test.h 2008-03-26 11:45:54 UTC (rev 1836) +++ branches/complement-sockios/explore/lib/sockios/ut/sockios2_test.h 2008-03-27 12:19:58 UTC (rev 1837) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/03/25 06:22:29 ptr> +// -*- C++ -*- Time-stamp: <08/03/26 23:57:59 ptr> /* * @@ -25,6 +25,8 @@ int EXAM_DECL(connect_disconnect); int EXAM_DECL(processor_core); int EXAM_DECL(fork); + int EXAM_DECL(srv_sigpipe); + int EXAM_DECL(read0); }; #endif // __sockios2_test_h Modified: branches/complement-sockios/explore/lib/sockios/ut/sockios_test_suite.cc =================================================================== --- branches/complement-sockios/explore/lib/sockios/ut/sockios_test_suite.cc 2008-03-26 11:45:54 UTC (rev 1836) +++ branches/complement-sockios/explore/lib/sockios/ut/sockios_test_suite.cc 2008-03-27 12:19:58 UTC (rev 1837) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/03/25 07:48:17 ptr> +// -*- C++ -*- Time-stamp: <08/03/27 00:48:22 ptr> /* * @@ -80,10 +80,12 @@ sockios2_test test2; - t.add( &sockios2_test::fork, test2, "sockios2_test::fork", - t.add( &sockios2_test::processor_core, test2, "sockios2_test::processor_core", - t.add( &sockios2_test::connect_disconnect, test2, "sockios2_test::connect_disconnect", - t.add( &sockios2_test::srv_core, test2, "sockios2_test::srv_core" ) ) ) ); + t.add( &sockios2_test::read0, test2, "sockios2_test::read0", + t.add( &sockios2_test::srv_sigpipe, test2, "sockios2_test::srv_sigpipe", + t.add( &sockios2_test::fork, test2, "sockios2_test::fork", + t.add( &sockios2_test::processor_core, test2, "sockios2_test::processor_core", + t.add( &sockios2_test::connect_disconnect, test2, "sockios2_test::connect_disconnect", + t.add( &sockios2_test::srv_core, test2, "sockios2_test::srv_core" ) ) ) ) ) ); return t.girdle(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |