[complement-svn] SF.net SVN: complement: [1787] trunk/complement/explore
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2007-11-19 17:14:44
|
Revision: 1787 http://complement.svn.sourceforge.net/complement/?rev=1787&view=rev Author: complement Date: 2007-11-19 08:50:55 -0800 (Mon, 19 Nov 2007) Log Message: ----------- remove out-of-date sockmgr_sream_MP_SELECT; stack size restriction for loop really dangerous; accept_udp come back, but concept changed---no session at all in UDP processing; test for simple udp connection; libsockios: Version 1.14.0 Modified Paths: -------------- trunk/complement/explore/include/sockios/sockmgr.cc trunk/complement/explore/include/sockios/sockmgr.h trunk/complement/explore/lib/sockios/ChangeLog trunk/complement/explore/lib/sockios/Makefile.inc trunk/complement/explore/lib/sockios/ut/ConnectionProcessor.cc trunk/complement/explore/lib/sockios/ut/ConnectionProcessor.h trunk/complement/explore/lib/sockios/ut/sockios_test_suite.cc Modified: trunk/complement/explore/include/sockios/sockmgr.cc =================================================================== --- trunk/complement/explore/include/sockios/sockmgr.cc 2007-11-13 13:17:44 UTC (rev 1786) +++ trunk/complement/explore/include/sockios/sockmgr.cc 2007-11-19 16:50:55 UTC (rev 1787) @@ -14,9 +14,9 @@ #include <algorithm> #include <functional> -#ifdef __unix -extern "C" int nanosleep(const struct timespec *, struct timespec *); -#endif +// #ifdef __unix +// extern "C" int nanosleep(const struct timespec *, struct timespec *); +// #endif #ifdef STLPORT _STLP_BEGIN_NAMESPACE @@ -43,7 +43,7 @@ _pfd[0].fd = fd_unsafe(); _pfd[0].events = POLLIN; _pfd[1].fd = pipefd[0]; - _pfd[1].events = POLLIN; + _pfd[1].events = POLLIN; } } else if ( t == sock_base::sock_dgram ) { _accept = &_Self_type::accept_udp; @@ -56,14 +56,14 @@ _pfd[0].fd = fd_unsafe(); _pfd[0].events = POLLIN; _pfd[1].fd = pipefd[0]; - _pfd[1].events = POLLIN; + _pfd[1].events = POLLIN; } } else { throw invalid_argument( "sockmgr_stream_MP" ); } _loop_cnd.set( false ); - loop_thr.launch( loop, this, 0, PTHREAD_STACK_MIN * 2 ); + loop_thr.launch( loop, this /* , 0, PTHREAD_STACK_MIN * 2 */ ); _loop_cnd.try_wait(); } } @@ -266,11 +266,23 @@ socklen_t sz = sizeof( sockaddr_in ); bool _in_buf; + // Problem here: + // if I see event on pfd[1], I should set fd_in_work = 1 and process it below in loop; + // but if no event on pfd[1], I don't really know wether pfd[1] polling in + // connect_processor or not; size of _conn_pool don't help here too ... + + // Hmm, but not all so bad: if I will see event on pfd[0] here, I just + // add SAME iterator to _conn_pool, and hope that observer process it accurate... + + int pret = poll( &_pfd[1], 1, 1 ); // timeout as short as possible + int fd_in_work = pret == 0 ? 0 : 1; + // int fd_in_work = 0; + do { _in_buf = false; _pfd[0].revents = 0; _pfd[1].revents = 0; - while ( poll( &_pfd[0], /* _pfd.size() */ 1, -1 ) < 0 ) { // wait infinite + while ( poll( &_pfd[0 + fd_in_work], /* _pfd.size() */ 2 - fd_in_work, -1 ) < 0 ) { // wait infinite if ( errno == EINTR ) { // may be interrupted, check and ignore errno = 0; continue; @@ -290,20 +302,44 @@ if ( !is_open_unsafe() ) { // may be already closed return false; } - // poll found event on binded socket - // get address of caller only - char buff[65535]; - ::recvfrom( fd(), buff, 65535, MSG_PEEK, &addr.any, &sz ); try { xmt::scoped_lock _l( _c_lock ); - // if addr.any pesent in _M_c - typename container_type::iterator i = - find_if( _M_c.begin(), _M_c.end(), bind2nd( _M_comp_inet, addr.any ) ); - if ( i == _M_c.end() ) { + // + if ( _M_c.empty() ) { _M_c.push_back( _Connect() ); - _M_c.back().open( fd(), addr.any, sock_base::sock_dgram ); + // poll found event on binded socket + // to fill addr.any only, for _M_c.back().open() call + char buff[1]; + ::recvfrom( fd_unsafe(), buff, 1, MSG_PEEK, &addr.any, &sz ); + _M_c.back().open( fd_unsafe(), addr.any, sock_base::sock_dgram ); _Connect *cl_new = &_M_c.back(); + if ( cl_new->s.rdbuf()->in_avail() > 0 ) { + // this is the case when user read from sockstream + // in ctor above; push processing of this stream + xmt::scoped_lock lk(_dlock); + _conn_pool.push_back( _M_c.begin() ); + _pool_cnd.set( true ); + _observer_cnd.set( true ); + _in_buf = true; + fd_in_work = 1; + } + } else { // normal data available for reading + xmt::scoped_lock lk(_dlock); + _conn_pool.push_back( _M_c.begin() ); + // xmt::Thread::gettime( &_tpush ); + _pool_cnd.set( true ); + _observer_cnd.set( true ); + _in_buf = true; + fd_in_work = 1; } + // if addr.any pesent in _M_c + // typename container_type::iterator i = + // find_if( _M_c.begin(), _M_c.end(), bind2nd( _M_comp_inet, addr.any ) ); + // if ( i == _M_c.end() ) { + // _M_c.push_back( _Connect() ); + // _M_c.back().open( fd(), addr.any, sock_base::sock_dgram ); + // _Connect *cl_new = &_M_c.back(); + // } // // ... // @@ -311,52 +347,15 @@ catch ( ... ) { } } -#if 0 if ( _pfd[1].revents != 0 ) { // fd come back for poll - pollfd rfd; - ::read( _pfd[1].fd, reinterpret_cast<char *>(&rfd.fd), sizeof(sock_base::socket_type) ); - rfd.events = POLLIN; - rfd.revents = 0; - _pfd.push_back( rfd ); + // really not used (i.e. this is fd()), but we need to read it from pipe + sock_base::socket_type _xfd; + ::read( _pfd[1].fd, reinterpret_cast<char *>(&_xfd), sizeof(sock_base::socket_type) ); + fd_in_work = 0; } -#endif } while ( /* !_shift_fd() && */ !_in_buf ); -#if 0 - if ( poll( &_pfd[0], 1, -1 ) < 0 ) { // wait infinite - return false; // poll wait infinite, so it can't return 0 (timeout), so it return -1. - } - // get address of caller only - char buff[32]; - ::recvfrom( fd(), buff, 32, MSG_PEEK, &addr.any, &sz ); - _Connect *cl; - try { - _c_lock.lock(); - typename container_type::iterator i = _M_c.begin(); - sockbuf *b; - while ( i != _M_c.end() ) { - b = (*i).s.rdbuf(); - if ( (*i).s.is_open() && b->stype() == sock_base::sock_dgram && - b->port() == addr.inet.sin_port && - b->inet_addr() == addr.inet.sin_addr.s_addr ) { - _c_lock.unlock(); - return true /* *i */; - } - ++i; - } - - _M_c.push_back( Connect() ); - - cl->s->open( dup( fd() ), addr.any, sock_base::sock_dgram ); - cl->_proc = new Connect( *cl->s ); - _c_lock.unlock(); - } - catch ( ... ) { - _c_lock.unlock(); - cl = 0; - } -#endif - return true /* cl */; + return true; } template <class Connect, void (Connect::*C)( std::sockstream& ), void (Connect::*T)() > @@ -589,341 +588,6 @@ #endif // !__FIT_NO_POLL -#ifndef __FIT_NO_SELECT - -template <class Connect> -void sockmgr_stream_MP_SELECT<Connect>::_open( sock_base::stype t ) -{ - xmt::scoped_lock lk(_fd_lck); - if ( is_open_unsafe() ) { - if ( t == sock_base::sock_stream ) { - _accept = &_Self_type::accept_tcp; - } else if ( t == sock_base::sock_dgram ) { - _accept = &_Self_type::accept_udp; - } else { - throw invalid_argument( "sockmgr_stream_MP" ); - } - - FD_ZERO( &_pfdr ); - FD_ZERO( &_pfde ); - FD_SET( fd_unsafe(), &_pfdr ); - FD_SET( fd_unsafe(), &_pfde ); - _fdmax = fd_unsafe(); - - loop_thr.launch( loop, this, 0, PTHREAD_STACK_MIN * 2 ); - } -} - -template <class Connect> -void sockmgr_stream_MP_SELECT<Connect>::open( const in_addr& addr, int port, sock_base::stype t ) -{ - basic_sockmgr::open( addr, port, t, sock_base::inet ); - sockmgr_stream_MP_SELECT<Connect>::_open( t ); -} - -template <class Connect> -void sockmgr_stream_MP_SELECT<Connect>::open( unsigned long addr, int port, sock_base::stype t ) -{ - basic_sockmgr::open( addr, port, t, sock_base::inet ); - sockmgr_stream_MP_SELECT<Connect>::_open( t ); -} - -template <class Connect> -void sockmgr_stream_MP_SELECT<Connect>::open( int port, sock_base::stype t ) -{ - basic_sockmgr::open( port, t, sock_base::inet ); - sockmgr_stream_MP_SELECT<Connect>::_open( t ); -} - -template <class Connect> -__FIT_TYPENAME sockmgr_stream_MP_SELECT<Connect>::_Connect *sockmgr_stream_MP_SELECT<Connect>::_shift_fd() -{ - _Connect *msg = 0; - for ( unsigned j = 0; j <= _fdmax; ++j ) { - if ( FD_ISSET( j, &_pfde ) || FD_ISSET( j, &_pfdr ) ) { - // We should distinguish closed socket from income message - typename container_type::iterator i = - find_if( _M_c.begin(), _M_c.end(), bind2nd( _M_comp, j ) ); - // Solaris return ERROR on poll, before close socket - if ( i == _M_c.end() ) { - // Socket already closed (may be after read/write failure) - // this way may not notify poll (like in HP-UX 11.00) via POLLERR flag - // as made in Solaris - // decrement of _fdmax may be here // --_fdcount; - for ( i = _M_c.begin(); i != _M_c.end(); ++i ) { - if ( (*i)->s->rdbuf()->fd() == -1 ) { - (*i)->s->close(); - (*i)->_proc->close(); - delete (*i)->_proc; - (*i)->_proc = 0; - } - } - continue; - } else if ( FD_ISSET( j, &_pfde ) ) { - // poll first see closed socket - // decrement of _fdmax may be here // --_fdcount; - (*i)->s->close(); - (*i)->_proc->close(); - delete (*i)->_proc; - (*i)->_proc = 0; - continue; - } else { - // Check that other side close socket: - // on Linux and (?) Solaris I see normal POLLIN event, and see error - // only after attempt to read something. - // Due to this fd isn't stream (it's upper than stream), - // I can't use ioctl with I_PEEK command here. - char x; - int nr = recv( j, reinterpret_cast<void *>(&x), 1, MSG_PEEK ); - if ( nr <= 0 ) { // I can't read even one byte: this designate closed - // socket operation - // decrement of _fdmax may be here // --_fdcount; - (*i)->s->close(); - (*i)->_proc->close(); - delete (*i)->_proc; - (*i)->_proc = 0; - continue; - } - } - if ( msg == 0 ) { - FD_CLR( j, &_pfdr ); - FD_CLR( j, &_pfde ); - msg = *i; - } - } - } - - return msg; -} - -template <class Connect> -__FIT_TYPENAME sockmgr_stream_MP_SELECT<Connect>::_Connect *sockmgr_stream_MP_SELECT<Connect>::accept_tcp() -{ - if ( !is_open() ) { - return 0; - } - - _xsockaddr addr; - size_t sz = sizeof( sockaddr_in ); - - _Connect *cl; - bool more = true; - - do { - FD_ZERO( &_pfdr ); - FD_ZERO( &_pfde ); - - // *** Set all listen sockets here... - _fd_lck.lock(); - FD_SET( fd_unsafe(), &_pfdr ); - FD_SET( fd_unsafe(), &_pfde ); - _fdmax = fd_unsafe(); - _fd_lck.unlock(); - for ( typename container_type::iterator i = _M_c.begin(); i != _M_c.end(); ++i ) { - if ( (*i)->s->is_open() ) { - FD_SET( (*i)->s->rdbuf()->fd(), &_pfdr ); - FD_SET( (*i)->s->rdbuf()->fd(), &_pfde ); - _fdmax = max( (*i)->s->rdbuf()->fd(), _fdmax ); - } - } - - // select wait infinite here, so it can't return 0 (timeout), so it return -1. - while ( select( _fdmax + 1, &_pfdr, 0, &_pfde, 0 ) < 0 ) { // wait infinite - if ( errno == EINTR ) { // may be interrupted, check and ignore - errno = 0; - continue; - } - return 0; // poll wait infinite, so it can't return 0 (timeout), so it return -1. - } - - xmt::scoped_lock lk(_fd_lck); - if ( !is_open_unsafe() || FD_ISSET( fd_unsafe(), &_pfde ) ) { // may be already closed - return 0; - } - - if ( FD_ISSET( fd_unsafe(), &_pfdr ) ) { // select found event on binded socket - sock_base::socket_type _sd = ::accept( fd_unsafe(), &addr.any, &sz ); - if ( _sd == -1 ) { - // check and set errno - // _STLP_ASSERT( _sd == -1 ); - return 0; - } - - try { - // sockmgr_client_MP<Connect> *cl_new; - _Connect *cl_new; - typename container_type::iterator i = - find_if( _M_c.begin(), _M_c.end(), bind2nd( _M_comp, -1 ) ); - - if ( i == _M_c.end() ) { // we need new message processor - cl_new = new _Connect(); - cl_new->s = new sockstream(); - cl_new->s->open( _sd, addr.any ); - cl_new->_proc = new Connect( *cl_new->s ); - _M_c.push_back( cl_new ); - } else { // we can reuse old - cl_new = *i; - cl_new->s->open( _sd, addr.any ); - // delete cl_new->_proc; // may be new ( cl_new->_proc ) Connect( *cl_new->s ); - cl_new->_proc = new Connect( *cl_new->s ); - } - - FD_SET( _sd, &_pfdr ); - FD_SET( _sd, &_pfde ); - } - catch ( ... ) { - } - } - - cl = _shift_fd(); // find polled and return it - if ( cl != 0 ) { - return cl; // return message processor - } else { // nothing found, may be only closed sockets - FD_SET( fd_unsafe(), &_pfdr ); // we return to poll again - } - more = is_open_unsafe() && FD_ISSET( fd_unsafe(), &_pfdr ); - } while ( more ); - - return 0; // Unexpected; should never occur - -} - -template <class Connect> -__FIT_TYPENAME sockmgr_stream_MP_SELECT<Connect>::_Connect *sockmgr_stream_MP_SELECT<Connect>::accept_udp() -{ - if ( !is_open() ) { - return 0; - } - - size_t sz = sizeof( sockaddr_in ); - _xsockaddr addr; - - if ( select( fd() + 1, &_pfdr, 0, &_pfde, 0 ) < 0 ) { - return 0; // poll wait infinite, so it can't return 0 (timeout), so it return -1. - } - // get address of caller only - char buff[32]; - ::recvfrom( fd(), buff, 32, MSG_PEEK, &addr.any, &sz ); - _Connect *cl; - try { - _c_lock.lock(); - typename container_type::iterator i = _M_c.begin(); - sockbuf *b; - while ( i != _M_c.end() ) { - b = (*i)->s->rdbuf(); - if ( (*i)->s->is_open() && b->stype() == sock_base::sock_dgram && - b->port() == addr.inet.sin_port && - b->inet_addr() == addr.inet.sin_addr.s_addr ) { - _c_lock.unlock(); - return *i; - } - ++i; - } - - cl = new _Connect(); - cl->s = new sockstream(); - _M_c.push_back( cl ); -#ifdef _WIN32 - SOCKET dup_fd; - HANDLE proc = GetCurrentProcess(); - DuplicateHandle( proc, (HANDLE)fd(), proc, (HANDLE *)&dup_fd, 0, FALSE, DUPLICATE_SAME_ACCESS ); - cl->s->open( dup_fd, addr.any, sock_base::sock_dgram ); -#else - cl->s->open( dup( fd() ), addr.any, sock_base::sock_dgram ); -#endif - cl->_proc = new Connect( *cl->s ); - _c_lock.unlock(); - } - catch ( ... ) { - _c_lock.unlock(); - cl = 0; - } - return cl; -} - -template <class Connect> -void sockmgr_stream_MP_SELECT<Connect>::_close_by_signal( int ) -{ -#ifdef _PTHREADS - void *_uw_save = *((void **)pthread_getspecific( xmt::Thread::mtkey() ) + _idx ); - _Self_type *me = static_cast<_Self_type *>( _uw_save ); - - me->close(); -#else -// #error "Fix me!" -#ifdef __FIT_WIN32THREADS - void *_uw_save = *((void **)TlsGetValue( xmt::Thread::mtkey() ) + _idx ); - _Self_type *me = static_cast<_Self_type *>( _uw_save ); - - me->close(); -#endif -#endif -} - -template <class Connect> -xmt::Thread::ret_t sockmgr_stream_MP_SELECT<Connect>::loop( void *p ) -{ - _Self_type *me = static_cast<_Self_type *>(p); - me->loop_id.pword( _idx ) = me; // push pointer to self for signal processing - - try { - _Connect *s; - unsigned _sfd; - - while ( (s = me->accept()) != 0 ) { - // The user connect function: application processing - if ( s->s->is_open() ) { - _sfd = s->s->rdbuf()->fd(); - s->_proc->connect( *s->s ); - if ( !s->s->good() ) { - s->s->close(); - s->_proc->close(); - delete s->_proc; - s->_proc = 0; - } - } - } - } - catch ( ... ) { - me->_c_lock.lock(); - - for ( typename container_type::iterator i = me->_M_c.begin(); i != me->_M_c.end(); ++i ) { - if ( (*i)->s->is_open() ) { // close all not closed yet - (*i)->s->close(); - (*i)->_proc->close(); - } - delete (*i)->s; - (*i)->s = 0; - delete (*i)->_proc; - (*i)->_proc = 0; - } - me->close(); - me->_c_lock.unlock(); - - return reinterpret_cast<xmt::Thread::ret_t>(-1); - // throw; - } - - me->_c_lock.lock(); - - for ( typename container_type::iterator i = me->_M_c.begin(); i != me->_M_c.end(); ++i ) { - if ( (*i)->s->is_open() ) { // close all not closed yet - (*i)->s->close(); - (*i)->_proc->close(); - } - delete (*i)->s; - (*i)->s = 0; - delete (*i)->_proc; - (*i)->_proc = 0; - } - me->close(); - me->_c_lock.unlock(); - - return 0; -} - -#endif // !__FIT_NO_SELECT - #ifdef STLPORT _STLP_END_NAMESPACE #else Modified: trunk/complement/explore/include/sockios/sockmgr.h =================================================================== --- trunk/complement/explore/include/sockios/sockmgr.h 2007-11-13 13:17:44 UTC (rev 1786) +++ trunk/complement/explore/include/sockios/sockmgr.h 2007-11-19 16:50:55 UTC (rev 1787) @@ -90,7 +90,7 @@ { return _state == ios_base::goodbit; } sock_base::socket_type fd() const - { xmt::scoped_lock lk(_fd_lck); return fd_unsafe(); } + { xmt::scoped_lock lk(_fd_lck); sock_base::socket_type tmp = fd_unsafe(); return tmp; } __FIT_DECLSPEC void shutdown( sock_base::shutdownflg dir ); @@ -338,117 +338,6 @@ #endif // !__FIT_NO_POLL -#ifndef __FIT_NO_SELECT - -template <class Connect> -class sockmgr_stream_MP_SELECT : - public basic_sockmgr -{ - public: - sockmgr_stream_MP_SELECT() : - basic_sockmgr(), - _fdmax( 0 ) - { - } - - explicit sockmgr_stream_MP_SELECT( const in_addr& addr, int port, sock_base::stype t = sock_base::sock_stream ) : - basic_sockmgr(), - _fdmax( 0 ) - { - open( addr, port, t ); - } - - explicit sockmgr_stream_MP_SELECT( unsigned long addr, int port, sock_base::stype t = sock_base::sock_stream ) : - basic_sockmgr(), - _fdmax( 0 ) - { - open( addr, port, t ); - } - - explicit sockmgr_stream_MP_SELECT( int port, sock_base::stype t = sock_base::sock_stream ) : - basic_sockmgr(), - _fdmax( 0 ) - { - open( port, t ); - } - - ~sockmgr_stream_MP_SELECT() - { - } - - void open( const in_addr& addr, int port, sock_base::stype t = sock_base::sock_stream ); - void open( unsigned long addr, int port, sock_base::stype t = sock_base::sock_stream ); - void open( int port, sock_base::stype t = sock_base::sock_stream ); - - virtual void close() - { basic_sockmgr::close(); } - - void wait() - { loop_id.join(); } - - void detach( sockstream& ) // remove sockstream from polling in manager - { } - - protected: - void _open( sock_base::stype t = sock_base::sock_stream ); - static xmt::Thread::ret_t loop( void * ); - - struct _Connect { - sockstream *s; - Connect *_proc; - }; - - struct fd_equal : - public std::binary_function<_Connect *,int,bool> - { - bool operator()(const _Connect *__x, int __y) const - { return __x->s->rdbuf()->fd() == __y; } - }; - - struct in_buf_avail : - public std::unary_function<_Connect *,bool> - { - bool operator()(const _Connect *__x) const - { return __x->s->rdbuf()->in_avail() > 0; } - }; - - typedef _Connect *(sockmgr_stream_MP_SELECT<Connect>::*accept_type)(); - - accept_type _accept; - _Connect *accept() // workaround for CC - { return (this->*_accept)(); } - _Connect *accept_tcp(); - _Connect *accept_udp(); - - private: - xmt::Thread loop_id; - - protected: - typedef sockmgr_stream_MP_SELECT<Connect> _Self_type; - typedef std::vector<_Connect *> _Sequence; - typedef fd_equal _Compare; - typedef typename _Sequence::value_type value_type; - typedef typename _Sequence::size_type size_type; - typedef _Sequence container_type; - - typedef typename _Sequence::reference reference; - typedef typename _Sequence::const_reference const_reference; - - _Sequence _M_c; - _Compare _M_comp; - in_buf_avail _M_av; - xmt::mutex _c_lock; - - fd_set _pfdr; - fd_set _pfde; - int _fdmax; - - private: - _Connect *_shift_fd(); - static void _close_by_signal( int ); -}; -#endif // !__FIT_NO_SELECT - #ifdef STLPORT _STLP_END_NAMESPACE #else Modified: trunk/complement/explore/lib/sockios/ChangeLog =================================================================== --- trunk/complement/explore/lib/sockios/ChangeLog 2007-11-13 13:17:44 UTC (rev 1786) +++ trunk/complement/explore/lib/sockios/ChangeLog 2007-11-19 16:50:55 UTC (rev 1787) @@ -1,3 +1,19 @@ +2007-11-19 Petr Ovtchenkov <pt...@is...> + + * sockmgr.h, sockmgr.cc: remove out-of-date sockmgr_sream_MP_SELECT; + + * sockmgr.cc: stack size restriction for loop really dangerous; + + * sockmgr.cc: accept_udp come back, but concept changed---no session + at all in UDP processing; + + * ut/ConnectionProcessor.h, ut/ConnectionProcessor.cc: test for simple + udp connection; + + * ut/sockios_test_suite.cc: ditto; + + * libsockios: Version 1.14.0. + 2007-09-24 Petr Ovtchenkov <pt...@is...> * sockios/sockmgr.h, sockios/sockmgr.cc: rename loop_id to loop_thr, Modified: trunk/complement/explore/lib/sockios/Makefile.inc =================================================================== --- trunk/complement/explore/lib/sockios/Makefile.inc 2007-11-13 13:17:44 UTC (rev 1786) +++ trunk/complement/explore/lib/sockios/Makefile.inc 2007-11-19 16:50:55 UTC (rev 1787) @@ -2,7 +2,7 @@ LIBNAME = sockios MAJOR = 1 -MINOR = 13 +MINOR = 14 PATCH = 0 SRC_CC = _sockstream.cc _sockmgr.cc SRC_C = freebsd/getaddrinfo.c \ Modified: trunk/complement/explore/lib/sockios/ut/ConnectionProcessor.cc =================================================================== --- trunk/complement/explore/lib/sockios/ut/ConnectionProcessor.cc 2007-11-13 13:17:44 UTC (rev 1786) +++ trunk/complement/explore/lib/sockios/ut/ConnectionProcessor.cc 2007-11-19 16:50:55 UTC (rev 1787) @@ -146,6 +146,56 @@ // ****************** +int EXAM_IMPL(trivial_sockios_test::simple_udp) +{ +#ifndef __FIT_NO_POLL + + std::sockmgr_stream_MP<ConnectionProcessor> srv( port, std::sock_base::sock_dgram ); // start server + { + EXAM_MESSAGE( "Client start" ); + std::sockstream sock( "localhost", ::port, std::sock_base::sock_dgram ); + string srv_line; + + sock << ::message << endl; + + EXAM_CHECK( sock.good() ); + + // sock.clear(); + getline( sock, srv_line ); + + EXAM_CHECK( sock.good() ); + + EXAM_CHECK( srv_line == ::message_rsp ); + + EXAM_MESSAGE( "Client close connection (client's end of life)" ); + // sock.close(); // no needs, that will done in sock destructor + } + + { + std::sockstream sock( "127.0.0.1", ::port, std::sock_base::sock_dgram ); + string srv_line; + + sock << ::message << endl; + + EXAM_CHECK( sock.good() ); + + // sock.clear(); + getline( sock, srv_line ); + + EXAM_CHECK( sock.good() ); + + EXAM_CHECK( srv_line == ::message_rsp ); + } + + srv.close(); // close server, so we don't wait server termination on next line + srv.wait(); // Wait for server stop to serve clients connections +#else + EXAM_ERROR( "poll-based sockmgr not implemented on this platform" ); +#endif + + return EXAM_RESULT; +} + int EXAM_IMPL(trivial_sockios_test::listen_iface) { #ifndef __FIT_NO_POLL Modified: trunk/complement/explore/lib/sockios/ut/ConnectionProcessor.h =================================================================== --- trunk/complement/explore/lib/sockios/ut/ConnectionProcessor.h 2007-11-13 13:17:44 UTC (rev 1786) +++ trunk/complement/explore/lib/sockios/ut/ConnectionProcessor.h 2007-11-19 16:50:55 UTC (rev 1787) @@ -39,6 +39,7 @@ trivial_sockios_test(); int EXAM_DECL(simple); + int EXAM_DECL(simple_udp); int EXAM_DECL(listen_iface); int EXAM_DECL(shared_socket); Modified: trunk/complement/explore/lib/sockios/ut/sockios_test_suite.cc =================================================================== --- trunk/complement/explore/lib/sockios/ut/sockios_test_suite.cc 2007-11-13 13:17:44 UTC (rev 1786) +++ trunk/complement/explore/lib/sockios/ut/sockios_test_suite.cc 2007-11-19 16:50:55 UTC (rev 1787) @@ -36,11 +36,12 @@ exam::test_suite t( "libsockios test" ); - // t.flags( t.flags() | exam::base_logger::trace ); + // t.flags( t.flags() | exam::base_logger::trace | exam::base_logger::verbose ); trivial_sockios_test trivial_test; tc[0] = t.add( &trivial_sockios_test::simple, trivial_test, "trivial_sockios_test::simple" ); + t.add( &trivial_sockios_test::simple_udp, trivial_test, "trivial_sockios_test::simple_udp", tc[0] ); names_sockios_test names_test; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |