[complement-svn] SF.net SVN: complement: [1938] trunk/complement/explore
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2008-07-02 05:36:23
|
Revision: 1938 http://complement.svn.sourceforge.net/complement/?rev=1938&view=rev Author: complement Date: 2008-07-01 22:36:21 -0700 (Tue, 01 Jul 2008) Log Message: ----------- Merge branch 'master' of /export/hostel/pub/scm/complement Conflicts: complement/explore/include/sockios/sockmgr.cc complement/explore/lib/stem/NetTransport.cc Modified Paths: -------------- trunk/complement/explore/include/sockios/sockmgr.cc trunk/complement/explore/include/sockios/sockstream trunk/complement/explore/include/sockios/sockstream.cc trunk/complement/explore/lib/sockios/ut/Makefile trunk/complement/explore/lib/sockios/ut/Makefile.inc trunk/complement/explore/lib/sockios/ut/sockios2_test.cc trunk/complement/explore/lib/sockios/ut/sockios2_test.h trunk/complement/explore/lib/sockios/ut/sockios_test_suite.cc trunk/complement/explore/lib/stem/NetTransport.cc Modified: trunk/complement/explore/include/sockios/sockmgr.cc =================================================================== --- trunk/complement/explore/include/sockios/sockmgr.cc 2008-07-01 14:42:03 UTC (rev 1937) +++ trunk/complement/explore/include/sockios/sockmgr.cc 2008-07-02 05:36:21 UTC (rev 1938) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/07/01 10:16:39 ptr> +// -*- C++ -*- Time-stamp: <08/07/01 14:40:03 yeti> /* * Copyright (c) 2008 @@ -407,13 +407,19 @@ } if ( (ev.events & (EPOLLRDHUP | EPOLLHUP | EPOLLERR) ) != 0 ) { + // std::cerr << __FILE__ << ":" << __LINE__ << " " << ifd->first << std::endl; - if ( epoll_ctl( efd, EPOLL_CTL_DEL, ifd->first, 0 ) < 0 ) { - // throw system_error - std::cerr << __FILE__ << ":" << __LINE__ << " " << ifd->first << " " << errno << std::endl; - } if ( info.p != 0 ) { + if ( epoll_ctl( efd, EPOLL_CTL_DEL, ifd->first, 0 ) < 0 ) { + // throw system_error + std::cerr << __FILE__ << ":" << __LINE__ << " " << ifd->first << " " << errno << std::endl; + } + { + std::tr2::lock_guard<std::tr2::mutex> lk( b->ulck ); + b->close(); + b->ucnd.notify_all(); + } // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; (*info.p)( ifd->first, typename socks_processor_t::adopt_close_t() ); // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; @@ -434,7 +440,9 @@ std::cerr << __FILE__ << ":" << __LINE__ << " " << ifd->first << " " << errno << std::endl; } descr.erase( ifd ); + std::tr2::lock_guard<std::tr2::mutex> lk( b->ulck ); b->close(); + b->ucnd.notify_all(); } // dump_descr(); } Modified: trunk/complement/explore/include/sockios/sockstream =================================================================== --- trunk/complement/explore/include/sockios/sockstream 2008-07-01 14:42:03 UTC (rev 1937) +++ trunk/complement/explore/include/sockios/sockstream 2008-07-02 05:36:21 UTC (rev 1938) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/27 00:51:30 ptr> +// -*- C++ -*- Time-stamp: <08/07/01 14:46:29 yeti> /* * Copyright (c) 1997-1999, 2002, 2003, 2005-2008 @@ -480,7 +480,7 @@ protected: virtual streamsize showmanyc() - { return this->egptr() - this->gptr(); } + { return basic_socket_t::_fd != -1 ? this->egptr() - this->gptr() : -1; } virtual int_type underflow(); virtual int_type overflow( int_type c = traits::eof() ); @@ -568,7 +568,7 @@ b( self ) { } bool operator ()() const - { return b.showmanyc() != 0; } + { return b.showmanyc() > 0; } private: sockbuf_type& b; } rdready; Modified: trunk/complement/explore/include/sockios/sockstream.cc =================================================================== --- trunk/complement/explore/include/sockios/sockstream.cc 2008-07-01 14:42:03 UTC (rev 1937) +++ trunk/complement/explore/include/sockios/sockstream.cc 2008-07-02 05:36:21 UTC (rev 1938) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/26 08:40:03 ptr> +// -*- C++ -*- Time-stamp: <08/07/01 13:30:58 yeti> /* * Copyright (c) 1997-1999, 2002, 2003, 2005-2008 @@ -307,8 +307,9 @@ std::tr2::unique_lock<std::tr2::mutex> lk( ulck ); - if ( this->gptr() < this->egptr() ) + if ( this->gptr() < this->egptr() ) { return traits::to_int_type(*this->gptr()); + } if ( this->egptr() == this->gptr() ) { // fullfilled: _ebuf == gptr() setg( this->eback(), this->eback(), this->eback() ); @@ -317,12 +318,14 @@ // setg( this->eback(), this->eback(), this->eback() + offset ); // wait on condition if ( basic_socket_t::_use_rdtimeout ) { - ucnd.timed_wait( lk, basic_socket_t::_rdtimeout, rdready ); + if ( !ucnd.timed_wait( lk, basic_socket_t::_rdtimeout, rdready ) ) { + return traits::eof(); + } } else { ucnd.wait( lk, rdready ); } - - return traits::to_int_type(*this->gptr()); + + return this->gptr() < this->egptr() ? traits::to_int_type(*this->gptr()) : traits::eof(); } template<class charT, class traits, class _Alloc> Modified: trunk/complement/explore/lib/sockios/ut/Makefile =================================================================== --- trunk/complement/explore/lib/sockios/ut/Makefile 2008-07-01 14:42:03 UTC (rev 1937) +++ trunk/complement/explore/lib/sockios/ut/Makefile 2008-07-02 05:36:21 UTC (rev 1938) @@ -1,4 +1,4 @@ -# -*- Makefile -*- Time-stamp: <08/06/12 15:24:26 ptr> +# -*- Makefile -*- Time-stamp: <08/07/01 12:27:54 yeti> SRCROOT := ../../.. @@ -15,18 +15,24 @@ LIBMT_DIR = ${CoMT_DIR}/lib/mt LIBSOCK_DIR = ${CoMT_DIR}/lib/sockios LIBEXAM_DIR = ${CoMT_DIR}/lib/exam -# LIBUTF_DIR = ${CoMT_DIR}/../extern/custom/boost/libs/test/unit_test_framework +LIBMISC_DIR = ${CoMT_DIR}/lib/misc ifeq ($(OSNAME),linux) -release-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR} -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L${LIBSOCK_DIR}/${OUTPUT_DIR} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR}:${LIBEXAM_DIR}/${OUTPUT_DIR}:${LIBSOCK_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} + +release-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR} -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L${LIBSOCK_DIR}/${OUTPUT_DIR} -L${LIBMISC_DIR}/${OUTPUT_DIR} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR}:${LIBEXAM_DIR}/${OUTPUT_DIR}:${LIBSOCK_DIR}/${OUTPUT_DIR}:${LIBMISC_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} + +dbg-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR_DBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_DBG} -L${LIBMISC_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_DBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_DBG}:${LIBMISC_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} + ifndef WITHOUT_STLPORT -stldbg-shared: LDFLAGS += -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} +stldbg-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBMISC_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_STLDBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG}:${LIBMISC_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} endif -dbg-shared: LDFLAGS += -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} + endif -release-shared : LDLIBS = -lxmt -lsockios -lexam +release-shared : LDLIBS = -lxmt -lsockios -lexam -lmisc + +dbg-shared : LDLIBS = -lxmtg -lsockiosg -lexamg -lmiscg + ifndef WITHOUT_STLPORT -stldbg-shared : LDLIBS = -lxmtstlg -lsockiosstlg -lexamstlg +stldbg-shared : LDLIBS = -lxmtstlg -lsockiosstlg -lexamstlg -lmiscstlg endif -dbg-shared : LDLIBS = -lxmtg -lsockiosg -lexamg Modified: trunk/complement/explore/lib/sockios/ut/Makefile.inc =================================================================== --- trunk/complement/explore/lib/sockios/ut/Makefile.inc 2008-07-01 14:42:03 UTC (rev 1937) +++ trunk/complement/explore/lib/sockios/ut/Makefile.inc 2008-07-02 05:36:21 UTC (rev 1938) @@ -1,5 +1,5 @@ -# -*- makefile -*- Time-stamp: <08/06/09 20:31:17 yeti> +# -*- makefile -*- Time-stamp: <08/07/01 12:22:34 yeti> PRGNAME = sockios_ut SRC_CC = message.cc \ - names.cc sockios_test.cc sockios2_test.cc sockios_test_suite.cc unit_test.cc + names.cc sockios_test.cc sockios2_test.cc sockios_test_suite.cc Modified: trunk/complement/explore/lib/sockios/ut/sockios2_test.cc =================================================================== --- trunk/complement/explore/lib/sockios/ut/sockios2_test.cc 2008-07-01 14:42:03 UTC (rev 1937) +++ trunk/complement/explore/lib/sockios/ut/sockios2_test.cc 2008-07-02 05:36:21 UTC (rev 1938) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/26 21:29:52 ptr> +// -*- C++ -*- Time-stamp: <08/07/01 15:28:50 yeti> /* * @@ -464,6 +464,96 @@ return EXAM_RESULT; } +class srv_reader +{ + public: + srv_reader( sockstream& ) + { } + ~srv_reader() + { } + void connect( sockstream& s ) + { + char buf[64]; + + while ( s.read( buf, 4 ).good() ) { + continue; + } + + cnd.notify_one(); + } + + static std::tr2::condition_event cnd; +}; + +std::tr2::condition_event srv_reader::cnd; + +int EXAM_IMPL(sockios2_test::disconnect) +{ + const char fname[] = "/tmp/sockios2_test.shm"; + xmt::shm_alloc<0> seg; + + try { + seg.allocate( fname, 4096, xmt::shm_base::create | xmt::shm_base::exclusive, 0660 ); + } + catch ( xmt::shm_bad_alloc& err ) { + EXAM_ERROR( err.what() ); + try { + seg.allocate( fname, 4096, 0, 0660 ); + } + catch ( xmt::shm_bad_alloc& err2 ) { + EXAM_ERROR( err.what() ); + return EXAM_RESULT; + } + } + + xmt::allocator_shm<barrier_ip,0> shm; + barrier_ip& b = *new ( shm.allocate( 1 ) ) barrier_ip(); + + try { + this_thread::fork(); + + connect_processor<srv_reader> prss( 2008 ); + + EXAM_CHECK_ASYNC( prss.good() ); + + b.wait(); + + if ( srv_reader::cnd.timed_wait( milliseconds( 800 ) ) ) { + exit( 0 ); + } + // srv_reader::cnd.wait(); + + exit( 1 ); + } + catch ( std::tr2::fork_in_parent& child ) { + b.wait(); + + sockstream s( "localhost", 2008 ); + + char buf[] = "1234"; + + EXAM_CHECK( s.write( buf, 4 ).flush().good() ); + + s.rdbuf()->shutdown( sock_base::stop_in | sock_base::stop_out ); + + // s.close(); + + int stat = -1; + EXAM_CHECK( waitpid( child.pid(), &stat, 0 ) == child.pid() ); + if ( WIFEXITED(stat) ) { + EXAM_CHECK( WEXITSTATUS(stat) == 0 ); + } else { + EXAM_ERROR( "child fail" ); + } + } + + shm.deallocate( &b ); + seg.deallocate(); + unlink( fname ); + + return EXAM_RESULT; +} + int EXAM_IMPL(sockios2_test::fork) { const char fname[] = "/tmp/sockios2_test.shm"; Modified: trunk/complement/explore/lib/sockios/ut/sockios2_test.h =================================================================== --- trunk/complement/explore/lib/sockios/ut/sockios2_test.h 2008-07-01 14:42:03 UTC (rev 1937) +++ trunk/complement/explore/lib/sockios/ut/sockios2_test.h 2008-07-02 05:36:21 UTC (rev 1938) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/27 00:55:32 ptr> +// -*- C++ -*- Time-stamp: <08/07/01 12:21:46 yeti> /* * @@ -22,6 +22,7 @@ int EXAM_DECL(srv_core); int EXAM_DECL(connect_disconnect); + int EXAM_DECL(disconnect); int EXAM_DECL(processor_core); int EXAM_DECL(fork); int EXAM_DECL(srv_sigpipe); Modified: trunk/complement/explore/lib/sockios/ut/sockios_test_suite.cc =================================================================== --- trunk/complement/explore/lib/sockios/ut/sockios_test_suite.cc 2008-07-01 14:42:03 UTC (rev 1937) +++ trunk/complement/explore/lib/sockios/ut/sockios_test_suite.cc 2008-07-02 05:36:21 UTC (rev 1938) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/11 21:55:26 yeti> +// -*- C++ -*- Time-stamp: <08/07/01 12:57:40 yeti> /* * @@ -9,7 +9,6 @@ * */ -#include "sockios_test_suite.h" #include "sockios_test.h" #include "sockios2_test.h" @@ -17,7 +16,7 @@ #include <iostream> #include <list> -#include <mt/xmt.h> +#include <misc/opts.h> // #include <sockios/sockstream> // #include <sockios/sockmgr.h> @@ -31,14 +30,12 @@ int EXAM_DECL(test_more_bytes_in_socket); int EXAM_DECL(test_more_bytes_in_socket2); -int EXAM_IMPL(sockios_test_suite) +int main( int argc, const char** argv ) { - exam::test_suite::test_case_type tc[3]; + exam::test_suite::test_case_type tc[4]; exam::test_suite t( "libsockios test" ); - t.flags( t.flags() | exam::base_logger::trace | exam::base_logger::verbose ); - #if 0 trivial_sockios_test trivial_test; @@ -83,10 +80,59 @@ 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", + tc[3] = 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::disconnect, test2, "sockios2_test::disconnect", tc[3] ); + + Opts opts; + + opts.description( "test suite for 'sockios' framework" ); + opts.usage( "[options]" ); + + opts << option<bool>( "print this help message", 'h', "help" ) + << option<bool>( "list all test cases", 'l', "list" ) + << option<string>( "run tests by number", 'r', "run" )["0"] + << option<bool>( "print status of tests within test suite", 'v', "verbose" ) + << option<bool>( "trace checks", 't', "trace" ); + + try { + opts.parse( argc, argv ); + } + catch (...) { + opts.help( cerr ); + return 1; + } + + if ( opts.is_set( 'h' ) ) { + opts.help( cerr ); + return 0; + } + + if ( opts.is_set( 'l' ) ) { + t.print_graph( cerr ); + return 0; + } + + if ( opts.is_set( 'v' ) ) { + t.flags( t.flags() | exam::base_logger::verbose ); + } + + if ( opts.is_set( 't' ) ) { + t.flags( t.flags() | exam::base_logger::trace ); + } + + if ( opts.is_set( 'r' ) ) { + stringstream ss( opts.get<string>( 'r' ) ); + int n; + while ( ss >> n ) { + t.single( n ); + } + + return 0; + } + return t.girdle(); } Modified: trunk/complement/explore/lib/stem/NetTransport.cc =================================================================== --- trunk/complement/explore/lib/stem/NetTransport.cc 2008-07-01 14:42:03 UTC (rev 1937) +++ trunk/complement/explore/lib/stem/NetTransport.cc 2008-07-02 05:36:21 UTC (rev 1938) @@ -105,8 +105,6 @@ uint32_t buf[bsz]; using namespace std; - MT_IO_REENTRANT( *net ) - if ( !net->read( (char *)buf, sizeof(uint32_t) ).good() ) { return false; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |