complement-svn Mailing List for Complement (Page 3)
Status: Pre-Alpha
Brought to you by:
complement
You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(61) |
Nov
(76) |
Dec
(39) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
(33) |
Feb
(41) |
Mar
(16) |
Apr
|
May
(22) |
Jun
(14) |
Jul
(64) |
Aug
(60) |
Sep
(35) |
Oct
(34) |
Nov
(10) |
Dec
(5) |
2008 |
Jan
(4) |
Feb
(24) |
Mar
(10) |
Apr
(30) |
May
(15) |
Jun
(50) |
Jul
(20) |
Aug
(7) |
Sep
(8) |
Oct
(10) |
Nov
|
Dec
|
From: <com...@us...> - 2008-06-29 21:48:36
|
Revision: 1928 http://complement.svn.sourceforge.net/complement/?rev=1928&view=rev Author: complement Date: 2008-06-29 14:48:33 -0700 (Sun, 29 Jun 2008) Log Message: ----------- revision of options framework. insert object with type and type check into option; default value passed via [] operator; option registration done via << oprator. Modified Paths: -------------- trunk/complement/explore/include/misc/opts.h trunk/complement/explore/lib/exam/ut/exam_self_test.cc trunk/complement/explore/lib/misc/ChangeLog trunk/complement/explore/lib/misc/Makefile.inc trunk/complement/explore/lib/misc/opts.cc trunk/complement/explore/lib/misc/ut/Makefile trunk/complement/explore/lib/misc/ut/Makefile.inc trunk/complement/explore/lib/misc/ut/misc_test_suite.cc trunk/complement/explore/lib/misc/ut/opts_test.cc Modified: trunk/complement/explore/include/misc/opts.h =================================================================== --- trunk/complement/explore/include/misc/opts.h 2008-06-29 21:48:10 UTC (rev 1927) +++ trunk/complement/explore/include/misc/opts.h 2008-06-29 21:48:33 UTC (rev 1928) @@ -1,10 +1,10 @@ -// -*- C++ -*- Time-stamp: <08/06/29 13:52:41 ptr> +// -*- C++ -*- Time-stamp: <08/06/29 22:16:12 ptr> /* * Copyright (c) 2008 * Dmitry Osmakov * - * Copyright (c) 2008 + * Copyright (c) 1997-1998, 2001, 2008 * Petr Ovtchenkov * * Licensed under the Academic Free License Version 3.0 @@ -17,11 +17,15 @@ #include <iostream> #include <string> #include <vector> +#include <list> #include <sstream> #include <typeinfo> #include <cctype> #include <exception> #include <stdexcept> +#include <algorithm> +#include <functional> +#include <iterator> class option_base { @@ -31,6 +35,7 @@ shortname( _short_var ), longname( _long_var ), desc( _description ), + token( _count++ ), has_arg( false ) { } @@ -38,6 +43,7 @@ shortname( _short_var ), longname(), desc( _description ), + token( _count++ ), has_arg( false ) { } @@ -45,11 +51,12 @@ shortname( 0 ), longname( _long_var ), desc( _description ), + token( _count++ ), has_arg( false ) { } - option_base& operator []( const std::string& d ) - { default_v = d; has_arg = true; } + virtual ~option_base() + { } bool operator ==( const std::string& _longname ) const { return longname == _longname; } @@ -58,31 +65,300 @@ bool operator ==( int _token ) const { return token == _token; } - private: + virtual const std::type_info& type() const = 0; + + template <class T> + bool assign( T& v ) const + { + if ( this->type() != typeid(T) ) { + throw std::invalid_argument( "types mismatch" ); + } + return _assign( static_cast<void*>(&v) ); + } + + protected: + virtual void read( const char* str ) = 0; + virtual void read( const std::string& str ) = 0; + virtual bool _assign( void* ) const = 0; + virtual std::ostream& _describe( std::ostream& ) const = 0; + char shortname; std::string longname; std::string desc; - std::string default_v; int token; - - std::vector< std::string > args; - std::vector< int > pos; + protected: + std::vector<int> pos; + bool has_arg; - friend std::ostream& operator <<( std::ostream& t, const option_base& opt ); + // friend std::ostream& operator <<( std::ostream& t, const option_base& opt ); friend class Opts; + + private: + static int _count; }; +namespace detail { + +template <class P, class V> +class deref_equal : + public std::binary_function<P,V,bool> +{ + public: + bool operator()(const P& __x, const V& __y) const + { return *__x == __y; } +}; + +} // namespace detail + +template <class T> +class option : + public option_base +{ + public: + option( const char* _description, char _short_var, const char* _long_var ) : + option_base( _description, _short_var, _long_var ) + { } + + option( const char* _description, char _short_var ) : + option_base( _description, _short_var ) + { } + + option( const char* _description, const char* _long_var ) : + option_base( _description, _long_var ) + { } + + virtual const std::type_info& type() const + { return typeid( T ); } + + option<T>& operator []( const T& val ) + { args.push_back( val ); has_arg = true; return *this; } + + template <class BackInstertIterator> + void get( BackInstertIterator bi ) const + { std::copy( args.begin(), args.end(), bi ); } + + protected: + virtual std::ostream& _describe( std::ostream& o ) const; + + virtual bool _assign( void* v ) const + { + if ( args.empty() ) { + // throw + } + *reinterpret_cast<T*>(v) = args.front(); + + return !pos.empty(); + } + + private: + std::list<T> args; + + void read( const char *str ) throw (std::invalid_argument) + { + std::istringstream s( str ); + T _v; + if ( !(s >> _v).fail() ) { + if ( has_arg && args.size() == 1 && pos.size() == 0 ) { // override default value + args.front() = _v; + } else { + args.push_back( _v ); + } + } else { + throw std::invalid_argument( str ); + } + } + + void read( const std::string& str ) throw (std::invalid_argument) + { + std::istringstream s( str ); + T _v; + if ( !(s >> _v).fail() ) { + if ( has_arg && args.size() == 1 && pos.size() == 0 ) { // override default value + args.front() = _v; + } else { + args.push_back( _v ); + } + } else { + throw std::invalid_argument( str ); + } + } + + friend class Opts; +}; + +template <class T> +std::ostream& option<T>::_describe( std::ostream& out ) const +{ + if ( option_base::shortname != 0 ) { + out << '-' << option_base::shortname; + if ( option_base::has_arg ) { + out << " <" << typeid(T).name() << ">"; + } + if ( !option_base::longname.empty() ) { + out << ", "; + } + } + + if ( !option_base::longname.empty() ) { + out << "--" << option_base::longname; + if ( option_base::has_arg ) { + out << "=<" << typeid(T).name() << ">"; + } + } + + if ( option_base::has_arg ) { + out << " [" << args.front() << "]\t"; + } else { + out << '\t'; + } + + return out << option_base::desc; +} + +template <> +class option<std::string> : + public option_base +{ + public: + option( const char* _description, char _short_var, const char* _long_var ) : + option_base( _description, _short_var, _long_var ) + { } + + option( const char* _description, char _short_var ) : + option_base( _description, _short_var ) + { } + + option( const char* _description, const char* _long_var ) : + option_base( _description, _long_var ) + { } + + virtual const std::type_info& type() const + { return typeid( std::string ); } + + option<std::string>& operator []( const char* val ) + { args.push_back( std::string(val) ); has_arg = true; return *this; } + + option<std::string>& operator []( const std::string& val ) + { args.push_back( val ); has_arg = true; return *this; } + + template <class BackInstertIterator> + void get( BackInstertIterator bi ) const + { std::copy( args.begin(), args.end(), bi ); } + + protected: + virtual std::ostream& _describe( std::ostream& o ) const; + + virtual bool _assign( void* v ) const + { + if ( args.empty() ) { + // throw + } + *reinterpret_cast<std::string*>(v) = args.front(); + + return !pos.empty(); + } + + private: + std::list<std::string> args; + + void read( const char *str ) + { + if ( has_arg && args.size() == 1 && pos.size() == 0 ) { // override default value + args.front() = str; + } else { + args.push_back( std::string( str ) ); + } + } + + void read( const std::string& str ) + { + if ( has_arg && args.size() == 1 && pos.size() == 0 ) { // override default value + args.front() = str; + } else { + args.push_back( str ); + } + } + + friend class Opts; +}; + +template <> +class option<char*> : + public option_base +{ + public: + option( const char* _description, char _short_var, const char* _long_var ) : + option_base( _description, _short_var, _long_var ) + { } + + option( const char* _description, char _short_var ) : + option_base( _description, _short_var ) + { } + + option( const char* _description, const char* _long_var ) : + option_base( _description, _long_var ) + { } + + virtual const std::type_info& type() const + { return typeid( std::string ); } + + option<char*>& operator []( const char* val ) + { args.push_back( std::string(val) ); has_arg = true; return *this; } + + option<char*>& operator []( const std::string& val ) + { args.push_back( val ); has_arg = true; return *this; } + + template <class BackInstertIterator> + void get( BackInstertIterator bi ) const + { std::copy( args.begin(), args.end(), bi ); } + + protected: + virtual std::ostream& _describe( std::ostream& o ) const; + + virtual bool _assign( void* v ) const + { + if ( args.empty() ) { + // throw + } + *reinterpret_cast<std::string*>(v) = args.front(); + + return !pos.empty(); + } + + private: + std::list<std::string> args; + + void read( const char *str ) + { + if ( has_arg && args.size() == 1 && pos.size() == 0 ) { // override default value + args.front() = str; + } else { + args.push_back( std::string( str ) ); + } + } + + void read( const std::string& str ) + { + if ( has_arg && args.size() == 1 && pos.size() == 0 ) { // override default value + args.front() = str; + } else { + args.push_back( str ); + } + } + + friend class Opts; +}; + class Opts { private: - typedef std::vector< option_base > options_container_type; - options_container_type storage; + typedef std::vector< option_base* > options_container_type; + options_container_type storage; public: - Opts() : - free_token(0) + Opts() { } void description( const char* text ) @@ -97,46 +373,51 @@ void copyright( const char* text ) { _copyright = text; } - // adding option / flag (option that doesn't need arguments) - template <class T> - int add( const std::string& _longname,T _default_value,const std::string& _desc = "(no decription)" ); template <class T> - int add( char _shortname,T _default_value,const std::string& _longname = "(no longname)", const std::string& _desc = "(no decription)" ); + Opts& operator << ( const option<T>& o ) + { + storage.push_back( new option<T>( o ) ); + return *this; + } - int addflag( const std::string& _longname = "(no longname)",const std::string& desc = "(no decription)"); - - int addflag( char _shortname,const std::string& _longname = "(no longname)",const std::string& _desc = "(no decription)" ); - // getting option - template < class T ,class V > - T get( V field ); - - - template < class V > - std::string get( V field ); - + template <class T ,class V> + T get( const V& field, const T& ); - template <class T , class V> - T get_default( V field ); + template <class T, class V> + T get( const V& field ); - template < class V > - std::string get_default( V field ); + template <class BackInsertIterator> + void getemall( char field , BackInsertIterator bi ); + template <class BackInsertIterator> + void getemall( const std::string& field , BackInsertIterator bi ); + template <class BackInsertIterator> + void getemall( int field , BackInsertIterator bi ); - template < class V , class BackInsertIterator> - void getemall( V field , BackInsertIterator bi); + bool is_set( char field ) const; + bool is_set( const char* field ) const + { return is_set( std::string(field) ); } + bool is_set( const std::string& field ) const; + bool is_set( int field ) const; + int get_cnt( char field ) const; + int get_cnt( const char* field ) const + { return get_cnt( std::string(field) ); } + int get_cnt( const std::string& field ) const; + int get_cnt( int field ) const; - template < class T > - bool is_set( T field ) const; + template <class BackInsertIterator> + void get_pos( char, BackInsertIterator bi); + template <class BackInsertIterator> + void get_pos( const char* f, BackInsertIterator bi) + { get_pos( std::string(f), bi ); } + template <class BackInsertIterator> + void get_pos( const std::string&, BackInsertIterator bi); + template <class BackInsertIterator> + void get_pos( int, BackInsertIterator bi); - template < class T > - int get_cnt( T field ) const; - - template < class V , class BackInsertIterator > - void get_pos( V field , BackInsertIterator bi); - // parse void parse(int& ac, const char** av); @@ -169,9 +450,10 @@ { } }; + int last_token() const + { return storage.empty() ? -1 : storage.back()->token; } + private: - int free_token; - std::string pname; std::string _brief; std::string _usage; @@ -182,65 +464,39 @@ bool is_opt_name( const std::string& s ); bool is_flag_group( const std::string& s ); bool is_substr(const std::string& small, const std::string& big ); - options_container_type::iterator get_opt_index( std::string s ); + options_container_type::const_iterator get_opt_index( const std::string& s ); }; -template <class T> -int Opts::add(char _shortname,T _default_value,const std::string& _longname,const std::string& _desc) +template < class T , class V > +T Opts::get( const V& field, const T& ) { - addflag(_shortname,_longname,_desc); - std::stringstream ss; - ss << _default_value; - storage[storage.size() - 1][ss.str()]; - return storage[storage.size() - 1].token; -} + options_container_type::const_iterator i = + std::find_if( storage.begin(), storage.end(), + std::bind2nd( detail::deref_equal<option_base*,V>(), field ) ); -template <class T> -int Opts::add(const std::string& _longname,T _default_value,const std::string& _desc) -{ - addflag(_longname,_desc); - std::stringstream ss; - ss << _default_value; - storage[storage.size() - 1][ss.str()]; - return storage[storage.size() - 1].token; -} - -template <class T> -bool Opts::is_set(T field) const -{ - options_container_type::const_iterator i = std::find( storage.begin(), storage.end(), field ); - return ( (i == storage.end()) ? false : !i->pos.empty()); -} - -template <class T> -int Opts::get_cnt(T field) const -{ - options_container_type::const_iterator i = std::find( storage.begin(), storage.end(), field ); - return ( (i == storage.end()) ? 0 : i->pos.size()); -} - -template <class V> -std::string Opts::get( V field ) -{ - options_container_type::const_iterator i = std::find( storage.begin(), storage.end(), field ); - if ( i == storage.end() ) { std::stringstream ss1; ss1 << field; - throw unknown_option( ss1.str() ); + throw unknown_option( ss1.str() ); } - if ( !i->has_arg ) { + if ( !(*i)->has_arg ) { throw std::logic_error("using Opts::get for option without arguments"); } - return i->args.empty() ? i->default_v : i->args[0]; + T res; + + (*i)->assign( res ); + + return res; } template < class T , class V > -T Opts::get( V field ) +T Opts::get( const V& field ) { - options_container_type::const_iterator i = std::find(storage.begin(), storage.end() ,field); + options_container_type::const_iterator i = + std::find_if( storage.begin(), storage.end(), + std::bind2nd( detail::deref_equal<option_base*,V>(), field ) ); if ( i == storage.end() ) { std::stringstream ss1; @@ -248,73 +504,71 @@ throw unknown_option( ss1.str() ); } - if ( !i->has_arg ) { + if ( !(*i)->has_arg ) { throw std::logic_error("using Opts::get for option without arguments"); } T res; - std::stringstream ss(i->args.empty() ? i->default_v : i->args[0]); - ss >> res; - if ( ss.fail() ) { - std::stringstream ss1; - ss1 << field; - throw arg_typemismatch(ss1.str(),i->args.empty() ? i->default_v : i->args[0]); - } + (*i)->assign( res ); return res; } -template < class V> -std::string Opts::get_default( V field ) +template <class BackInsertIterator> +void Opts::getemall( char field, BackInsertIterator bi ) { - options_container_type::const_iterator i = std::find( storage.begin(), storage.end(), field ); + options_container_type::const_iterator i = + std::find_if( storage.begin(), storage.end(), + std::bind2nd( detail::deref_equal<option_base*,char>(), field ) ); if ( i == storage.end() ) { std::stringstream ss1; ss1 << field; - throw unknown_option( ss1.str() ); + throw unknown_option(ss1.str()); } - if ( !i->has_arg ) { - throw std::logic_error("using Opts::get for option without arguments"); + if ( !(*i)->has_arg ) { + throw std::logic_error("using Opts::getemall for option without arguments"); } - - return i->default_v; + + typedef typename BackInsertIterator::container_type::value_type real_type; + + option<real_type>* opt = dynamic_cast< option<real_type> * >( *i ); + + opt->get( bi ); } -template <class T , class V> -T Opts::get_default( V field ) +template <class BackInsertIterator> +void Opts::getemall( const std::string& field, BackInsertIterator bi ) { - options_container_type::const_iterator i = std::find( storage.begin(), storage.end(), field ); + options_container_type::const_iterator i = + std::find_if( storage.begin(), storage.end(), + std::bind2nd( detail::deref_equal<option_base*,std::string>(), field ) ); if ( i == storage.end() ) { std::stringstream ss1; ss1 << field; - throw unknown_option( ss1.str() ); + throw unknown_option(ss1.str()); } - if ( !i->has_arg ) { - throw std::logic_error("using Opts::get for option without arguments"); + if ( !(*i)->has_arg ) { + throw std::logic_error("using Opts::getemall for option without arguments"); } - - T res; - std::stringstream ss(i->default_v); - ss >> res; - if ( ss.fail() ) { - std::stringstream ss1; - ss1 << field; - throw arg_typemismatch(ss1.str(),i->default_v); - } + typedef typename BackInsertIterator::container_type::value_type real_type; - return res; + option<real_type>* opt = dynamic_cast< option<real_type> * >( *i ); + + opt->get( bi ); } -template <class V , class BackInsertIterator> -void Opts::getemall( V field , BackInsertIterator bi) +template <class BackInsertIterator> +void Opts::getemall( int field, BackInsertIterator bi ) { - options_container_type::const_iterator i = std::find( storage.begin(), storage.end(), field ); + options_container_type::const_iterator i = + std::find_if( storage.begin(), storage.end(), + std::bind2nd( detail::deref_equal<option_base*,int>(), field ) ); if ( i == storage.end() ) { std::stringstream ss1; @@ -322,28 +576,39 @@ throw unknown_option(ss1.str()); } - if ( !i->has_arg ) { + if ( !(*i)->has_arg ) { throw std::logic_error("using Opts::getemall for option without arguments"); } - - if ( !i->args.empty() ) { - for ( int j = 0; j < i->args.size(); ++j) { - std::stringstream ss(i->args[j]); - ss >> *bi++; - if ( ss.fail() ) { - std::stringstream ss1; - ss1 << field; - throw arg_typemismatch(ss1.str(),i->args[j]); - } - } + typedef typename BackInsertIterator::container_type::value_type real_type; + + option<real_type>* opt = dynamic_cast< option<real_type> * >( *i ); + + opt->get( bi ); +} + +template <class BackInsertIterator> +void Opts::get_pos( char field , BackInsertIterator bi ) +{ + options_container_type::const_iterator i = + std::find_if( storage.begin(), storage.end(), + std::bind2nd( detail::deref_equal<option_base*,char>(), field ) ); + + if ( i == storage.end() ) { + std::stringstream ss1; + ss1 << field; + throw unknown_option(ss1.str()); } + + std::copy( (*i)->pos.begin(), (*i)->pos.end(), bi ); } -template <class V , class BackInsertIterator> -void Opts::get_pos( V field , BackInsertIterator bi) +template <class BackInsertIterator> +void Opts::get_pos( const std::string& field, BackInsertIterator bi ) { - options_container_type::const_iterator i = std::find( storage.begin(), storage.end(), field ); + options_container_type::const_iterator i = + std::find_if( storage.begin(), storage.end(), + std::bind2nd( detail::deref_equal<option_base*,std::string>(), field ) ); if ( i == storage.end() ) { std::stringstream ss1; @@ -351,7 +616,23 @@ throw unknown_option(ss1.str()); } - std::copy( i->pos.begin(), i->pos.end(), bi ); + std::copy( (*i)->pos.begin(), (*i)->pos.end(), bi ); } +template <class BackInsertIterator> +void Opts::get_pos( int field, BackInsertIterator bi ) +{ + options_container_type::const_iterator i = + std::find_if( storage.begin(), storage.end(), + std::bind2nd( detail::deref_equal<option_base*,int>(), field ) ); + + if ( i == storage.end() ) { + std::stringstream ss1; + ss1 << field; + throw unknown_option(ss1.str()); + } + + std::copy( (*i)->pos.begin(), (*i)->pos.end(), bi ); +} + #endif // __OPTS_H__ Modified: trunk/complement/explore/lib/exam/ut/exam_self_test.cc =================================================================== --- trunk/complement/explore/lib/exam/ut/exam_self_test.cc 2008-06-29 21:48:10 UTC (rev 1927) +++ trunk/complement/explore/lib/exam/ut/exam_self_test.cc 2008-06-29 21:48:33 UTC (rev 1928) @@ -1,7 +1,7 @@ -// -*- C++ -*- Time-stamp: <07/09/01 09:10:26 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 01:27:58 ptr> /* - * Copyright (c) 2007 + * Copyright (c) 2007, 2008 * Petr Ovtchenkov * * Licensed under the Academic Free License Version 3.0 @@ -14,15 +14,8 @@ using namespace std; -int main( int argc,const char** argv) +int main( int argc, const char** argv ) { - // exam::test_suite t( "exam self test" ); - // t.add( exam_self_test, "exam self test suite" ); - // - // return t.girdle(); - - // return exam_self_test(0); - exam::test_suite t( "exam self test" ); exam_basic_test exam_basic; @@ -40,12 +33,15 @@ Opts opts; - opts.addflag( 'h', "help", "print this help message" ); - opts.addflag( 'l', "list", "list all test cases" ); - opts.add( 'r', 0, "run", "run tests by number" ); - opts.addflag( 'v', "verbose", "print status of tests within test suite" ); - opts.addflag( 't', "trace", "trace checks" ); + opts.description( "test suite for 'exam' 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 ); } @@ -73,7 +69,7 @@ } if ( opts.is_set( 'r' ) ) { - stringstream ss( opts.get( 'r' ) ); + stringstream ss( opts.get<string>( 'r' ) ); int n; while ( ss >> n ) { t.single( n ); @@ -84,4 +80,3 @@ return t.girdle(); } - Modified: trunk/complement/explore/lib/misc/ChangeLog =================================================================== --- trunk/complement/explore/lib/misc/ChangeLog 2008-06-29 21:48:10 UTC (rev 1927) +++ trunk/complement/explore/lib/misc/ChangeLog 2008-06-29 21:48:33 UTC (rev 1928) @@ -1,3 +1,11 @@ +2008-06-30 Petr Ovtchenkov <pt...@is...> + + * opts.h, opts.cc: revision of options framework; + insert object with type and type check into option; + default value passed via [] operator; + + * libmisc: version 1.10.0. + 2008-06-16 Petr Ovtchenkov <ye...@ya...> * opts.cc, opts.h: options parser, by Dmitry Osmakov. Modified: trunk/complement/explore/lib/misc/Makefile.inc =================================================================== --- trunk/complement/explore/lib/misc/Makefile.inc 2008-06-29 21:48:10 UTC (rev 1927) +++ trunk/complement/explore/lib/misc/Makefile.inc 2008-06-29 21:48:33 UTC (rev 1928) @@ -1,4 +1,4 @@ -# -*- Makefile -*- Time-stamp: <02/08/01 09:27:30 ptr> +# -*- Makefile -*- Time-stamp: <08/06/30 01:39:17 ptr> # I have only one reason while I should use "C++" variant of MD5 instead of "C": # names like MD5Init is wide distributed, but some cool programmers use this @@ -9,7 +9,7 @@ LIBNAME = misc MAJOR = 1 -MINOR = 9 -PATCH = 1 +MINOR = 10 +PATCH = 0 SRC_CC = CyrMoney.cc args.cc arguments.cc opts.cc SRC_C = md5.c Modified: trunk/complement/explore/lib/misc/opts.cc =================================================================== --- trunk/complement/explore/lib/misc/opts.cc 2008-06-29 21:48:10 UTC (rev 1927) +++ trunk/complement/explore/lib/misc/opts.cc 2008-06-29 21:48:33 UTC (rev 1928) @@ -1,10 +1,10 @@ -// -*- C++ -*- Time-stamp: <08/06/29 13:05:13 ptr> +// -*- C++ -*- Time-stamp: <08/06/29 22:38:24 ptr> /* * Copyright (c) 2008 * Dmitry Osmakov * - * Copyright (c) 2008 + * Copyright (c) 1997-1998, 2001, 2008 * Petr Ovtchenkov * * Licensed under the Academic Free License Version 3.0 @@ -21,22 +21,106 @@ using namespace std; -ostream& operator <<( ostream& out, const option_base& opt ) +int option_base::_count = 0; + +std::ostream& option<string>::_describe( std::ostream& out ) const { - if ( opt.shortname != 0 ) { - out << '-' << opt.shortname << (opt.has_arg ? " <val>" : "" ); - if ( !opt.longname.empty() ) { + if ( option_base::shortname != 0 ) { + out << '-' << option_base::shortname << " <string>"; + if ( !option_base::longname.empty() ) { out << ", "; } } + + if ( !option_base::longname.empty() ) { + out << "--" << option_base::longname << "=<string>"; + } - if ( !opt.longname.empty() ) { - out << "--" << opt.longname << (opt.has_arg ? "=<val>" : "" ); + if ( option_base::has_arg ) { + out << " [" << args.front() << "]\t"; + } else { + out << '\t'; } - return out << (opt.has_arg ? (string(" [") + opt.default_v + "]\t") : "\t" ) << opt.desc; + return out << option_base::desc; } +std::ostream& option<char*>::_describe( std::ostream& out ) const +{ + if ( option_base::shortname != 0 ) { + out << '-' << option_base::shortname << " <string>"; + if ( !option_base::longname.empty() ) { + out << ", "; + } + } + + if ( !option_base::longname.empty() ) { + out << "--" << option_base::longname << "=<string>"; + } + + if ( option_base::has_arg ) { + out << " [" << args.front() << "]\t"; + } else { + out << '\t'; + } + + return out << option_base::desc; +} + +bool Opts::is_set( char field ) const +{ + options_container_type::const_iterator i = + std::find_if( storage.begin(), storage.end(), + std::bind2nd( detail::deref_equal<option_base*,char>(), field ) ); + + return ( (i == storage.end()) ? false : !(*i)->pos.empty()); +} + +bool Opts::is_set( const std::string& field ) const +{ + options_container_type::const_iterator i = + std::find_if( storage.begin(), storage.end(), + std::bind2nd( detail::deref_equal<option_base*,std::string>(), field ) ); + + return ( (i == storage.end()) ? false : !(*i)->pos.empty()); +} + +bool Opts::is_set( int field ) const +{ + options_container_type::const_iterator i = + std::find_if( storage.begin(), storage.end(), + std::bind2nd( detail::deref_equal<option_base*,int>(), field ) ); + + return ( (i == storage.end()) ? false : !(*i)->pos.empty()); +} + +int Opts::get_cnt( char field ) const +{ + options_container_type::const_iterator i = + std::find_if( storage.begin(), storage.end(), + std::bind2nd( detail::deref_equal<option_base*,char>(), field ) ); + + return ( (i == storage.end()) ? 0 : (*i)->pos.size()); +} + +int Opts::get_cnt( const std::string& field ) const +{ + options_container_type::const_iterator i = + std::find_if( storage.begin(), storage.end(), + std::bind2nd( detail::deref_equal<option_base*,std::string>(), field ) ); + + return ( (i == storage.end()) ? 0 : (*i)->pos.size()); +} + +int Opts::get_cnt( int field ) const +{ + options_container_type::const_iterator i = + std::find_if( storage.begin(), storage.end(), + std::bind2nd( detail::deref_equal<option_base*,int>(), field ) ); + + return ( (i == storage.end()) ? 0 : (*i)->pos.size()); +} + string Opts::get_pname() const { return pname; } bool Opts::is_opt_name(const string& s) @@ -71,37 +155,38 @@ } // this function assumes that is_opt_name(s) = true; -Opts::options_container_type::iterator Opts::get_opt_index(string s) +Opts::options_container_type::const_iterator Opts::get_opt_index( const string& s) { assert(is_opt_name(s)); - if (s.size() == 2 && isalnum(s[1]) ) // is short name - { - options_container_type::iterator i; - for (i = storage.begin();i != storage.end();++i) - if (i->shortname == s[1]) + if (s.size() == 2 && isalnum(s[1]) ) { // is short name + options_container_type::const_iterator i = storage.begin(); + for ( ; i != storage.end(); ++i ) { + if ( (*i)->shortname == s[1]) { break; + } + } return i; } - if (s.size() > 2 && s[1] == '-') - { - options_container_type::iterator i; - s = s.substr(2); + if (s.size() > 2 && s[1] == '-') { + options_container_type::const_iterator i; + string tmp = s.substr(2); // exact match - for (i = storage.begin();i != storage.end();++i) - if (i->longname == s) + for ( i = storage.begin(); i != storage.end(); ++i ) { + if ( (*i)->longname == tmp ) { return i; + } + } - vector< options_container_type::iterator > matches; - for (i = storage.begin();i != storage.end();++i) - if (is_substr(s,i->longname)) + vector< options_container_type::const_iterator > matches; + for ( i = storage.begin();i != storage.end();++i ) { + if ( is_substr( tmp, (*i)->longname ) ) { matches.push_back(i); + } + } - if (matches.size() == 1) - return matches[0]; - else - return storage.end(); + return matches.size() == 1 ? matches[0] : storage.end(); } return storage.end(); @@ -129,32 +214,12 @@ out << "\nOptions:\n\n"; for ( options_container_type::const_iterator i = storage.begin(); i != storage.end(); ++i) { - out << *i << "\n"; + (*i)->_describe( out ) << '\n'; } } out << endl; } -int Opts::addflag( char _shortname, const string& _longname, const string& _desc ) -{ - option_base opt( _desc.c_str(), _shortname, _longname.c_str() ); - - opt.has_arg = false; - opt.token = ++free_token; - storage.push_back(opt); - return opt.token; -} - -int Opts::addflag( const string& _longname, const string& _desc ) -{ - option_base opt( _desc.c_str(), _longname.c_str() ); - - opt.has_arg = false; - opt.token = ++free_token; - storage.push_back(opt); - return opt.token; -} - void Opts::parse( int& ac, const char** av ) { pname = av[0]; @@ -168,41 +233,41 @@ string opt = av[i]; string arg; - int k = opt.find( "=" ); + string::size_type k = opt.find( "=" ); if ( k != string::npos ) { arg = opt.substr( k + 1 ); opt = opt.substr( 0, k ); } - options_container_type::iterator p = get_opt_index(opt); + options_container_type::const_iterator p = get_opt_index(opt); if ( p == storage.end() ) { throw unknown_option(opt); } - p->pos.push_back(++q); - if ( p->has_arg ) { + if ( (*p)->has_arg ) { if ( !arg.empty() ) { - p->args.push_back(arg); + (*p)->read(arg); } else { if ( (i + 1) >= ac ) { throw missing_arg(opt); } - p->args.push_back(av[++i]); + (*p)->read( av[++i] ); } } else if ( !arg.empty() ) { //unexpected arg (not exactly mismatch) throw arg_typemismatch(opt,arg); } + (*p)->pos.push_back(++q); } else if ( is_flag_group(av[i]) ) { string optgroup = av[i]; for ( int j = 1; j < optgroup.size(); j++ ) { - options_container_type::iterator p = get_opt_index(string("-") + optgroup[j]); + options_container_type::const_iterator p = get_opt_index(string("-") + optgroup[j]); if ( p == storage.end() ) { throw unknown_option( "-" + string(1,optgroup[j]) ); } - p->pos.push_back(++q); - if ( p->has_arg ) { + (*p)->pos.push_back(++q); + if ( (*p)->has_arg ) { throw missing_arg( "-" + string(1,optgroup[j]) ); } } Modified: trunk/complement/explore/lib/misc/ut/Makefile =================================================================== --- trunk/complement/explore/lib/misc/ut/Makefile 2008-06-29 21:48:10 UTC (rev 1927) +++ trunk/complement/explore/lib/misc/ut/Makefile 2008-06-29 21:48:33 UTC (rev 1928) @@ -1,4 +1,4 @@ -# -*- Makefile -*- Time-stamp: <08/06/12 15:20:10 ptr> +# -*- Makefile -*- Time-stamp: <08/06/29 19:26:11 ptr> SRCROOT := ../../.. @@ -11,15 +11,16 @@ LIBEXAM_DIR = ${CoMT_DIR}/lib/exam LIBXMT_DIR = ${CoMT_DIR}/lib/mt +LIBMISC_DIR = ${CoMT_DIR}/lib/misc ifeq ($(OSNAME),linux) -release-shared: LDFLAGS += -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L${LIBXMT_DIR}/${OUTPUT_DIR} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR}:${LIBXMT_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} +release-shared: LDFLAGS += -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L${LIBXMT_DIR}/${OUTPUT_DIR} -L${LIBMISC_DIR}/${OUTPUT_DIR} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR}:${LIBXMT_DIR}/${OUTPUT_DIR}:${LIBMISC_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} -dbg-shared: LDFLAGS += -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L${LIBXMT_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:${LIBXMT_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} +dbg-shared: LDFLAGS += -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L${LIBXMT_DIR}/${OUTPUT_DIR_DBG} -L${LIBMISC_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:${LIBXMT_DIR}/${OUTPUT_DIR_DBG}:${LIBMISC_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} ifndef WITHOUT_STLPORT -stldbg-shared: LDFLAGS += -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBXMT_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBXMT_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} +stldbg-shared: LDFLAGS += -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBXMT_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBMISC_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBXMT_DIR}/${OUTPUT_DIR_STLDBG}:${LIBMISC_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} endif endif @@ -34,10 +35,10 @@ endif -release-shared : LDLIBS = -lexam -lxmt -dbg-shared : LDLIBS = -lexamg -lxmtg +release-shared : LDLIBS = -lexam -lxmt -lmisc +dbg-shared : LDLIBS = -lexamg -lxmtg -lmiscg ifndef WITHOUT_STLPORT -stldbg-shared : LDLIBS = -lexamstlg -lxmtstlg +stldbg-shared : LDLIBS = -lexamstlg -lxmtstlg -lmiscstlg endif ifeq ($(OSNAME),freebsd) Modified: trunk/complement/explore/lib/misc/ut/Makefile.inc =================================================================== --- trunk/complement/explore/lib/misc/ut/Makefile.inc 2008-06-29 21:48:10 UTC (rev 1927) +++ trunk/complement/explore/lib/misc/ut/Makefile.inc 2008-06-29 21:48:33 UTC (rev 1928) @@ -1,7 +1,6 @@ -# -*- makefile -*- Time-stamp: <08/05/01 12:00:01 ptr> +# -*- makefile -*- Time-stamp: <08/06/29 19:23:01 ptr> PRGNAME = misc_ut SRC_CC = unit_test.cc \ misc_test.cc misc_test_suite.cc opts_test.cc -SRC_CPP = ../opts.cpp Modified: trunk/complement/explore/lib/misc/ut/misc_test_suite.cc =================================================================== --- trunk/complement/explore/lib/misc/ut/misc_test_suite.cc 2008-06-29 21:48:10 UTC (rev 1927) +++ trunk/complement/explore/lib/misc/ut/misc_test_suite.cc 2008-06-29 21:48:33 UTC (rev 1928) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/05/21 12:30:07 yeti> +// -*- C++ -*- Time-stamp: <08/06/30 01:37:00 ptr> /* * Copyright (c) 2007, 2008 @@ -65,45 +65,49 @@ opts_test opts; - t.add( &opts_test::bool_option_long, opts, "simple boolean option, long" , + exam::test_suite::test_case_type tc[10]; + + tc[0] = + t.add( &opts_test::bool_option_long, opts, "simple boolean option, long" , t.add( &opts_test::bool_option, opts, "simple boolean option" ) ); - t.add( &opts_test::int_option_long, opts, "option with int parameter, long", + tc[1] = + t.add( &opts_test::int_option_long, opts, "option with int parameter, long", t.add( &opts_test::int_option, opts, "option with int parameter" ) ); - t.add( &opts_test::add_check_flag , opts , "add_check_flag"); - t.add( &opts_test::add_get_opt , opts , "add_get_opts"); - t.add( &opts_test::option_position,opts,"option position"); + t.add( &opts_test::add_check_flag, opts, "add_check_flag", tc[0] ); + t.add( &opts_test::add_get_opt, opts, "add_get_opts", tc[1] ); + t.add( &opts_test::option_position, opts, "option position", tc[0] ); - t.add( &opts_test::defaults, opts, "defaults" ); + t.add( &opts_test::defaults, opts, "defaults", tc[1] ); - t.add( &opts_test::bad_option, opts, "bad option" ); - t.add( &opts_test::bad_argument, opts, "bad argument" ); - t.add( &opts_test::unexpected_argument, opts, "unexpected_argument" ); - t.add( &opts_test::missing_argument, opts, "missing argument" ); + t.add( &opts_test::bad_option, opts, "bad option", tc[0] ); + t.add( &opts_test::bad_argument, opts, "bad argument", tc[1] ); + t.add( &opts_test::unexpected_argument, opts, "unexpected_argument", tc[0] ); + t.add( &opts_test::missing_argument, opts, "missing argument", tc[1] ); t.add( &opts_test::user_defined, opts, "user-defined type" ); - t.add( &opts_test::compound, opts, "compound" ); + tc[2] = t.add( &opts_test::compound, opts, "compound", tc[0] ); - t.add( &opts_test::multiple, opts,"multiple"); + tc[3] = t.add( &opts_test::multiple, opts, "multiple", tc[0] ); - t.add( &opts_test::multiple_compound, opts,"multiple_compound"); + t.add( &opts_test::multiple_compound, opts, "multiple_compound", tc + 2, tc + 4 ); - t.add( &opts_test::args, opts,"args"); + t.add( &opts_test::args, opts, "args" ); - t.add( &opts_test::stop, opts,"stop"); + t.add( &opts_test::stop, opts, "stop", tc, tc + 2 ); // check whether autocomplement works - t.add( &opts_test::autocomplement, opts,"autocomplement"); - t.add( &opts_test::autocomplement_failure, opts,"autocomplement_failure"); + tc[4] = t.add( &opts_test::autocomplement, opts, "autocomplement", tc[1] ); + t.add( &opts_test::autocomplement_failure, opts, "autocomplement_failure", tc[4] ); - t.add( &opts_test::multiple_args, opts,"multiple_args"); + t.add( &opts_test::multiple_args, opts, "multiple_args", tc[3] ); - t.add( &opts_test::help, opts, "help"); + t.add( &opts_test::help, opts, "help", tc, tc + 2 ); - t.add( &opts_test::long_string, opts, "long string"); + t.add( &opts_test::long_string, opts, "long string" ); return t.girdle(); } Modified: trunk/complement/explore/lib/misc/ut/opts_test.cc =================================================================== --- trunk/complement/explore/lib/misc/ut/opts_test.cc 2008-06-29 21:48:10 UTC (rev 1927) +++ trunk/complement/explore/lib/misc/ut/opts_test.cc 2008-06-29 21:48:33 UTC (rev 1928) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/29 13:18:16 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 01:10:34 ptr> /* * Copyright (c) 2008 @@ -17,7 +17,6 @@ #include <set> #include <vector> #include <list> -#include <fstream> #include <iostream> using namespace std; @@ -29,7 +28,7 @@ Opts opts; - opts.addflag( 'h', "help", "print this help message" ); + opts << option<bool>( "print this help message", 'h', "help" ); try { opts.parse( argc, argv ); @@ -40,6 +39,8 @@ } catch ( const Opts::arg_typemismatch& e ) { } + catch ( const std::invalid_argument& e ) { + } return EXAM_RESULT; } @@ -51,7 +52,7 @@ Opts opts; - opts.addflag( 'h', "help", "print this help message" ); + opts << option<bool>( "print this help message", 'h', "help" ); try { opts.parse( argc, argv ); @@ -62,6 +63,8 @@ } catch ( const Opts::arg_typemismatch& e ) { } + catch ( const std::invalid_argument& e ) { + } return EXAM_RESULT; } @@ -74,7 +77,7 @@ Opts opts; - opts.add( 'p', 0,"port", "listen tcp port"); + opts << option<int>( "listen tcp port", 'p', "port" )[0]; try { opts.parse( argc, argv ); @@ -97,7 +100,7 @@ Opts opts; - opts.add( 'p', 0, "port", "listen tcp port"); + opts << option<int>( "listen tcp port", 'p', "port" )[0]; try { opts.parse( argc, argv ); @@ -110,6 +113,8 @@ } catch ( const Opts::arg_typemismatch& e ) { } + catch ( const std::invalid_argument& e ) { + } return EXAM_RESULT; } @@ -121,11 +126,15 @@ Opts opts; - int f_token = opts.addflag('f'); - opts.addflag('t',"tag"); - int foo_token = opts.addflag("foo"); - opts.addflag("temp","temp desc"); - int h_token = opts.addflag( 'h', "help", "print this help message" ); + int f_token = (opts << option<bool>( "", 'f' )).last_token(); + + opts << option<bool>( "", 't', "tag" ); + + int foo_token = (opts << option<bool>( "", "foo" ) ).last_token(); + + opts << option<bool>( "temp desc", "temp" ); + + int h_token = ( opts << option<bool>( "print this help message", 'h', "help" ) ).last_token(); bool exception_happens = false; try { @@ -137,6 +146,10 @@ } catch ( const Opts::arg_typemismatch& e ) { } + catch ( const std::invalid_argument& e ) { + } + catch ( ... ) { + } EXAM_CHECK( !opts.is_set("foo") ); EXAM_CHECK( !opts.is_set(foo_token) ); @@ -146,40 +159,36 @@ EXAM_CHECK( opts.is_set('t')); EXAM_CHECK( opts.is_set("temp") ); EXAM_CHECK( !opts.is_set("unknow option") ); - EXAM_CHECK( !opts.is_set(42) ); + EXAM_CHECK( !opts.is_set(h_token+1) ); - try - { + try { opts.get<int>('f'); } - catch(const logic_error& e) - { + catch(const logic_error& e) { exception_happens = true; } EXAM_CHECK( exception_happens ); - exception_happens = false; - try - { - opts.get_default<int>("tag"); - } - catch(const logic_error& e) - { - exception_happens = true; - } +// exception_happens = false; +// try +// { +// opts.get_default<int>("tag"); +// } +// catch(const logic_error& e) +// { +// exception_happens = true; +// } - EXAM_CHECK( exception_happens ); +// EXAM_CHECK( exception_happens ); exception_happens = false; - try - { + try { vector< string > vs; - opts.getemall(h_token,vs.begin()); + opts.getemall( h_token, back_inserter( vs ) ); } - catch( const logic_error& e) - { + catch ( const logic_error& e) { exception_happens = true; } @@ -195,11 +204,10 @@ Opts opts; - int t_token = opts.add('t',10); - int name_token = opts.add("name","linus"); - int port_token = opts.add('p',80,"port"); - int num_token = opts.add("num",100,"number of elements"); - + int t_token = (opts << option<int>( "", 't' )[10]).last_token(); + int name_token = (opts << option<string>( "", "name" )["linus"]).last_token(); + int port_token = (opts << option<int>( "", 'p', "port" )[80]).last_token(); + int num_token = (opts << option<int>( "number of elements", "num")[100]).last_token(); try { opts.parse( argc, argv ); @@ -216,7 +224,7 @@ EXAM_CHECK( opts.is_set(name_token) ); EXAM_CHECK( opts.get_cnt("name") == 1 ); EXAM_CHECK( opts.get<string>(name_token) == "torwalds"); - EXAM_CHECK( opts.get_default<string>("name") == "linus"); + // EXAM_CHECK( opts.get_default<string>("name") == "linus"); EXAM_CHECK( !opts.is_set('p') ); //EXAM_CHECK( !opts.is_set("num") && opts.get<int>(num_token) == opts.get_default<int>("num") ) ; @@ -230,11 +238,11 @@ Opts opts; - opts.add( 'p', 0, "port", "listen tcp port"); - opts.addflag("begin"); - int f1_token = opts.addflag("f1"); - int f2_token = opts.addflag("f2"); - opts.addflag("end"); + opts << option<int>( "listen tcp port", 'p', "port" )[0]; + opts << option<bool>( "", "begin" ); + int f1_token = (opts << option<bool>( "", "f1") ).last_token(); + int f2_token = (opts << option<bool>( "", "f2") ).last_token(); + opts << option<bool>( "", "end" ); try { opts.parse( argc, argv ); @@ -262,8 +270,7 @@ opts.get_pos(f2_token,f2_v.begin()); opts.get_pos("end",e_v.begin()); - try - { + try { opts.get_pos("unknown",u_l.begin()); } catch(const Opts::unknown_option& e) @@ -292,7 +299,7 @@ Opts opts; - opts.add( 'p', 0, "port", "listen tcp port"); + opts << option<int>( "listen tcp port", 'p', "port" )[0]; try { opts.parse( argc, argv ); @@ -305,6 +312,8 @@ } catch ( const Opts::arg_typemismatch& e ) { } + catch ( ... ) { + } return EXAM_RESULT; } @@ -316,7 +325,7 @@ Opts opts; - opts.addflag( 'h', "help", "print this help message" ); + opts << option<bool>( "print this help message", 'h', "help" ); bool exception_happens = false; @@ -330,6 +339,8 @@ } catch ( const Opts::arg_typemismatch& e ) { } + catch ( ... ) { + } EXAM_CHECK( exception_happens ); @@ -343,23 +354,26 @@ Opts opts; - opts.add( 'p', 10, "port", "listen tcp port" ); + opts << option<int>( "listen tcp port", 'p', "port" )[10]; bool exception_happens = false; - - opts.parse( argc, argv ); - try - { + try { + opts.parse( argc, argv ); // <- exception here + int t = opts.get<int>('p'); } - catch(const Opts::arg_typemismatch& e) - { + catch ( const Opts::arg_typemismatch& e ) { exception_happens = true; } + catch ( const std::invalid_argument& e ) { + exception_happens = true; + } + catch ( ... ) { + } EXAM_CHECK( exception_happens ); - EXAM_CHECK ( opts.get_default<int>('p') == 10 ); + // EXAM_CHECK ( opts.get_default<int>('p') == 10 ); return EXAM_RESULT; } @@ -371,16 +385,14 @@ Opts opts; - opts.addflag('h',"help"); + opts << option<bool>( "", 'h', "help" ); bool exception_happens = false; - try - { + try { opts.parse( argc, argv ); } - catch(const Opts::arg_typemismatch& e) - { + catch(const Opts::arg_typemismatch& e) { exception_happens = true; } @@ -396,18 +408,18 @@ Opts opts; - opts.add('n',10,"num"); + opts << option<int>( "", 'n', "num" )[10]; bool exception_happens = false; - try - { + try { opts.parse( argc, argv ); } - catch(const Opts::missing_arg& e) - { + catch(const Opts::missing_arg& e) { exception_happens = true; } + catch ( ... ) { + } EXAM_CHECK( exception_happens ); @@ -422,7 +434,7 @@ Opts opts; - opts.addflag( 'v', "verbose", "more trace messages" ); + opts << option<bool>( "more trace messages", 'v', "verbose" ); opts.parse( argc, argv ); @@ -435,7 +447,7 @@ Opts opts; - opts.addflag( 'v', "verbose", "more trace messages" ); + opts << option<bool>( "more trace messages", 'v', "verbose" ); opts.parse( argc, argv ); @@ -448,7 +460,7 @@ Opts opts; - opts.addflag( 'v', "verbose", "more trace messages" ); + opts << option<bool>( "more trace messages", 'v', "verbose" ); opts.parse( argc, argv ); @@ -458,7 +470,6 @@ return EXAM_RESULT; } - int EXAM_IMPL(opts_test::compound) { { @@ -467,9 +478,9 @@ Opts opts; - opts.addflag( 'a', "a-option", "option a" ); - opts.addflag( 'b', "b-option", "option b" ); - opts.addflag( 'c', "c-option", "option c" ); + opts << option<bool>( "option a", 'a', "a-option" ); + opts << option<bool>( "option b", 'b', "b-option" ); + opts << option<bool>( "option c", 'c', "c-option" ); opts.parse( argc, argv ); @@ -482,36 +493,40 @@ int EXAM_IMPL(opts_test::multiple_compound) { - { - const char* argv[] = { "name", "-xf","--flag", "-f", "-p=first" ,"--pa","second" }; - int argc = sizeof( argv ) / sizeof(argv[0]); + const char* argv[] = { "name", "-xf", "--flag", "-f", "-p=first", "--pa", "second" }; + int argc = sizeof( argv ) / sizeof(argv[0]); - Opts opts; + Opts opts; - opts.addflag( 'x', "x-option", "option x" ); - opts.addflag( 'f', "flag", "option f" ); + opts << option<bool>( "option x", 'x', "x-option" ); + opts << option<bool>( "option f", 'f', "flag" ); - opts.add('p',"defaultpath","path","some path"); + opts << option<string>( "some path", 'p', "path" )["defaultpath"]; - opts.parse( argc, argv ); + opts.parse( argc, argv ); - EXAM_CHECK(opts.is_set('x')); - EXAM_CHECK(opts.is_set("flag")); - EXAM_CHECK(opts.is_set('p')); - EXAM_CHECK(opts.get_cnt("flag") == 3 && opts.get_cnt('f') == 3); - vector<string> vs(2); + EXAM_CHECK(opts.is_set('x')); + EXAM_CHECK(opts.is_set("flag")); + EXAM_CHECK(opts.is_set('p')); + EXAM_CHECK(opts.get_cnt("flag") == 3 && opts.get_cnt('f') == 3); - opts.getemall("path",vs.begin()); - EXAM_CHECK( vs[0] == "first" ); - EXAM_CHECK( vs[1] == "second" ); - } + vector<string> vs; + opts.getemall( "path", back_inserter( vs ) ); + vector<string>::iterator j = vs.begin(); + + EXAM_CHECK( j != vs.end() ); + EXAM_CHECK( *j == "first" ); + ++j; + EXAM_CHECK( j != vs.end() ); + EXAM_CHECK( *j == "second" ); + ++j; + EXAM_CHECK( j == vs.end() ); + return EXAM_RESULT; } - - int EXAM_IMPL(opts_test::args) { { @@ -520,7 +535,7 @@ Opts opts; - opts.add( 'f',string("default.conf"), "config", "configuration file"); + opts << option<string>( "configuration file", 'f', "config" )["default.conf"]; opts.parse( argc, argv ); @@ -536,7 +551,7 @@ Opts opts; - opts.add( 'f', string("default.conf"), "config", "configuration file" ); + opts << option<string>( "configuration file", 'f', "config" )["default.conf"]; opts.parse( argc, argv ); @@ -552,7 +567,7 @@ Opts opts; - opts.add( 'f', string("default.conf"), "config", "configuration file" ); + opts << option<string>( "configuration file", 'f', "config" )["default.conf"]; opts.parse( argc, argv ); @@ -573,7 +588,7 @@ Opts opts; - opts.addflag( 'a', "a-option", "option a" ); + opts << option<bool>( "option a", 'a', "a-option" ); opts.parse( argc, argv ); @@ -611,20 +626,18 @@ int EXAM_IMPL(opts_test::user_defined) { - { - const char* argv[] = { "name", "-s", "1 2" }; - int argc = sizeof( argv ) / sizeof(argv[0]); + const char* argv[] = { "name", "-s", "1 2" }; + int argc = sizeof( argv ) / sizeof(argv[0]); - Opts opts; + Opts opts; - opts.add( 's', point(1,1) ,"start-point", "start point"); + opts << option<point>( "start point", 's', "start-point" )[point(1,1)]; - opts.parse( argc, argv ); + opts.parse( argc, argv ); - point p = opts.get<point>( 's' ); + point p = opts.get<point>( 's' ); - EXAM_CHECK( (p.x == 1) && (p.y == 2) ); - } + EXAM_CHECK( (p.x == 1) && (p.y == 2) ); return EXAM_RESULT; } @@ -632,73 +645,79 @@ // check whether autocomplement works int EXAM_IMPL(opts_test::autocomplement) { - { - const char* argv[] = { "name" , "--num" , "4"}; - int argc = sizeof( argv ) / sizeof(argv[0]); + const char* argv[] = { "name" , "--num", "4" }; + int argc = sizeof( argv ) / sizeof(argv[0]); - Opts opts; + Opts opts; - opts.add('n',1,"number_of_processors","number of processors" ); + opts << option<int>( "number of processors", 'n', "number_of_processors" )[1]; - opts.parse( argc, argv ); + opts.parse( argc, argv ); - EXAM_CHECK( opts.get<int>('n') == 4 ); - } + EXAM_CHECK( opts.get<int>('n') == 4 ); return EXAM_RESULT; } int EXAM_IMPL(opts_test::autocomplement_failure) { - { - const char* argv[] = { "name" , "--proc" , "4"}; - int argc = sizeof( argv ) / sizeof(argv[0]); + const char* argv[] = { "name" , "--proc" , "4" }; + int argc = sizeof( argv ) / sizeof(argv[0]); - Opts opts; + Opts opts; - opts.add('p',1,"proc_num","process number" ); - opts.add('t',string("standart"),"proc_type","process type"); + opts << option<int>( "process number", 'p', "proc_num" )[1]; + opts << option<string>( "process type", 't', "proc_type" )["standard"]; - bool exception_happens = false; + bool exception_happens = false; - try - { - opts.parse( argc, argv ); - } - catch(const Opts::unknown_option& e) - { - exception_happens = true; - } - - EXAM_CHECK( exception_happens ); + try { + opts.parse( argc, argv ); } + catch (const Opts::unknown_option& e) { + exception_happens = true; + } + catch ( ... ) { + } + EXAM_CHECK( exception_happens ); + return EXAM_RESULT; } int EXAM_IMPL(opts_test::multiple_args) { - { - const char* argv[] = { "name" , "-I" , "first","-I","second","-I","third"}; - int argc = sizeof( argv ) / sizeof(argv[0]); + const char* argv[] = { "name" , "-I", "first", "-I", "second", "-I", "third" }; + int argc = sizeof( argv ) / sizeof(argv[0]); - Opts opts; + Opts opts; - opts.add('I',"/usr/include","include","include paths" ); + opts << option<string>( "include paths", 'I', "include" )[ "/usr/include" ]; - opts.parse( argc, argv ); + opts.parse( argc, argv ); - vector<string> vs(10); + vector<string> vs; - opts.getemall('I',vs.begin()); + opts.getemall( 'I', back_inserter(vs) ); - EXAM_CHECK( opts.get_default<string>("include") == "/usr/include"); + // EXAM_CHECK( opts.get_default<string>("include") == "/usr/include"); + + vector<string>::iterator j = vs.begin(); + + EXAM_CHECK( j != vs.end() ); + EXAM_CHECK( *j == "first" ); + + ++j; + EXAM_CHECK( j != vs.end() ); + EXAM_CHECK( *j == "second" ); - EXAM_CHECK( vs[0] == "first" ); - EXAM_CHECK( vs[1] == "second" ); - EXAM_CHECK( vs[2] == "third" ); - } + ++j; + EXAM_CHECK( j != vs.end() ); + EXAM_CHECK( *j == "third" ); + ++j; + EXAM_CHECK( j == vs.end() ); + return EXAM_RESULT; } @@ -714,12 +733,12 @@ opts.author( "B. L. User" ); opts.copyright( "Copyright (C) Youyoudine, 2008" ); - opts.addflag( 'h', "help", "print this help message" ); - opts.addflag( "flag", "some program flag" ); - opts.addflag( 'v', "version", "print version"); - opts.add( 'I', "/usr/include", "include", "include paths" ); - opts.add( 'p', 80, "port", "listen to tcp port" ); - opts.add( "mode", "standard", "program mode"); + opts << option<bool>( "print this help message", 'h', "help" ); + opts << option<bool>( "some program flag", "flag" ); + opts << option<bool>( "print version", 'v', "version" ); + opts << option<string>( "include paths", 'I', "include" )["/usr/include"]; + opts << option<int>( "listen to tcp port", 'p', "port" )[80]; + opts << option<string>( "program mode", "mode" )["standard"]; opts.parse( argc,argv ); @@ -746,9 +765,9 @@ -h, --help\tprint this help message\n\ --flag\tsome program flag\n\ -v, --version\tprint version\n\ --I <val>, --include=<val> [/usr/include]\tinclude paths\n\ --p <val>, --port=<val> [80]\tlisten to tcp port\n\ ---mode=<val> [standard]\tprogram mode\n\ +-I <string>, --include=<string> [/usr/include]\tinclude paths\n\ +-p <i>, --port=<i> [80]\tlisten to tcp port\n\ +--mode=<string> [standard]\tprogram mode\n\ \n"; EXAM_CHECK( s.str() == sample ); @@ -759,19 +778,29 @@ int EXAM_IMPL(opts_test::long_string) { { - const char* argv[] = { "name" , "--string" , "long string"}; + const char* argv[] = { "name", "--string", "long string" }; int argc = sizeof( argv ) / sizeof(argv[0]); Opts opts; - opts.add('s',string("default value"),"string","some string param"); + opts << option<string>( "some string param", 's', "string" )["default value"]; - EXAM_CHECK( opts.get('s') == "default value"); + opts.parse( argc, argv ); - opts.parse(argc,argv); + EXAM_CHECK( opts.get<string>( 's' ) == "long string" ); + } - EXAM_CHECK( opts.get('s') == "long string"); + { + const char* argv[] = { "name" }; + int argc = sizeof( argv ) / sizeof(argv[0]); + + Opts opts; + + opts << option<string>( "some string param", 's', "string" )["default value"]; + opts.parse( argc, argv ); + + EXAM_CHECK( opts.get<string>( 's' ) == "default value" ); } return EXAM_RESULT; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-06-29 21:48:13
|
Revision: 1927 http://complement.svn.sourceforge.net/complement/?rev=1927&view=rev Author: complement Date: 2008-06-29 14:48:10 -0700 (Sun, 29 Jun 2008) Log Message: ----------- Clean code; enhance help message; pass default value via operator [] Also rename option to option_base (keep in mind future changes). Test for print help really check printed message. Modified Paths: -------------- trunk/complement/explore/include/misc/opts.h trunk/complement/explore/lib/misc/opts.cc trunk/complement/explore/lib/misc/ut/opts_test.cc Modified: trunk/complement/explore/include/misc/opts.h =================================================================== --- trunk/complement/explore/include/misc/opts.h 2008-06-29 21:47:47 UTC (rev 1926) +++ trunk/complement/explore/include/misc/opts.h 2008-06-29 21:48:10 UTC (rev 1927) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/28 10:26:23 ptr> +// -*- C++ -*- Time-stamp: <08/06/29 13:52:41 ptr> /* * Copyright (c) 2008 @@ -23,30 +23,34 @@ #include <exception> #include <stdexcept> -#define all(c) (c).begin() , (c).end() - -class option +class option_base { public: - option( const char* _description, char _short_var, const char* _long_var ) : + option_base( const char* _description, char _short_var, const char* _long_var ) : shortname( _short_var ), longname( _long_var ), - desc( _description ) + desc( _description ), + has_arg( false ) { } - option( const char* _description, char _short_var ) : + option_base( const char* _description, char _short_var ) : shortname( _short_var ), longname(), - desc( _description ) + desc( _description ), + has_arg( false ) { } - option( const char* _description, const char* _long_var ) : + option_base( const char* _description, const char* _long_var ) : shortname( 0 ), longname( _long_var ), - desc( _description ) + desc( _description ), + has_arg( false ) { } + option_base& operator []( const std::string& d ) + { default_v = d; has_arg = true; } + bool operator ==( const std::string& _longname ) const { return longname == _longname; } bool operator ==( char _shortname ) const @@ -66,14 +70,14 @@ bool has_arg; - friend std::ostream& operator <<( std::ostream& t, const option& opt ); + friend std::ostream& operator <<( std::ostream& t, const option_base& opt ); friend class Opts; }; class Opts { private: - typedef std::vector< option > options_container_type; + typedef std::vector< option_base > options_container_type; options_container_type storage; public: @@ -84,6 +88,9 @@ void description( const char* text ) { _brief = text; } + void usage( const char* text ) + { _usage = text; } + void author( const char* text ) { _author = text; } @@ -167,6 +174,7 @@ std::string pname; std::string _brief; + std::string _usage; std::string _author; std::string _copyright; @@ -183,8 +191,7 @@ addflag(_shortname,_longname,_desc); std::stringstream ss; ss << _default_value; - storage[storage.size() - 1].default_v = ss.str(); - storage[storage.size() - 1].has_arg = true; + storage[storage.size() - 1][ss.str()]; return storage[storage.size() - 1].token; } @@ -194,186 +201,157 @@ addflag(_longname,_desc); std::stringstream ss; ss << _default_value; - storage[storage.size() - 1].default_v = ss.str(); - storage[storage.size() - 1].has_arg = true; + storage[storage.size() - 1][ss.str()]; return storage[storage.size() - 1].token; } template <class T> bool Opts::is_set(T field) const { - options_container_type::const_iterator i = find(all(storage),field); + options_container_type::const_iterator i = std::find( storage.begin(), storage.end(), field ); return ( (i == storage.end()) ? false : !i->pos.empty()); } template <class T> int Opts::get_cnt(T field) const { - options_container_type::const_iterator i = find(all(storage),field); + options_container_type::const_iterator i = std::find( storage.begin(), storage.end(), field ); return ( (i == storage.end()) ? 0 : i->pos.size()); } template <class V> std::string Opts::get( V field ) { - options_container_type::const_iterator i = find(all(storage),field); - std::string res; + options_container_type::const_iterator i = std::find( storage.begin(), storage.end(), field ); - if (i != storage.end()) - { - if ( !i->has_arg ) - { - throw std::logic_error("using Opts::get for option without arguments"); - } - - res = i->args.empty() ? i->default_v : i->args[0]; - } - else - { + if ( i == storage.end() ) { std::stringstream ss1; ss1 << field; - throw unknown_option( ss1.str() ); + throw unknown_option( ss1.str() ); } - return res; + if ( !i->has_arg ) { + throw std::logic_error("using Opts::get for option without arguments"); + } + + return i->args.empty() ? i->default_v : i->args[0]; } template < class T , class V > T Opts::get( V field ) { - options_container_type::const_iterator i = find(all(storage),field); - T res; + options_container_type::const_iterator i = std::find(storage.begin(), storage.end() ,field); - if (i != storage.end()) - { - if ( !i->has_arg ) - { - throw std::logic_error("using Opts::get for option without arguments"); - } + if ( i == storage.end() ) { + std::stringstream ss1; + ss1 << field; + throw unknown_option( ss1.str() ); + } - std::stringstream ss(i->args.empty() ? i->default_v : i->args[0]); - ss >> res; - - if (ss.fail()) - { - std::stringstream ss1; - ss1 << field; - throw arg_typemismatch(ss1.str(),i->args.empty() ? i->default_v : i->args[0]); - } + if ( !i->has_arg ) { + throw std::logic_error("using Opts::get for option without arguments"); } - else - { + + T res; + std::stringstream ss(i->args.empty() ? i->default_v : i->args[0]); + ss >> res; + + if ( ss.fail() ) { std::stringstream ss1; ss1 << field; - throw unknown_option( ss1.str() ); + throw arg_typemismatch(ss1.str(),i->args.empty() ? i->default_v : i->args[0]); } return res; } - template < class V> std::string Opts::get_default( V field ) { - options_container_type::const_iterator i = find(all(storage),field); - std::string res; + options_container_type::const_iterator i = std::find( storage.begin(), storage.end(), field ); - if (i != storage.end()) - { - if (!i->has_arg) - throw std::logic_error("using Opts::get for option without arguments"); - - res = i->default_v; - } - else - { + if ( i == storage.end() ) { std::stringstream ss1; ss1 << field; throw unknown_option( ss1.str() ); } - return res; + if ( !i->has_arg ) { + throw std::logic_error("using Opts::get for option without arguments"); + } + + return i->default_v; } template <class T , class V> T Opts::get_default( V field ) { - options_container_type::const_iterator i = find(all(storage),field); - T res; + options_container_type::const_iterator i = std::find( storage.begin(), storage.end(), field ); - if (i != storage.end()) - { - if (!i->has_arg) - throw std::logic_error("using Opts::get for option without arguments"); - - std::stringstream ss(i->default_v); - ss >> res; - - if (ss.fail()) - { - std::stringstream ss1; - ss1 << field; - throw arg_typemismatch(ss1.str(),i->default_v); - } - } - else - { + if ( i == storage.end() ) { std::stringstream ss1; ss1 << field; throw unknown_option( ss1.str() ); } + if ( !i->has_arg ) { + throw std::logic_error("using Opts::get for option without arguments"); + } + + T res; + std::stringstream ss(i->default_v); + ss >> res; + + if ( ss.fail() ) { + std::stringstream ss1; + ss1 << field; + throw arg_typemismatch(ss1.str(),i->default_v); + } + return res; } template <class V , class BackInsertIterator> void Opts::getemall( V field , BackInsertIterator bi) { - options_container_type::const_iterator i = find(all(storage),field); - if (i != storage.end()) - { - if (!i->has_arg) - throw std::logic_error("using Opts::getemall for option without arguments"); - - if (!i->args.empty()) - { - for (int j = 0;j < i->args.size();++j) - { - std::stringstream ss(i->args[j]); - ss >> *bi++; + options_container_type::const_iterator i = std::find( storage.begin(), storage.end(), field ); - if (ss.fail()) - { - std::stringstream ss1; - ss1 << field; - throw arg_typemismatch(ss1.str(),i->args[j]); - } - } - } - } - else - { + if ( i == storage.end() ) { std::stringstream ss1; ss1 << field; throw unknown_option(ss1.str()); } + + if ( !i->has_arg ) { + throw std::logic_error("using Opts::getemall for option without arguments"); + } + + if ( !i->args.empty() ) { + for ( int j = 0; j < i->args.size(); ++j) { + std::stringstream ss(i->args[j]); + ss >> *bi++; + + if ( ss.fail() ) { + std::stringstream ss1; + ss1 << field; + throw arg_typemismatch(ss1.str(),i->args[j]); + } + } + } } template <class V , class BackInsertIterator> void Opts::get_pos( V field , BackInsertIterator bi) { - options_container_type::const_iterator i = find(all(storage),field); + options_container_type::const_iterator i = std::find( storage.begin(), storage.end(), field ); - if (i != storage.end()) - { - copy(all(i->pos),bi); - } - else - { + if ( i == storage.end() ) { std::stringstream ss1; ss1 << field; throw unknown_option(ss1.str()); } + + std::copy( i->pos.begin(), i->pos.end(), bi ); } #endif // __OPTS_H__ Modified: trunk/complement/explore/lib/misc/opts.cc =================================================================== --- trunk/complement/explore/lib/misc/opts.cc 2008-06-29 21:47:47 UTC (rev 1926) +++ trunk/complement/explore/lib/misc/opts.cc 2008-06-29 21:48:10 UTC (rev 1927) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/28 10:25:43 ptr> +// -*- C++ -*- Time-stamp: <08/06/29 13:05:13 ptr> /* * Copyright (c) 2008 @@ -21,6 +21,22 @@ using namespace std; +ostream& operator <<( ostream& out, const option_base& opt ) +{ + if ( opt.shortname != 0 ) { + out << '-' << opt.shortname << (opt.has_arg ? " <val>" : "" ); + if ( !opt.longname.empty() ) { + out << ", "; + } + } + + if ( !opt.longname.empty() ) { + out << "--" << opt.longname << (opt.has_arg ? "=<val>" : "" ); + } + + return out << (opt.has_arg ? (string(" [") + opt.default_v + "]\t") : "\t" ) << opt.desc; +} + string Opts::get_pname() const { return pname; } bool Opts::is_opt_name(const string& s) @@ -39,17 +55,19 @@ return true; } -bool Opts::is_flag_group(const string& s) +bool Opts::is_flag_group( const string& s ) { - if (s.size() > 2 && s[0] == '-') - { - for (int i = 1;i < s.size();i++) - if (!isalnum(s[i])) + string::const_iterator i = s.begin(); + + if ( s.size() > 2 && *i == '-' ) { + while ( ++i != s.end() ) { + if ( !isalnum( *i ) ) { return false; + } + } return true; } - else - return false; + return false; } // this function assumes that is_opt_name(s) = true; @@ -89,37 +107,37 @@ return storage.end(); } -ostream& operator <<( ostream& out, const option& opt ) +void Opts::help( ostream& out ) { - if ( opt.shortname == 0 ) { - out << "--" << opt.longname << '\t' << (opt.has_arg ? (string("[") + opt.default_v + "]\t") : "" ) << opt.desc; - } else { - out << '-' << opt.shortname << '\t' << (!opt.longname.empty() ? (string("[--") + opt.longname +"]\t") : "") << (opt.has_arg ? string("[") + opt.default_v + ("]\t") : "") << opt.desc; + out << "This is " << pname; + if ( !_brief.empty() ) { + out << ", " << _brief; } - - return out; -} + out << "\n\n"; -void Opts::help(ostream& out) -{ - if (!_brief.empty()) - out << _brief << endl; - if (!_author.empty()) - out << _author << endl; - if (!_copyright.empty()) - out << _copyright << endl; - - out << "Valid options:" << endl; - options_container_type::const_iterator i; - for (i = storage.begin();i != storage.end();++i) - { - out << *i << endl; + if ( !_author.empty() ) { + out << _author << "\n\n"; } + + if ( !_copyright.empty() ) { + out << _copyright << "\n\n"; + } + + out << "Usage:\n\n" << pname << " " << _usage << "\n"; // " [options] etc. etc." + + if ( !storage.empty() ) { + out << "\nOptions:\n\n"; + + for ( options_container_type::const_iterator i = storage.begin(); i != storage.end(); ++i) { + out << *i << "\n"; + } + } + out << endl; } int Opts::addflag( char _shortname, const string& _longname, const string& _desc ) { - option opt( _desc.c_str(), _shortname, _longname.c_str() ); + option_base opt( _desc.c_str(), _shortname, _longname.c_str() ); opt.has_arg = false; opt.token = ++free_token; @@ -129,7 +147,7 @@ int Opts::addflag( const string& _longname, const string& _desc ) { - option opt( _desc.c_str(), _longname.c_str() ); + option_base opt( _desc.c_str(), _longname.c_str() ); opt.has_arg = false; opt.token = ++free_token; @@ -137,77 +155,67 @@ return opt.token; } -void Opts::parse(int& ac,const char** av) +void Opts::parse( int& ac, const char** av ) { pname = av[0]; int i = 1; int j = 1; int q = 0; - while ( (i < ac) && (string(av[i]) != "--") ) - { - if (is_opt_name(av[i])) - { + + while ( (i < ac) && (string(av[i]) != "--") ) { + if ( is_opt_name(av[i]) ) { string opt = av[i]; string arg; - int k = opt.find("="); + int k = opt.find( "=" ); - if (k != string::npos) - { - arg = opt.substr(k + 1); - opt = opt.substr(0,k); + if ( k != string::npos ) { + arg = opt.substr( k + 1 ); + opt = opt.substr( 0, k ); } - options_container_type::iterator p = get_opt_index(opt); + options_container_type::iterator p = get_opt_index(opt); - if (p == storage.end()) + if ( p == storage.end() ) { throw unknown_option(opt); - else - { - p->pos.push_back(++q); - if (p->has_arg) - { - if (!arg.empty()) - p->args.push_back(arg); - else - if (i + 1 < ac) - p->args.push_back(av[++i]); - else - throw missing_arg(opt); + } + + p->pos.push_back(++q); + if ( p->has_arg ) { + if ( !arg.empty() ) { + p->args.push_back(arg); + } else { + if ( (i + 1) >= ac ) { + throw missing_arg(opt); + } + p->args.push_back(av[++i]); } - else - if (!arg.empty()) //unexpected arg (not exactly mismatch) - throw arg_typemismatch(opt,arg); - } - } - else - if (is_flag_group(av[i])) - { + } else if ( !arg.empty() ) { //unexpected arg (not exactly mismatch) + throw arg_typemismatch(opt,arg); + } + } else if ( is_flag_group(av[i]) ) { string optgroup = av[i]; - for (int j = 1;j < optgroup.size();j++) - { + for ( int j = 1; j < optgroup.size(); j++ ) { options_container_type::iterator p = get_opt_index(string("-") + optgroup[j]); - if (p == storage.end()) - { + if ( p == storage.end() ) { throw unknown_option( "-" + string(1,optgroup[j]) ); } - else - { - p->pos.push_back(++q); - if (p->has_arg) - throw missing_arg( "-" + string(1,optgroup[j]) ); + p->pos.push_back(++q); + if ( p->has_arg ) { + throw missing_arg( "-" + string(1,optgroup[j]) ); } } + } else { + av[j++] = av[i]; } - else - av[j++] = av[i]; i++; } i += ( i < ac ); - while (i < ac) - av[j++] = av[i++]; + while (i < ac) { + av[j++] = av[i++]; + } ac = j; } Modified: trunk/complement/explore/lib/misc/ut/opts_test.cc =================================================================== --- trunk/complement/explore/lib/misc/ut/opts_test.cc 2008-06-29 21:47:47 UTC (rev 1926) +++ trunk/complement/explore/lib/misc/ut/opts_test.cc 2008-06-29 21:48:10 UTC (rev 1927) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/28 10:25:10 ptr> +// -*- C++ -*- Time-stamp: <08/06/29 13:18:16 ptr> /* * Copyright (c) 2008 @@ -704,34 +704,55 @@ int EXAM_IMPL(opts_test::help) { - { - const char* argv[] = { "name" , "--help" }; - int argc = sizeof( argv ) / sizeof(argv[0]); + const char* argv[] = { "programname" , "--help" }; + int argc = sizeof( argv ) / sizeof(argv[0]); - Opts opts; + Opts opts; - opts.description( "what utility do" ); - opts.author( "author" ); - opts.copyright( "copyright" ); + opts.description( "test for printing help message" ); + opts.usage( "[options] file-from file-to" ); + opts.author( "B. L. User" ); + opts.copyright( "Copyright (C) Youyoudine, 2008" ); - opts.addflag('h',"help","print this help message"); - opts.addflag("flag","some program flag"); - opts.addflag('v',"version","view program version"); - opts.add('I',"/usr/include","include","include paths" ); - opts.add('p',80,"port","listen to tcp port"); - opts.add("mode","standart","program mode"); + opts.addflag( 'h', "help", "print this help message" ); + opts.addflag( "flag", "some program flag" ); + opts.addflag( 'v', "version", "print version"); + opts.add( 'I', "/usr/include", "include", "include paths" ); + opts.add( 'p', 80, "port", "listen to tcp port" ); + opts.add( "mode", "standard", "program mode"); - opts.parse(argc,argv); + opts.parse( argc,argv ); - EXAM_CHECK(opts.is_set('h')); - EXAM_CHECK( opts.get_pname() == "name" ); + EXAM_CHECK( opts.is_set('h') ); + EXAM_CHECK( opts.get_pname() == "programname" ); - ofstream out("help.out"); - opts.help(out); - cout << "check file help.out" << endl; - out.close(); - } + stringstream s; + opts.help( s ); + + const char sample[] = +"This is programname, test for printing help message\n\ +\n\ +B. L. User\n\ +\n\ +Copyright (C) Youyoudine, 2008\n\ +\n\ +Usage:\n\ +\n\ +programname [options] file-from file-to\n\ +\n\ +Options:\n\ +\n\ +-h, --help\tprint this help message\n\ +--flag\tsome program flag\n\ +-v, --version\tprint version\n\ +-I <val>, --include=<val> [/usr/include]\tinclude paths\n\ +-p <val>, --port=<val> [80]\tlisten to tcp port\n\ +--mode=<val> [standard]\tprogram mode\n\ +\n"; + + EXAM_CHECK( s.str() == sample ); + return EXAM_RESULT; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-06-29 21:47:49
|
Revision: 1926 http://complement.svn.sourceforge.net/complement/?rev=1926&view=rev Author: complement Date: 2008-06-29 14:47:47 -0700 (Sun, 29 Jun 2008) Log Message: ----------- Rename Opt -> option; set proper ctors; hide implementation. Modified Paths: -------------- trunk/complement/explore/include/misc/opts.h trunk/complement/explore/lib/misc/opts.cc trunk/complement/explore/lib/misc/ut/opts_test.cc Modified: trunk/complement/explore/include/misc/opts.h =================================================================== --- trunk/complement/explore/include/misc/opts.h 2008-06-27 17:42:24 UTC (rev 1925) +++ trunk/complement/explore/include/misc/opts.h 2008-06-29 21:47:47 UTC (rev 1926) @@ -1,5 +1,16 @@ -// -*- C++ -*- Time-stamp: <08/05/21 12:17:39 yeti> +// -*- C++ -*- Time-stamp: <08/06/28 10:26:23 ptr> +/* + * Copyright (c) 2008 + * Dmitry Osmakov + * + * Copyright (c) 2008 + * Petr Ovtchenkov + * + * Licensed under the Academic Free License Version 3.0 + * + */ + #ifndef __OPTS_H__ #define __OPTS_H__ @@ -14,11 +25,36 @@ #define all(c) (c).begin() , (c).end() -class Opt +class option { public: - Opt() : shortname(' ') + + option( const char* _description, char _short_var, const char* _long_var ) : + shortname( _short_var ), + longname( _long_var ), + desc( _description ) { } + + option( const char* _description, char _short_var ) : + shortname( _short_var ), + longname(), + desc( _description ) + { } + + option( const char* _description, const char* _long_var ) : + shortname( 0 ), + longname( _long_var ), + desc( _description ) + { } + + bool operator ==( const std::string& _longname ) const + { return longname == _longname; } + bool operator ==( char _shortname ) const + { return shortname == _shortname; } + bool operator ==( int _token ) const + { return token == _token; } + + private: char shortname; std::string longname; std::string desc; @@ -29,24 +65,31 @@ std::vector< int > pos; bool has_arg; - bool operator==( const std::string& _longname ) const { return longname == _longname; } - bool operator==( char _shortname ) const { return shortname == _shortname; } - bool operator==( int _token ) const { return token == _token; } - friend std::ostream& operator<<(std::ostream& t,const Opt& opt); + + friend std::ostream& operator <<( std::ostream& t, const option& opt ); + friend class Opts; }; class Opts { private: - typedef std::vector< Opt > options_container_type; + typedef std::vector< option > options_container_type; options_container_type storage; + public: - Opts( const std::string& _brief = "", const std::string& _author = "", const std::string& _copyright = "") : - brief(_brief), - author(_author), - copyright(_copyright) - { free_token = 0; } + Opts() : + free_token(0) + { } + void description( const char* text ) + { _brief = text; } + + void author( const char* text ) + { _author = text; } + + void copyright( const char* text ) + { _copyright = text; } + // adding option / flag (option that doesn't need arguments) template <class T> int add( const std::string& _longname,T _default_value,const std::string& _desc = "(no decription)" ); @@ -118,13 +161,14 @@ std::invalid_argument(std::string("argument [").append(_argname).append("] doesn't match by type for option ").append(_optname)) { } }; - + + private: int free_token; - private: + std::string pname; - std::string brief; - std::string author; - std::string copyright; + std::string _brief; + std::string _author; + std::string _copyright; bool isterm( const std::string& s ); bool is_opt_name( const std::string& s ); @@ -332,4 +376,4 @@ } } -#endif +#endif // __OPTS_H__ Modified: trunk/complement/explore/lib/misc/opts.cc =================================================================== --- trunk/complement/explore/lib/misc/opts.cc 2008-06-27 17:42:24 UTC (rev 1925) +++ trunk/complement/explore/lib/misc/opts.cc 2008-06-29 21:47:47 UTC (rev 1926) @@ -1,3 +1,16 @@ +// -*- C++ -*- Time-stamp: <08/06/28 10:25:43 ptr> + +/* + * Copyright (c) 2008 + * Dmitry Osmakov + * + * Copyright (c) 2008 + * Petr Ovtchenkov + * + * Licensed under the Academic Free License Version 3.0 + * + */ + #include <vector> #include <string> #include <sstream> @@ -76,14 +89,11 @@ return storage.end(); } -ostream& operator<<(ostream& out,const Opt& opt) +ostream& operator <<( ostream& out, const option& opt ) { - if (opt.shortname == ' ') - { + if ( opt.shortname == 0 ) { out << "--" << opt.longname << '\t' << (opt.has_arg ? (string("[") + opt.default_v + "]\t") : "" ) << opt.desc; - } - else - { + } else { out << '-' << opt.shortname << '\t' << (!opt.longname.empty() ? (string("[--") + opt.longname +"]\t") : "") << (opt.has_arg ? string("[") + opt.default_v + ("]\t") : "") << opt.desc; } @@ -92,12 +102,12 @@ void Opts::help(ostream& out) { - if (!brief.empty()) - out << brief << endl; - if (!author.empty()) - out << author << endl; - if (!copyright.empty()) - out << copyright << endl; + if (!_brief.empty()) + out << _brief << endl; + if (!_author.empty()) + out << _author << endl; + if (!_copyright.empty()) + out << _copyright << endl; out << "Valid options:" << endl; options_container_type::const_iterator i; @@ -107,23 +117,20 @@ } } -int Opts::addflag(char _shortname,const string& _longname,const string& _desc) +int Opts::addflag( char _shortname, const string& _longname, const string& _desc ) { - Opt opt; - opt.shortname = _shortname; - opt.longname = _longname; - opt.desc = _desc; + option opt( _desc.c_str(), _shortname, _longname.c_str() ); + opt.has_arg = false; opt.token = ++free_token; storage.push_back(opt); return opt.token; } -int Opts::addflag(const string& _longname,const string& _desc) +int Opts::addflag( const string& _longname, const string& _desc ) { - Opt opt; - opt.longname = _longname; - opt.desc = _desc; + option opt( _desc.c_str(), _longname.c_str() ); + opt.has_arg = false; opt.token = ++free_token; storage.push_back(opt); Modified: trunk/complement/explore/lib/misc/ut/opts_test.cc =================================================================== --- trunk/complement/explore/lib/misc/ut/opts_test.cc 2008-06-27 17:42:24 UTC (rev 1925) +++ trunk/complement/explore/lib/misc/ut/opts_test.cc 2008-06-29 21:47:47 UTC (rev 1926) @@ -1,9 +1,12 @@ -// -*- C++ -*- Time-stamp: <08/05/21 12:20:14 yeti> +// -*- C++ -*- Time-stamp: <08/06/28 10:25:10 ptr> /* * Copyright (c) 2008 * Petr Ovtchenkov * + * Copyright (c) 2008 + * Dmitry Osmakov + * * Licensed under the Academic Free License Version 3.0 * */ @@ -705,8 +708,11 @@ const char* argv[] = { "name" , "--help" }; int argc = sizeof( argv ) / sizeof(argv[0]); - Opts opts("what utility do","author","copyright"); + Opts opts; + opts.description( "what utility do" ); + opts.author( "author" ); + opts.copyright( "copyright" ); opts.addflag('h',"help","print this help message"); opts.addflag("flag","some program flag"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-06-27 17:42:26
|
Revision: 1925 http://complement.svn.sourceforge.net/complement/?rev=1925&view=rev Author: complement Date: 2008-06-27 10:42:24 -0700 (Fri, 27 Jun 2008) Log Message: ----------- side-effect of merge Removed Paths: ------------- trunk/extern/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-06-27 11:20:51
|
Revision: 1924 http://complement.svn.sourceforge.net/complement/?rev=1924&view=rev Author: complement Date: 2008-06-27 04:20:41 -0700 (Fri, 27 Jun 2008) Log Message: ----------- Merge branch 'master' of /export/hostel/pub/scm/complement Modified Paths: -------------- trunk/complement/explore/include/sockios/sockmgr.cc trunk/complement/explore/include/sockios/sockmgr.h trunk/complement/explore/include/sockios/sockstream trunk/complement/explore/include/sockios/sockstream.cc trunk/complement/explore/include/stem/Cron.h trunk/complement/explore/include/stem/EvManager.h trunk/complement/explore/include/stem/EventHandler.h trunk/complement/explore/include/stem/NetTransport.h trunk/complement/explore/lib/sockios/ChangeLog trunk/complement/explore/lib/sockios/Makefile.inc trunk/complement/explore/lib/sockios/_sockmgr.cc trunk/complement/explore/lib/sockios/ut/Makefile.inc trunk/complement/explore/lib/sockios/ut/names.cc trunk/complement/explore/lib/sockios/ut/sockios_test.cc trunk/complement/explore/lib/sockios/ut/sockios_test.h trunk/complement/explore/lib/sockios/ut/sockios_test_suite.cc trunk/complement/explore/lib/stem/ChangeLog trunk/complement/explore/lib/stem/Cron.cc trunk/complement/explore/lib/stem/EvManager.cc trunk/complement/explore/lib/stem/Makefile.inc trunk/complement/explore/lib/stem/NetTransport.cc trunk/complement/explore/lib/stem/_EventHandler.cc trunk/complement/explore/lib/stem/ut/unit_test.cc Added Paths: ----------- trunk/complement/explore/include/sockios/socksrv.cc trunk/complement/explore/include/sockios/socksrv.h trunk/complement/explore/lib/sockios/ut/sockios2_test.cc trunk/complement/explore/lib/sockios/ut/sockios2_test.h Modified: trunk/complement/explore/include/sockios/sockmgr.cc =================================================================== --- trunk/complement/explore/include/sockios/sockmgr.cc 2008-06-27 10:28:54 UTC (rev 1923) +++ trunk/complement/explore/include/sockios/sockmgr.cc 2008-06-27 11:20:41 UTC (rev 1924) @@ -1,595 +1,515 @@ -// -*- C++ -*- Time-stamp: <07/09/19 11:43:21 ptr> +// -*- C++ -*- Time-stamp: <08/06/26 09:10:47 ptr> /* - * Copyright (c) 1997-1999, 2002, 2003, 2005-2007 + * Copyright (c) 2008 * Petr Ovtchenkov * - * Portion Copyright (c) 1999-2001 - * Parallel Graphics Ltd. - * * Licensed under the Academic Free License Version 3.0 * */ -#include <algorithm> -#include <functional> - -// #ifdef __unix -// extern "C" int nanosleep(const struct timespec *, struct timespec *); -// #endif - -#ifdef STLPORT -_STLP_BEGIN_NAMESPACE -#else namespace std { -#endif -#ifndef __FIT_NO_POLL +namespace detail { -template <class Connect, void (Connect::*C)( std::sockstream& ), void (Connect::*T)() > -void sockmgr_stream_MP<Connect,C,T>::_open( sock_base::stype t ) +template<class charT, class traits, class _Alloc> +void sockmgr<charT,traits,_Alloc>::io_worker() { - xmt::scoped_lock lk(_fd_lck); - if ( is_open_unsafe() ) { - if ( t == sock_base::sock_stream ) { - _accept = &_Self_type::accept_tcp; - _pfd.reserve( 32 ); - if ( _pfd.size() == 0 ) { - int pipefd[2]; - pipe( pipefd ); // check err - _cfd = pipefd[1]; + epoll_event ev[/*n_ret*/ 512 ]; - _pfd.resize( 2 ); - _pfd[0].fd = fd_unsafe(); - _pfd[0].events = POLLIN; - _pfd[1].fd = pipefd[0]; - _pfd[1].events = POLLIN; - } - } else if ( t == sock_base::sock_dgram ) { - _accept = &_Self_type::accept_udp; - if ( _pfd.size() == 0 ) { - int pipefd[2]; - pipe( pipefd ); // check err - _cfd = pipefd[1]; +/* + ctl _xctl; + int r = read( pipefd[0], &_xctl, sizeof(ctl) ); - _pfd.resize( 2 ); - _pfd[0].fd = fd_unsafe(); - _pfd[0].events = POLLIN; - _pfd[1].fd = pipefd[0]; - _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_cnd.try_wait(); + if ( _xctl.cmd == rqstart ) { + std::cerr << "io_worker fine" << std::endl; + } else { + std::cerr << "io_worker not fine, " << r << ", " << errno << std::endl; } -} +*/ -template <class Connect, void (Connect::*C)( std::sockstream& ), void (Connect::*T)() > -void sockmgr_stream_MP<Connect,C,T>::open( const in_addr& addr, int port, sock_base::stype t ) -{ - basic_sockmgr::open( addr, port, t, sock_base::inet ); - sockmgr_stream_MP<Connect,C,T>::_open( t ); -} + try { + for ( ; ; ) { + int n = epoll_wait( efd, &ev[0], /* n_ret */ 512, -1 ); -template <class Connect, void (Connect::*C)( std::sockstream& ), void (Connect::*T)() > -void sockmgr_stream_MP<Connect,C,T>::open( unsigned long addr, int port, sock_base::stype t ) -{ - basic_sockmgr::open( addr, port, t, sock_base::inet ); - sockmgr_stream_MP<Connect,C,T>::_open( t ); -} + if ( n < 0 ) { + if ( errno == EINTR ) { + errno = 0; + continue; + } + // throw system_error + } -template <class Connect, void (Connect::*C)( std::sockstream& ), void (Connect::*T)() > -void sockmgr_stream_MP<Connect,C,T>::open( int port, sock_base::stype t ) -{ - basic_sockmgr::open( port, t, sock_base::inet ); - sockmgr_stream_MP<Connect,C,T>::_open( t ); -} + std::tr2::lock_guard<std::tr2::mutex> lk( dll ); -template <class Connect, void (Connect::*C)( std::sockstream& ), void (Connect::*T)() > -bool sockmgr_stream_MP<Connect,C,T>::_shift_fd() -{ - bool ret = false; - typename iterator_traits<typename _fd_sequence::iterator>::difference_type d; + for ( int i = 0; i < n; ++i ) { + if ( ev[i].data.fd == pipefd[0] ) { + cmd_from_pipe(); + } else { + typename fd_container_type::iterator ifd = descr.find( ev[i].data.fd ); + if ( ifd == descr.end() ) { + // std::cerr << __FILE__ << ":" << __LINE__ << " " << ev[i].data.fd << std::endl; + if ( epoll_ctl( efd, EPOLL_CTL_DEL, ev[i].data.fd, 0 ) < 0 ) { + // throw system_error + } + continue; + // throw std::logic_error( "file descriptor in epoll, but not in descr[]" ); + } - for ( _fd_sequence::iterator j = _pfd.begin() + 2; j != _pfd.end(); ++j ) { // _pfd at least 2 in size - // if ( j->fd == -1 ) { - // cerr << __FILE__ << ":" << __LINE__ << endl; - // } - if ( j->revents != 0 ) { - xmt::scoped_lock _l( _c_lock ); - // 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->fd ) ); - // 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 - d = j - _pfd.begin(); - _pfd.erase( j ); - j = _pfd.begin() + (d - 1); - i = _M_c.begin(); - while ( (i = find_if( i, _M_c.end(), bind2nd( _M_comp, -1 ) )) != _M_c.end() ) { - _dlock.lock(); - _conn_pool.erase( std::remove( _conn_pool.begin(), _conn_pool.end(), i ), _conn_pool.end() ); - _dlock.unlock(); - _M_c.erase( i++ ); + fd_info& info = ifd->second; + if ( info.flags & fd_info::listener ) { + process_listener( ev[i], ifd ); + } else { + process_regular( ev[i], ifd ); + } } - } else if ( j->revents & POLLERR /* | POLLHUP | POLLNVAL */ ) { - // poll first see closed socket - d = j - _pfd.begin(); - _pfd.erase( j ); - j = _pfd.begin() + (d - 1); - _dlock.lock(); - _conn_pool.erase( std::remove( _conn_pool.begin(), _conn_pool.end(), i ), _conn_pool.end() ); - _dlock.unlock(); - _M_c.erase( i ); - } 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->fd, reinterpret_cast<void *>(&x), 1, MSG_PEEK ); - if ( nr <= 0 ) { // I can't read even one byte: this designate closed - // socket operation - d = j - _pfd.begin(); - _pfd.erase( j ); - j = _pfd.begin() + (d - 1); - _dlock.lock(); - _conn_pool.erase( std::remove( _conn_pool.begin(), _conn_pool.end(), i ), _conn_pool.end() ); - _dlock.unlock(); - _M_c.erase( i ); - } else { // normal data available for reading - _dlock.lock(); - _conn_pool.push_back( i ); - // xmt::Thread::gettime( &_tpush ); - _pool_cnd.set( true ); - _observer_cnd.set( true ); - _dlock.unlock(); - - /* erase: I don't want to listen this socket - * (it may be polled elsewhere, during connection - * processing). - * This help to avoid unwanted processing of the same socket - * in different threads: the socket in process can't - * come here before it will be re-added after processing - */ - d = j - _pfd.begin(); - _pfd.erase( j ); - j = _pfd.begin() + (d - 1); - - ret = true; // mark that I add somthing in connection queue - } } } } - - return ret; + catch ( std::detail::stop_request& ) { + // this is possible, normal flow of operation + } + catch ( std::exception& e ) { + std::cerr << e.what() << std::endl; + } } -template <class Connect, void (Connect::*C)( std::sockstream& ), void (Connect::*T)() > -bool sockmgr_stream_MP<Connect,C,T>::accept_tcp() +template<class charT, class traits, class _Alloc> +void sockmgr<charT,traits,_Alloc>::cmd_from_pipe() { - if ( !is_open() ) { - return false; + epoll_event ev_add; + ctl _ctl; + + int r = read( pipefd[0], &_ctl, sizeof(ctl) ); + if ( r < 0 ) { + // throw system_error + throw std::detail::stop_request(); // runtime_error( "Stop request (normal flow)" ); + } else if ( r == 0 ) { + throw runtime_error( "Read pipe return 0" ); } - _xsockaddr addr; - socklen_t sz = sizeof( sockaddr_in ); - bool _in_buf; - - do { - _in_buf = false; - _pfd[0].revents = 0; - _pfd[1].revents = 0; - while ( poll( &_pfd[0], _pfd.size(), -1 ) < 0 ) { // wait infinite - if ( errno == EINTR ) { // may be interrupted, check and ignore - errno = 0; - continue; + switch ( _ctl.cmd ) { + case listener: + ev_add.events = EPOLLIN | EPOLLRDHUP | EPOLLERR | EPOLLHUP | EPOLLET | EPOLLONESHOT; + ev_add.data.fd = static_cast<socks_processor_t*>(_ctl.data.ptr)->fd(); + if ( ev_add.data.fd >= 0 ) { + if ( fcntl( ev_add.data.fd, F_SETFL, fcntl( ev_add.data.fd, F_GETFL ) | O_NONBLOCK ) != 0 ) { + // std::cerr << "xxx " << errno << " " << std::tr2::getpid() << std::endl; + throw std::runtime_error( "can't establish nonblock mode on listener" ); + } + if ( descr.find( ev_add.data.fd ) != descr.end() ) { // reuse? + if ( epoll_ctl( efd, EPOLL_CTL_MOD, ev_add.data.fd, &ev_add ) < 0 ) { + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + // descr.erase( ev_add.data.fd ); + // throw system_error + return; + } + } else { + // std::cerr << __FILE__ << ":" << __LINE__ << " " << ev_add.data.fd << std::endl; + if ( epoll_ctl( efd, EPOLL_CTL_ADD, ev_add.data.fd, &ev_add ) < 0 ) { + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + // throw system_error + return; + } + } + descr[ev_add.data.fd] = fd_info( static_cast<socks_processor_t*>(_ctl.data.ptr) ); } - return false; // poll wait infinite, so it can't return 0 (timeout), so it return -1. - } + break; + case tcp_buffer: + 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 ) { + if ( descr.find( ev_add.data.fd ) != descr.end() ) { // reuse? + if ( epoll_ctl( efd, EPOLL_CTL_MOD, ev_add.data.fd, &ev_add ) < 0 ) { + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + // descr.erase( ev_add.data.fd ); + // throw system_error + return; + } + } else { + // std::cerr << __FILE__ << ":" << __LINE__ << " " << ev_add.data.fd << std::endl; + if ( epoll_ctl( efd, EPOLL_CTL_ADD, ev_add.data.fd, &ev_add ) < 0 ) { + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + // throw system_error + return; + } + } + descr[ev_add.data.fd] = fd_info( static_cast<sockbuf_t*>(_ctl.data.ptr) ); + } + 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( lfd ); + } + // dump_descr(); + } + break; + case rqstop: + // std::cerr << "Stop request\n"; + throw std::detail::stop_request(); // runtime_error( "Stop request (normal flow)" ); + // break; + } +} - // New connction open before data read from opened sockets. - // This policy may be worth to revise. - - if ( (_pfd[0].revents & POLLERR) != 0 || (_pfd[1].revents & POLLERR) != 0 ) { - return false; // return 0 only for binded socket, or control socket +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 | EPOLLHUP | EPOLLERR) ) { + // 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 ( _pfd[0].revents != 0 ) { - xmt::scoped_lock lk(_fd_lck); - if ( !is_open_unsafe() ) { // may be already closed - return false; + if ( ifd->second.p != 0 ) { + ifd->second.p->close(); + for ( typename fd_container_type::iterator i = descr.begin(); i != descr.end(); ++i ) { + if ( (i->second.p == ifd->second.p) && (i->second.b != 0) ) { + i->second.b->shutdown( sock_base::stop_in | sock_base::stop_out ); + } } - // poll 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 false; - } + } - try { - xmt::scoped_lock _l( _c_lock ); - _M_c.push_back( _Connect() ); - _M_c.back().open( _sd, addr.any ); - _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.end() ); - _pool_cnd.set( true ); - _observer_cnd.set( true ); - _in_buf = true; - } + listeners_final.insert(static_cast<void *>(ifd->second.p)); - pollfd newfd; + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; - newfd.fd = _sd; - newfd.events = POLLIN; - newfd.revents = 0; + socks_processor_t* p = ifd->second.p; - _pfd.push_back( newfd ); - } - catch ( ... ) { - } - } - 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; + descr.erase( ifd ); - _pfd.push_back( rfd ); + int lfd = check_closed_listener( p ); + + if ( lfd != -1 ) { + descr.erase( lfd ); } - } while ( !_shift_fd() && !_in_buf ); - - return true; // something was pushed in connection queue (by _shift_fd) -} -template <class Connect, void (Connect::*C)( std::sockstream& ), void (Connect::*T)() > -bool sockmgr_stream_MP<Connect,C,T>::accept_udp() -{ - if ( !is_open() ) { - return false; + // dump_descr(); + + return; } - _xsockaddr addr; + if ( (ev.events & EPOLLIN) == 0 ) { + // std::cerr << __FILE__ << ":" << __LINE__ << " " << std::hex << ev.events << std::dec << std::endl; + return; // I don't know what to do this case... + } + + sockaddr addr; 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 ... + fd_info info = ifd->second; - // 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 + fd_in_work], /* _pfd.size() */ 2 - fd_in_work, -1 ) < 0 ) { // wait infinite - if ( errno == EINTR ) { // may be interrupted, check and ignore + for ( ; ; ) { + int fd = accept( ev.data.fd, &addr, &sz ); + if ( fd < 0 ) { + // std::cerr << __FILE__ << ":" << __LINE__ /* << " " << std::tr2::getpid() */ << std::endl; + if ( (errno == EINTR) || (errno == ECONNABORTED) /* || (errno == ERESTARTSYS) */ ) { + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; errno = 0; continue; } - return false; // poll wait infinite, so it can't return 0 (timeout), so it return -1. - } + if ( !(errno == EAGAIN /* || errno == EWOULDBLOCK */ ) ) { // EWOULDBLOCK == EAGAIN + // std::cerr << __FILE__ << ":" << __LINE__ << " " << ifd->first << std::endl; + if ( epoll_ctl( efd, EPOLL_CTL_DEL, ifd->first, 0 ) < 0 ) { + std::cerr << __FILE__ << ":" << __LINE__ << " " << ifd->first << " " + << errno << std::endl; + // throw system_error + } - // New connction open before data read from opened sockets. - // This policy may be worth to revise. - - if ( (_pfd[0].revents & POLLERR) != 0 /* || (_pfd[1].revents & POLLERR) != 0 */ ) { - return false; // return 0 only for binded socket, or control socket - } - - if ( _pfd[0].revents != 0 ) { - xmt::scoped_lock lk(_fd_lck); - if ( !is_open_unsafe() ) { // may be already closed - return false; - } - try { - xmt::scoped_lock _l( _c_lock ); - // - if ( _M_c.empty() ) { - _M_c.push_back( _Connect() ); - // 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; + if ( ifd->second.p != 0 ) { + ifd->second.p->close(); + for ( typename fd_container_type::iterator i = descr.begin(); i != descr.end(); ++i ) { + if ( (i->second.p == ifd->second.p) && (i->second.b != 0) ) { + i->second.b->shutdown( sock_base::stop_in | sock_base::stop_out ); + } } - } 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(); - // } - // - // ... - // - } - catch ( ... ) { - } - } - if ( _pfd[1].revents != 0 ) { // fd come back for poll - // 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; - } - } while ( /* !_shift_fd() && */ !_in_buf ); - return true; -} + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; -template <class Connect, void (Connect::*C)( std::sockstream& ), void (Connect::*T)() > -void sockmgr_stream_MP<Connect,C,T>::_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 ); + socks_processor_t* p = ifd->second.p; + listeners_final.insert( static_cast<void *>(p) ); - me->close(); -#else -#error "Fix me!" -#endif -} + descr.erase( ifd ); -template <class Connect, void (Connect::*C)( std::sockstream& ), void (Connect::*T)() > -xmt::Thread::ret_t sockmgr_stream_MP<Connect,C,T>::loop( void *p ) -{ - _Self_type *me = static_cast<_Self_type *>(p); - me->loop_thr.pword( _idx ) = me; // push pointer to self for signal processing - xmt::Thread::ret_t rtc = 0; - xmt::Thread::ret_t rtc_observer = 0; + check_closed_listener( p ); - xmt::Thread thr_observer; - - try { - me->_loop_cnd.set( true ); - - me->_follow = true; - - while ( (me->*me->_accept)() /* && me->_is_follow() */ ) { - if ( thr_observer.bad() ) { - if ( thr_observer.is_join_req() ) { - rtc_observer = thr_observer.join(); - if ( rtc_observer != 0 ) { - rtc = reinterpret_cast<xmt::Thread::ret_t>(-2); // there was connect_processor that was killed - } + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + // dump_descr(); + } else { // back to listen + errno = 0; + epoll_event xev; + xev.events = EPOLLIN | EPOLLRDHUP | EPOLLERR | EPOLLHUP | EPOLLET | EPOLLONESHOT; + xev.data.fd = ev.data.fd; + if ( epoll_ctl( efd, EPOLL_CTL_MOD, ev.data.fd, &xev ) < 0 ) { + std::cerr << __FILE__ << ":" << __LINE__ << " " << ev.data.fd << " " + << errno << std::endl; } - thr_observer.launch( observer, me, 0, PTHREAD_STACK_MIN * 2 ); } + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + return; } - } - catch ( ... ) { - rtc = reinterpret_cast<xmt::Thread::ret_t>(-1); - } + 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 { + epoll_event ev_add; + ev_add.events = EPOLLIN | EPOLLRDHUP | EPOLLERR | EPOLLHUP | EPOLLET | EPOLLONESHOT; + ev_add.data.fd = fd; - xmt::block_signal( SIGINT ); - xmt::block_signal( SIGPIPE ); - xmt::block_signal( SIGCHLD ); - xmt::block_signal( SIGPOLL ); + if ( descr.find( fd ) != descr.end() ) { // reuse? + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + if ( epoll_ctl( efd, EPOLL_CTL_MOD, fd, &ev_add ) < 0 ) { + std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << " " << errno << std::endl; + descr.erase( fd ); + // throw system_error + return; // throw + } + } else { + // std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; + if ( epoll_ctl( efd, EPOLL_CTL_ADD, fd, &ev_add ) < 0 ) { + // throw system_error + std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << " " << errno << std::endl; + return; // throw + } + } - me->_dlock.lock(); - me->_follow = false; - me->_pool_cnd.set( true, true ); - me->_observer_cnd.set( true ); - me->_dlock.unlock(); + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + sockbuf_t* b = (*info.p)( fd, addr ); + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; - // me->_c_lock.lock(); - ::close( me->_cfd ); - ::close( me->_pfd[1].fd ); - me->close(); - // me->_c_lock.unlock(); - rtc_observer = thr_observer.join(); - - xmt::scoped_lock _l( me->_c_lock ); - me->_M_c.clear(); // FIN still may not come yet; force close - if ( rtc_observer != 0 && rtc == 0 ) { - rtc = reinterpret_cast<xmt::Thread::ret_t>(-2); // there was connect_processor that was killed + descr[fd] = fd_info( b, info.p ); + } + catch ( const std::bad_alloc& ) { + // nothing + descr.erase( fd ); + } + catch ( ... ) { + descr.erase( fd ); + } } - - return rtc; } -template <class Connect, void (Connect::*C)( std::sockstream& ), void (Connect::*T)() > -xmt::Thread::ret_t sockmgr_stream_MP<Connect,C,T>::connect_processor( void *p ) +template<class charT, class traits, class _Alloc> +void sockmgr<charT,traits,_Alloc>::process_regular( epoll_event& ev, typename sockmgr<charT,traits,_Alloc>::fd_container_type::iterator ifd ) { - _Self_type *me = static_cast<_Self_type *>(p); + fd_info& info = ifd->second; - try { - timespec idle( me->_idle ); - typename _Sequence::iterator c; + sockbuf_t* b = info.b; + if ( b == 0 ) { // marginal case: sockbuf wasn't created by processor... + // std::cerr << __FILE__ << ":" << __LINE__ << " " << ifd->first << std::endl; + if ( epoll_ctl( efd, EPOLL_CTL_DEL, ifd->first, 0 ) < 0 ) { + std::cerr << __FILE__ << ":" << __LINE__ << " " << ifd->first << " " << errno << std::endl; + // throw system_error + } + if ( info.p != 0 ) { // ... but controlled by processor + (*info.p)( ifd->first, typename socks_processor_t::adopt_close_t() ); - { - xmt::scoped_lock lk(me->_dlock); - if ( me->_conn_pool.empty() ) { - me->_pool_cnd.set( false ); - me->_observer_cnd.set( false ); - return 0; + socks_processor_t* p = info.p; + descr.erase( ifd ); + int lfd = check_closed_listener( p ); + if ( lfd != -1 ) { + descr.erase( lfd ); } - c = me->_conn_pool.front(); - me->_conn_pool.pop_front(); - xmt::gettime( &me->_tpop ); + } else { + descr.erase( ifd ); } + return; + } - do { - sockstream& stream = c->s; - if ( stream.is_open() ) { - (c->_proc->*C)( stream ); - if ( stream.is_open() && stream.good() ) { - if ( stream.rdbuf()->in_avail() > 0 ) { - // socket has buffered data, push it back to queue - xmt::scoped_lock lk(me->_dlock); - me->_conn_pool.push_back( c ); - me->_observer_cnd.set( true ); - me->_pool_cnd.set( true ); - if ( !me->_follow ) { - break; - } - c = me->_conn_pool.front(); - me->_conn_pool.pop_front(); - xmt::gettime( &me->_tpop ); - // xmt::Thread::gettime( &me->_tpush ); - continue; - } else { // no buffered data, return socket to poll - sock_base::socket_type rfd = stream.rdbuf()->fd(); - ::write( me->_cfd, reinterpret_cast<const char *>(&rfd), sizeof(sock_base::socket_type) ); - } - } else { - me->_dlock.lock(); - me->_conn_pool.erase( std::remove( me->_conn_pool.begin(), me->_conn_pool.end(), c ), me->_conn_pool.end() ); - me->_dlock.unlock(); + errno = 0; - xmt::scoped_lock _l( me->_c_lock ); - me->_M_c.erase( c ); + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + if ( ev.events & EPOLLIN ) { + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + for ( ; ; ) { + if ( b->_ebuf == b->egptr() ) { + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + // process extract data from buffer too slow for us! + if ( (info.flags & fd_info::level_triggered) == 0 ) { + epoll_event xev; + xev.events = EPOLLIN | EPOLLRDHUP | EPOLLERR | EPOLLHUP; + xev.data.fd = ev.data.fd; + info.flags |= fd_info::level_triggered; + if ( epoll_ctl( efd, EPOLL_CTL_MOD, ev.data.fd, &xev ) < 0 ) { + std::cerr << __FILE__ << ":" << __LINE__ << " " << ev.data.fd << " " << errno << std::endl; + } } + if ( info.p != 0 ) { + (*info.p)( ev.data.fd ); + } + break; } - { - xmt::scoped_lock lk(me->_dlock); - if ( me->_conn_pool.empty() ) { - lk.unlock(); - if ( me->_pool_cnd.try_wait_delay( &idle ) != 0 ) { - lk.lock(); - me->_pool_cnd.set( false ); - me->_observer_cnd.set( false ); - return 0; + long offset = read( ev.data.fd, b->egptr(), sizeof(charT) * (b->_ebuf - b->egptr()) ); + + if ( offset < 0 ) { + switch ( errno ) { + case EINTR: // read was interrupted + errno = 0; + continue; + break; + case EFAULT: // Bad address + case ECONNRESET: // Connection reset by peer + errno = 0; + ev.events |= EPOLLRDHUP; // will be processed below + break; + case EAGAIN: + // case EWOULDBLOCK: + errno = 0; + { + epoll_event xev; + xev.events = EPOLLIN | EPOLLRDHUP | EPOLLERR | EPOLLHUP | EPOLLET | EPOLLONESHOT; + xev.data.fd = ev.data.fd; + if ( epoll_ctl( efd, EPOLL_CTL_MOD, ev.data.fd, &xev ) < 0 ) { + std::cerr << __FILE__ << ":" << __LINE__ << " " << ev.data.fd << " " << errno << std::endl; + } + } + break; + default: + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + break; + } + break; + } else if ( offset > 0 ) { + offset /= sizeof(charT); // if offset % sizeof(charT) != 0, rest will be lost! + + if ( info.flags & fd_info::level_triggered ) { + epoll_event xev; + xev.events = EPOLLIN | EPOLLRDHUP | EPOLLERR | EPOLLHUP | EPOLLET | EPOLLONESHOT; + xev.data.fd = ev.data.fd; + info.flags &= ~static_cast<unsigned>(fd_info::level_triggered); + if ( epoll_ctl( efd, EPOLL_CTL_MOD, ev.data.fd, &xev ) < 0 ) { + std::cerr << __FILE__ << ":" << __LINE__ << " " << ev.data.fd << " " << errno << std::endl; } - if ( !me->_is_follow() ) { // before _conn_pool.front() - return 0; - } - lk.lock(); - if ( me->_conn_pool.empty() ) { - return 0; - } } - c = me->_conn_pool.front(); - me->_conn_pool.pop_front(); - xmt::gettime( &me->_tpop ); + std::tr2::lock_guard<std::tr2::mutex> lk( b->ulck ); + b->setg( b->eback(), b->gptr(), b->egptr() + offset ); + b->ucnd.notify_one(); + if ( info.p != 0 ) { + // std::cerr << __FILE__ << ":" << __LINE__ << " " << ev.data.fd << std::endl; + (*info.p)( ev.data.fd ); + } + } else { + // std::cerr << __FILE__ << ":" << __LINE__ << " " << ev.data.fd << std::endl; + // EPOLLRDHUP may be missed in kernel, but offset 0 is the same + ev.events |= EPOLLRDHUP; // will be processed below + break; } - } while ( me->_is_follow() ); + } } - catch ( ... ) { - return reinterpret_cast<xmt::Thread::ret_t>(-1); - } - return 0; -} + 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; + } -template <class Connect, void (Connect::*C)( std::sockstream& ), void (Connect::*T)() > -xmt::Thread::ret_t sockmgr_stream_MP<Connect,C,T>::observer( void *p ) -{ - _Self_type *me = static_cast<_Self_type *>(p); - xmt::Thread::ret_t rtc = 0; - int pool_size[3]; - // size_t thr_pool_size[3]; - timespec tpop; - timespec delta( me->_busylimit ); - timespec alarm( me->_alarm ); + 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; - timespec idle( me->_idle ); + socks_processor_t* p = info.p; - timespec now; - std::fill( pool_size, pool_size + 3, 0 ); + descr.erase( ifd ); - try { - xmt::ThreadMgr mgr; + int lfd = check_closed_listener( p ); + if ( lfd != -1 ) { + descr.erase( lfd ); + } + } else { + b->_notify_close = false; // avoid deadlock + // 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; + } + descr.erase( ifd ); + b->close(); + } + // dump_descr(); + } + // if ( ev.events & EPOLLHUP ) { + // std::cerr << "Poll HUP" << std::endl; + // } + // if ( ev.events & EPOLLERR ) { + // std::cerr << "Poll ERR" << std::endl; + // } + if ( ev.events & EPOLLPRI ) { + std::cerr << "Poll PRI" << std::endl; + } + if ( ev.events & EPOLLRDNORM ) { + std::cerr << "Poll RDNORM" << std::endl; + } + if ( ev.events & EPOLLRDBAND ) { + std::cerr << "Poll RDBAND" << std::endl; + } + if ( ev.events & EPOLLMSG ) { + std::cerr << "Poll MSG" << std::endl; + } +} - mgr.launch( connect_processor, me /* , 0, 0, PTHREAD_STACK_MIN * 2 */ ); +template<class charT, class traits, class _Alloc> +int sockmgr<charT,traits,_Alloc>::check_closed_listener( socks_processor_t* p ) +{ + int myfd = -1; - do { - // std::swap( pool_size[0], pool_size[1] ); - std::rotate( pool_size, pool_size, pool_size + 3 ); - { - xmt::scoped_lock lk(me->_dlock); - pool_size[2] = static_cast<int>(me->_conn_pool.size()); - tpop = me->_tpop; - } - if ( pool_size[2] != 0 ) { - if ( me->_thr_limit > mgr.size() ) { - if ( (pool_size[0] - 2 * pool_size[1] + pool_size[2]) > 0 || - pool_size[2] > me->_thr_limit - /* pool_size[1] > 3 && pool_size[0] <= pool_size[1] */ ) { - // queue not empty and not decrease - mgr.launch( connect_processor, me /* , 0, 0, PTHREAD_STACK_MIN * 2 */ ); - } else { - xmt::gettime( &now ); - if ( (tpop + delta) < now ) { - // a long time was since last pop from queue - mgr.launch( connect_processor, me /* , 0, 0, PTHREAD_STACK_MIN * 2 */ ); - } + 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; } - mgr.garbage_collector(); - xmt::delay( &alarm ); - } else { - if ( /* me->_is_follow() && */ me->_observer_cnd.try_wait_delay( &idle ) != 0 && mgr.size() == 0 ) { - return rtc; - } } - } while ( me->_is_follow() ); + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; - int count = 24; - while ( mgr.size() > 0 && count > 0 ) { - me->_pool_cnd.set( true, true ); - xmt::delay( &alarm ); - alarm *= 1.2; - --count; + // no more connection with this listener + listeners_final.erase( static_cast<void*>(p) ); + + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + + // if ( myfd != -1 ) { + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + p->stop(); + // } } - if ( mgr.size() > 0 ) { - mgr.signal( SIGTERM ); - rtc = reinterpret_cast<xmt::Thread::ret_t>(-1); - } } - catch ( ... ) { - rtc = reinterpret_cast<xmt::Thread::ret_t>(-1); - } - return rtc; + return myfd; } -#endif // !__FIT_NO_POLL +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; + } +} -#ifdef STLPORT -_STLP_END_NAMESPACE -#else + +} // namespace detail + } // namespace std -#endif Modified: trunk/complement/explore/include/sockios/sockmgr.h =================================================================== --- trunk/complement/explore/include/sockios/sockmgr.h 2008-06-27 10:28:54 UTC (rev 1923) +++ trunk/complement/explore/include/sockios/sockmgr.h 2008-06-27 11:20:41 UTC (rev 1924) @@ -1,351 +1,350 @@ -// -*- C++ -*- Time-stamp: <07/09/06 21:23:52 ptr> +// -*- C++ -*- Time-stamp: <08/06/27 00:50:33 ptr> /* - * Copyright (c) 1997-1999, 2002, 2003, 2005-2007 + * Copyright (c) 2008 * Petr Ovtchenkov * - * Portion Copyright (c) 1999-2001 - * Parallel Graphics Ltd. - * * Licensed under the Academic Free License Version 3.0 * */ -#ifndef __SOCKMGR_H -#define __SOCKMGR_H +#ifndef __SOCKIOS_SOCKMGR_H +#define __SOCKIOS_SOCKMGR_H -#ifndef __config_feature_h -#include <config/feature.h> -#endif +#include <sys/epoll.h> -#ifndef __SOCKSTREAM__ -#include <sockios/sockstream> +#ifndef EPOLLRDHUP +# define EPOLLRDHUP 0x2000 #endif -#include <vector> -#include <deque> +#include <fcntl.h> + #include <cerrno> +#include <mt/thread> +#include <mt/mutex> +#include <mt/condition_variable> -#ifndef __XMT_H -#include <mt/xmt.h> -#endif +#include <sockios/socksrv.h> -#ifndef __THR_MGR_H -#include <mt/thr_mgr.h> +#ifdef STLPORT +# include <unordered_map> +# include <unordered_set> +// # include <hash_map> +// # include <hash_set> +// # define __USE_STLPORT_HASH +# define __USE_STLPORT_TR1 +#else +# if defined(__GNUC__) && (__GNUC__ < 4) +# include <ext/hash_map> +# include <ext/hash_set> +# define __USE_STD_HASH +# else +# include <tr1/unordered_map> +# include <tr1/unordered_set> +# define __USE_STD_TR1 +# endif #endif -#ifdef __unix -#include <poll.h> -#endif +#include <sockios/sockstream> +#include <deque> +#include <functional> -#ifdef STLPORT -_STLP_BEGIN_NAMESPACE -#else namespace std { -#endif -union _xsockaddr { - sockaddr_in inet; - sockaddr any; +template <class charT, class traits, class _Alloc> class basic_sockbuf; +template <class charT, class traits, class _Alloc> class basic_sockstream; +template <class charT, class traits, class _Alloc> class sock_processor_base; + + +template <class charT, class traits, class _Alloc> class basic_sockbuf; + +namespace detail { + +class stop_request : + public std::exception +{ + public: + virtual const char* what() throw() + { return "sockmgr receive stop reqest"; } }; -class basic_sockmgr : - public sock_base +template<class charT, class traits, class _Alloc> +class sockmgr { private: - class Init - { - public: - Init(); - ~Init(); - private: - static void _guard( int ); - static void __at_fork_prepare(); - static void __at_fork_child(); - static void __at_fork_parent(); + typedef basic_sockstream<charT,traits,_Alloc> sockstream_t; + typedef basic_sockbuf<charT,traits,_Alloc> sockbuf_t; + typedef sock_processor_base<charT,traits,_Alloc> socks_processor_t; + + enum { + listener, + tcp_buffer, + rqstop, + rqstart, + listener_on_exit }; - public: - basic_sockmgr(); - virtual ~basic_sockmgr(); + struct fd_info + { + enum { + listener = 0x1, + level_triggered = 0x2 + }; - protected: - __FIT_DECLSPEC void open( const in_addr& addr, int port, sock_base::stype type, sock_base::protocol prot ); - __FIT_DECLSPEC void open( unsigned long addr, int port, sock_base::stype type, sock_base::protocol prot ); - __FIT_DECLSPEC void open( int port, sock_base::stype type, sock_base::protocol prot ); + fd_info() : + flags(0U), + b(0), + p(0) + { } - virtual __FIT_DECLSPEC void close(); - bool is_open_unsafe() const - { return _fd != -1; } - sock_base::socket_type fd_unsafe() const - { return _fd; } - __FIT_DECLSPEC - void setoptions_unsafe( sock_base::so_t optname, bool on_off = true, - int __v = 0 ); + fd_info( unsigned f, sockbuf_t* buf, socks_processor_t* proc ) : + flags(f), + b(buf), + p(proc) + { } - public: - bool is_open() const - { xmt::scoped_lock lk(_fd_lck); return is_open_unsafe(); } - bool good() const - { return _state == ios_base::goodbit; } + fd_info( sockbuf_t* buf, socks_processor_t* proc ) : + flags(0U), + b(buf), + p(proc) + { } - sock_base::socket_type fd() const - { xmt::scoped_lock lk(_fd_lck); sock_base::socket_type tmp = fd_unsafe(); return tmp; } + fd_info( sockbuf_t* buf ) : + flags(0U), + b(buf), + p(0) + { } - __FIT_DECLSPEC - void shutdown( sock_base::shutdownflg dir ); - void setoptions( sock_base::so_t optname, bool on_off = true, - int __v = 0 ) - { - xmt::scoped_lock lk(_fd_lck); - setoptions_unsafe( optname, on_off, __v ); - } + fd_info( socks_processor_t* proc ) : + flags(listener), + b(0), + p(proc) + { } - private: - basic_sockmgr( const basic_sockmgr& ); - basic_sockmgr& operator =( const basic_sockmgr& ); + fd_info( const fd_info& info ) : + flags( info.flags ), + b( info.b ), + p( info.p ) + { } - private: - sock_base::socket_type _fd; // master socket - unsigned long _mode; // open mode - unsigned long _state; // state flags - int _errno; // error state - _xsockaddr _address; + unsigned flags; + sockbuf_t* b; + socks_processor_t* p; + }; - protected: - static int _idx; - friend class Init; + struct ctl + { + int cmd; + union { + sock_base::socket_type fd; + void *ptr; + } data; + }; - protected: - xmt::mutex _fd_lck; - xmt::condition _loop_cnd; -}; + static void _loop( sockmgr *me ) + { me->io_worker(); } -class ConnectionProcessorTemplate_MP // As reference -{ public: - ConnectionProcessorTemplate_MP( std::sockstream& ) - { } + sockmgr( int hint = 1024, int ret = 512 ) : + n_ret( ret ) + { + efd = epoll_create( hint ); + if ( efd < 0 ) { + // throw system_error( errno ) + throw std::runtime_error( "epoll_create" ); + } + if ( pipe( pipefd ) < 0 ) { // check err + ::close( efd ); + // throw system_error; + throw std::runtime_error( "pipe" ); + } + // cfd = pipefd[1]; - void connect( std::sockstream& ) - { } - void close() - { } -}; + epoll_event ev_add; + ev_add.events = EPOLLIN | EPOLLRDHUP | EPOLLERR | EPOLLHUP; + ev_add.data.fd = pipefd[0]; + epoll_ctl( efd, EPOLL_CTL_ADD, pipefd[0], &ev_add ); -#ifndef __FIT_NO_POLL + _worker = new std::tr2::thread( _loop, this ); -template <class Connect, void (Connect::*C)( std::sockstream& ) = &Connect::connect, void (Connect::*T)() = &Connect::close > -class sockmgr_stream_MP : - public basic_sockmgr -{ - public: - sockmgr_stream_MP() : - basic_sockmgr(), - _thr_limit( 31 ) - { - _busylimit.tv_sec = 0; - _busylimit.tv_nsec = 90000000; // i.e 0.09 sec - _alarm.tv_sec = 0; - _alarm.tv_nsec = 50000000; // i.e 0.05 sec - _idle.tv_sec = 10; - _idle.tv_nsec = 0; // i.e 10 sec + // ctl _ctl; + // _ctl.cmd = rqstart; + + // write( pipefd[1], &_ctl, sizeof(ctl) ); } - explicit sockmgr_stream_MP( const in_addr& addr, int port, sock_base::stype t = sock_base::sock_stream ) : - basic_sockmgr(), - _thr_limit( 31 ) + ~sockmgr() { - open( addr, port, t ); - _busylimit.tv_sec = 0; - _busylimit.tv_nsec = 90000000; // i.e 0.09 sec - _alarm.tv_sec = 0; - _alarm.tv_nsec = 50000000; // i.e 0.05 sec - _idle.tv_sec = 10; - _idle.tv_nsec = 0; // i.e 10 sec + if ( _worker->joinable() ) { + ctl _ctl; + _ctl.cmd = rqstop; + _ctl.data.ptr = 0; + + ::write( pipefd[1], &_ctl, sizeof(ctl) ); + + _worker->join(); + } + ::close( pipefd[1] ); + ::close( pipefd[0] ); + ::close( efd ); + delete _worker; } - explicit sockmgr_stream_MP( unsigned long addr, int port, sock_base::stype t = sock_base::sock_stream ) : - basic_sockmgr(), - _thr_limit( 31 ) + void push( socks_processor_t& p ) { - open( addr, port, t ); - _busylimit.tv_sec = 0; - _busylimit.tv_nsec = 90000000; // i.e 0.09 sec - _alarm.tv_sec = 0; - _alarm.tv_nsec = 50000000; // i.e 0.05 sec - _idle.tv_sec = 10; - _idle.tv_nsec = 0; // i.e 10 sec + ctl _ctl; + _ctl.cmd = listener; + _ctl.data.ptr = static_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" ); + } } - explicit sockmgr_stream_MP( int port, sock_base::stype t = sock_base::sock_stream ) : - basic_sockmgr(), - _thr_limit( 31 ) + void push( sockbuf_t& s ) { - open( port, t ); - _busylimit.tv_sec = 0; - _busylimit.tv_nsec = 50000000; // i.e 0.05 sec - _alarm.tv_sec = 0; - _alarm.tv_nsec = 50000000; // i.e 0.05 sec - _idle.tv_sec = 10; - _idle.tv_nsec = 0; // i.e 10 sec + ctl _ctl; + _ctl.cmd = tcp_buffer; + _ctl.data.ptr = static_cast<void *>(&s); + + errno = 0; + int r = ::write( pipefd[1], &_ctl, sizeof(ctl) ); + if ( r < 0 || r != sizeof(ctl) ) { + throw std::runtime_error( "can't write to pipe" ); + } } - ~sockmgr_stream_MP() - { loop_thr.join(); } + void pop( socks_processor_t& p, sock_base::socket_type _fd ) + { + ctl _ctl; + _ctl.cmd = listener_on_exit; + _ctl.data.ptr = reinterpret_cast<void *>(&p); - private: - sockmgr_stream_MP( const sockmgr_stream_MP<Connect,C,T>& ); - sockmgr_stream_MP<Connect,C,T>& operator =( const sockmgr_stream_MP<Connect,C,T>& ); + int r = ::write( pipefd[1], &_ctl, sizeof(ctl) ); + if ( r < 0 || r != sizeof(ctl) ) { + throw std::runtime_error( "can't write to pipe" ); + } + } - public: - 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 ); + void exit_notify( sockbuf_t* b, sock_base::socket_type fd ) + { + try { + std::tr2::unique_lock<std::tr2::mutex> lk( dll, std::tr2::defer_lock ); - virtual void close() - { basic_sockmgr::close(); } + if ( lk.try_lock() ) { + if ( b->_notify_close ) { + // std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; + typename fd_container_type::iterator i = descr.find( fd ); + if ( (i != descr.end()) && (i->second.b == b) && (i->second.p == 0) ) { + // std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; + if ( epoll_ctl( efd, EPOLL_CTL_DEL, fd, 0 ) < 0 ) { + // std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; + // throw system_error + } + // std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; + descr.erase( i ); + } + b->_notify_close = false; + } + } + } + catch ( const std::tr2::lock_error& ) { + // std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; + } + } - void wait() - { loop_thr.join(); } - - void detach( sockstream& ) // remove sockstream from polling in manager + private: + sockmgr( const sockmgr& ) { } + sockmgr& operator =( const sockmgr& ) + { return *this; } - void setbusytime( const timespec& t ) - { _busylimit = t; } + int check_closed_listener( socks_processor_t* p ); + void dump_descr(); - void setobservertime( const timespec& t ) - { _alarm = t; } +#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 setidletime( const timespec& t ) - { _idle = t; } + void io_worker(); + void cmd_from_pipe(); + void process_listener( epoll_event&, typename fd_container_type::iterator ); + void process_regular( epoll_event&, typename fd_container_type::iterator ); - void setthreadlimit( unsigned lim ) - { _thr_limit = std::max( 3U, lim ) - 1; } + int efd; + int pipefd[2]; + std::tr2::thread *_worker; + const int n_ret; - protected: + fd_container_type descr; + listener_container_type listeners_final; + std::tr2::mutex dll; +}; - struct _Connect - { - _Connect() : - _proc( 0 ) - { } +} //detail - _Connect( const _Connect& ) : - _proc( 0 ) - { } +} // namesapce std - ~_Connect() - { if ( _proc ) { s.close(); (_proc->*T)(); delete _proc; _proc = 0; } } +#if defined(__USE_STLPORT_HASH) || defined(__USE_STLPORT_TR1) || defined(__USE_STD_TR1) +# define __HASH_NAMESPACE std +#endif +#if defined(__USE_STD_HASH) +# define __HASH_NAMESPACE __gnu_cxx +#endif - void open( sock_base::socket_type st, const sockaddr& addr, sock_base::stype t = sock_base::sock_stream ) - { s.open( st, addr, t ); _proc = new Connect( s ); } +namespace __HASH_NAMESPACE { - sockstream s; - Connect *_proc; - }; +#ifdef __USE_STD_TR1 +namespace tr1 { +#endif - typedef std::vector<pollfd> _fd_sequence; - typedef std::list<_Connect> _Sequence; - typedef std::deque<typename _Sequence::iterator> _connect_pool_sequence; +template <class charT, class traits, class _Alloc> +struct hash<std::basic_sockstream<charT, traits, _Alloc>* > +{ + size_t operator()(const std::basic_sockstream<charT, traits, _Alloc>* __x) const + { return reinterpret_cast<size_t>(__x); } +}; - void _open( sock_base::stype t = sock_base::sock_stream ); - static xmt::Thread::ret_t loop( void * ); - static xmt::Thread::ret_t connect_processor( void * ); - static xmt::Thread::ret_t observer( void * ); - - 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 iaddr_equal : - public std::binary_function<_Connect,sockaddr,bool> - { - bool operator()(const _Connect& __x, const sockaddr& __y) const - { return memcmp( &(__x.s.rdbuf()->inet_sockaddr()), reinterpret_cast<const sockaddr_in *>(&__y), sizeof(sockaddr_in) ) == 0; } - }; - - struct pfd_equal : - public std::binary_function<typename _fd_sequence::value_type,int,bool> - { - bool operator()(const typename _fd_sequence::value_type& __x, int __y) const - { return __x.fd == __y; } - }; - - typedef bool (sockmgr_stream_MP<Connect,C,T>::*accept_type)(); - -#if 0 - accept_type _accept; - _Connect *accept() // workaround for CC - { return (this->*_accept)(); } -#else - accept_type _accept; +#ifdef __USE_STD_TR1 +} #endif - bool accept_tcp(); - bool accept_udp(); - private: - xmt::Thread loop_thr; - - protected: - typedef sockmgr_stream_MP<Connect,C,T> _Self_type; - typedef fd_equal _Compare; - typedef iaddr_equal _Compare_inet; - 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; - _Compare_inet _M_comp_inet; - pfd_equal _pfdcomp; - xmt::mutex _c_lock; - - _fd_sequence _pfd; - int _cfd; // sock_base::socket_type - _connect_pool_sequence _conn_pool; - xmt::condition _pool_cnd; - xmt::mutex _dlock; - timespec _tpop; - - xmt::mutex _flock; - bool _follow; - - xmt::condition _observer_cnd; - timespec _busylimit; // start new thread to process incoming - // requests, if processing thread busy - // more then _busylimit - timespec _alarm; // check and make decision about start - // new thread with _alarm interval - timespec _idle; // do nothing _idle time before thread - // terminate - - unsigned _thr_limit; - - private: - bool _shift_fd(); - static void _close_by_signal( int ); - bool _is_follow() const - { xmt::scoped_lock lk( _flock ); bool tmp = _follow; return tmp; } +#if defined(__GNUC__) && (__GNUC__ < 4) +template<> +struct hash<void *> +{ + size_t operator()(const void *__x) const + { return reinterpret_cast<size_t>(__x); } }; +#endif // __GNUC__ < 4 -#endif // !__FIT_NO_POLL +} // namespace __HASH_NAMESPACE -#ifdef STLPORT -_STLP_END_NAMESPACE -#else -} // namespace std +#undef __HASH_NAMESPACE + +#ifdef __USE_STLPORT_HASH +# undef __USE_STLPORT_HASH #endif +#ifdef __USE_STD_HASH +# undef __USE_STD_HASH +#endif +#ifdef __USE_STLPORT_TR1 +# undef __USE_STLPORT_TR1 +#endif +#ifdef __USE_STD_TR1 +# undef __USE_STD_TR1 +#endif -#ifndef __STL_LINK_TIME_INSTANTIATION #include <sockios/sockmgr.cc> -#endif -#endif // __SOCKMGR_H +#endif /* __SOCKIOS_SOCKMGR_H */ Added: trunk/complement/explore/include/sockios/socksrv.cc =================================================================== --- trunk/complement/explore/include/sockios/socksrv.cc (rev 0) +++ trunk/complement/explore/include/sockios/socksrv.cc 2008-06-27 11:20:41 UTC (rev 1924) @@ -0,0 +1,341 @@ +// -*- C++ -*- Time-stamp: <08/06/26 09:00:54 ptr> + +/* + * Copyright (c) 2008 + * Petr Ovtchenkov + * + * Licensed under the Academic Free License Version 3.0 + * + */ + +namespace std { + +template<class charT, class traits, class _Alloc> +void sock_processor_base<charT,traits,_Alloc>::open( const in_addr& addr, int port, sock_base::stype type, sock_base::protocol prot ) +{ + std::tr2::lock_guard<std::tr2::mutex> lk(_fd_lck); + if ( basic_socket_t::is_open_unsafe() ) { + return; + } + _mode = ios_base::in | ios_base::out; + _state = ios_base::goodbit; +#ifdef WIN32 + ::WSASetLastError( 0 ); +#endif + if ( prot == sock_base::inet ) { + basic_socket_t::_fd = socket( PF_INET, type, 0 ); + if ( basic_socket_t::_fd == -1 ) { + _state |= ios_base::failbit | ios_base::badbit; + return; + } + // _open = true; + basic_socket_t::_address.inet.sin_family = AF_INET; + basic_socket_t::_address.inet.sin_port = htons( port ); + basic_socket_t::_address.inet.sin_addr.s_addr = addr.s_addr; + + if ( type == sock_base::sock_stream || type == sock_base::sock_seqpacket ) { + // let's try reuse local address + setoptions_unsafe( sock_base::so_reuseaddr, true ); + } + + if ( ::bind( basic_socket_t::_fd, &basic_socket_t::_address.any, sizeof(basic_socket_t::_address) ) == -1 ) { + _state |= ios_base::failbit; +#ifdef WIN32 + ::closesocket( basic_socket_t::_fd ); +#else + ::close( basic_socket_t::_fd ); +#endif + basic_socket_t::_fd = -1; + return; + } + + if ( type == sock_base::sock_stream || type == sock_base::sock_seqpacket ) { + // I am shure, this is socket of type SOCK_STREAM | SOCK_SEQPACKET, + // so don't check return code from listen + ::listen( basic_socket_t::_fd, SOMAXCONN ); + basic_socket_t::mgr->push( *this ); + } + } else if ( prot == sock_base::local ) { + return; + } else { + return; + } + _state = ios_base::goodbit; + + return; +} + +template<class charT, class traits, class _Alloc> +void sock_processor_base<charT,traits,_Alloc>::_close() +{ + std::tr2::lock_guard<std::tr2::mutex> lk(_fd_lck); + if ( !basic_socket_t::is_open_unsafe() ) { + return; + } + // std::cerr << __FILE__ << ":" << __LINE__ << " " << basic_socket_t::_fd << 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 & ... [truncated message content] |
From: <com...@us...> - 2008-06-27 10:28:57
|
Revision: 1923 http://complement.svn.sourceforge.net/complement/?rev=1923&view=rev Author: complement Date: 2008-06-27 03:28:54 -0700 (Fri, 27 Jun 2008) Log Message: ----------- boost::filesystem build from boost 1.35.0 Modified Paths: -------------- trunk/complement/extern/custom/boost/libs/filesystem/Makefile.inc trunk/complement/extern/custom/boost/libs/filesystem/test/Makefile Modified: trunk/complement/extern/custom/boost/libs/filesystem/Makefile.inc =================================================================== --- trunk/complement/extern/custom/boost/libs/filesystem/Makefile.inc 2008-06-27 10:25:25 UTC (rev 1922) +++ trunk/complement/extern/custom/boost/libs/filesystem/Makefile.inc 2008-06-27 10:28:54 UTC (rev 1923) @@ -4,6 +4,10 @@ #BOOST_FS_SRC = src LIBNAME = boost_fs MAJOR = 1 -MINOR = 34 -PATCH = 1 -SRC_CPP = ${BOOST_FS_SRC}/exception.cpp ${BOOST_FS_SRC}/operations.cpp ${BOOST_FS_SRC}/path.cpp ${BOOST_FS_SRC}/portability.cpp ${BOOST_FS_SRC}/utf8_codecvt_facet.cpp +MINOR = 35 +PATCH = 0 +SRC_CPP = ${BOOST_FS_SRC}/operations.cpp \ + ${BOOST_FS_SRC}/path.cpp \ + ${BOOST_FS_SRC}/portability.cpp \ + ${BOOST_FS_SRC}/utf8_codecvt_facet.cpp \ + ${BOOST_INCLUDE_DIR}/libs/system/src/error_code.cpp Modified: trunk/complement/extern/custom/boost/libs/filesystem/test/Makefile =================================================================== --- trunk/complement/extern/custom/boost/libs/filesystem/test/Makefile 2008-06-27 10:25:25 UTC (rev 1922) +++ trunk/complement/extern/custom/boost/libs/filesystem/test/Makefile 2008-06-27 10:28:54 UTC (rev 1923) @@ -8,7 +8,11 @@ INCLUDES += -I${BOOST_INCLUDE_DIR} -LDFLAGS += -L${INSTALL_LIB_DIR} -Wl,-rpath=${INSTALL_LIB_DIR}:${STLPORT_LIB_DIR} +release-shared: LDFLAGS += -L../${OUTPUT_DIR} -Wl,-rpath=../${OUTPUT_DIR} +dbg-shared: LDFLAGS += -L../${OUTPUT_DIR_DBG} -Wl,-rpath=../${OUTPUT_DIR_DBG} +ifndef WITHOUT_STLPORT +stldbg-shared: LDFLAGS += -L../${OUTPUT_DIR_STLDBG} -Wl,-rpath=../${OUTPUT_DIR_STLDBG} +endif release-shared: LDLIBS = -lboost_fs dbg-shared: LDLIBS = -lboost_fsg This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-06-27 10:25:27
|
Revision: 1922 http://complement.svn.sourceforge.net/complement/?rev=1922&view=rev Author: complement Date: 2008-06-27 03:25:25 -0700 (Fri, 27 Jun 2008) Log Message: ----------- merge with svn Removed Paths: ------------- trunk/extern/custom/boost/libs/program_options/Makefile trunk/extern/custom/boost/libs/program_options/Makefile.inc trunk/extern/custom/boost/libs/serialization/Makefile trunk/extern/custom/boost/libs/serialization/Makefile.inc Deleted: trunk/extern/custom/boost/libs/program_options/Makefile =================================================================== --- trunk/extern/custom/boost/libs/program_options/Makefile 2008-06-27 10:25:01 UTC (rev 1921) +++ trunk/extern/custom/boost/libs/program_options/Makefile 2008-06-27 10:25:25 UTC (rev 1922) @@ -1,9 +0,0 @@ -# -*- makefile -*- Time-stamp: <03/03/31 15:18:29 ptr> - -SRCROOT := ../../../../../explore -COMPILER_NAME := gcc - -include Makefile.inc -include ${SRCROOT}/Makefiles/top.mak - -INCLUDES += -I${BOOST_INCLUDE_DIR} Deleted: trunk/extern/custom/boost/libs/program_options/Makefile.inc =================================================================== --- trunk/extern/custom/boost/libs/program_options/Makefile.inc 2008-06-27 10:25:01 UTC (rev 1921) +++ trunk/extern/custom/boost/libs/program_options/Makefile.inc 2008-06-27 10:25:25 UTC (rev 1922) @@ -1,19 +0,0 @@ -# -*- makefile -*- Time-stamp: <06/06/02 19:38:29 ptr> - -BOOST_SR_SRC = ${BOOST_INCLUDE_DIR}/libs/program_options/src - -LIBNAME = boost_program_options -MAJOR = 1 -MINOR = 33 -PATCH = 1 - -SRC_CPP = ${BOOST_SR_SRC}/cmdline.cpp \ - ${BOOST_SR_SRC}/config_file.cpp \ - ${BOOST_SR_SRC}/options_description.cpp \ - ${BOOST_SR_SRC}/parsers.cpp \ - ${BOOST_SR_SRC}/variables_map.cpp \ - ${BOOST_SR_SRC}/value_semantic.cpp \ - ${BOOST_SR_SRC}/positional_options.cpp \ - ${BOOST_SR_SRC}/utf8_codecvt_facet.cpp \ - ${BOOST_SR_SRC}/convert.cpp \ - ${BOOST_SR_SRC}/winmain.cpp Deleted: trunk/extern/custom/boost/libs/serialization/Makefile =================================================================== --- trunk/extern/custom/boost/libs/serialization/Makefile 2008-06-27 10:25:01 UTC (rev 1921) +++ trunk/extern/custom/boost/libs/serialization/Makefile 2008-06-27 10:25:25 UTC (rev 1922) @@ -1,11 +0,0 @@ -# -*- makefile -*- Time-stamp: <03/03/31 15:18:29 ptr> - -SRCROOT := ../../../../../explore -COMPILER_NAME := gcc -POST_INSTALL = ln -sf ${SO_NAME} $(INSTALL_LIB_DIR)/libboost_serialization-gcc-mt.so -# POST_INSTALL_DBG = ln -sf ${SO_NAME_DBG} $(INSTALL_LIB_DIR_DBG)/libboost_serialization.so - -include Makefile.inc -include ${SRCROOT}/Makefiles/top.mak - -INCLUDES += -I${BOOST_INCLUDE_DIR} Deleted: trunk/extern/custom/boost/libs/serialization/Makefile.inc =================================================================== --- trunk/extern/custom/boost/libs/serialization/Makefile.inc 2008-06-27 10:25:01 UTC (rev 1921) +++ trunk/extern/custom/boost/libs/serialization/Makefile.inc 2008-06-27 10:25:25 UTC (rev 1922) @@ -1,34 +0,0 @@ -# -*- makefile -*- Time-stamp: <06/06/02 19:38:29 ptr> - -BOOST_SR_SRC = ${BOOST_INCLUDE_DIR}/libs/serialization/src -#BOOST_SR_SRC = src -LIBNAME = boost_serialization -MAJOR = 1 -MINOR = 33 -PATCH = 1 -SRC_CPP = ${BOOST_SR_SRC}/basic_archive.cpp \ - ${BOOST_SR_SRC}/basic_archive_impl.cpp \ - ${BOOST_SR_SRC}/basic_iarchive.cpp \ - ${BOOST_SR_SRC}/basic_iserializer.cpp \ - ${BOOST_SR_SRC}/basic_oarchive.cpp \ - ${BOOST_SR_SRC}/basic_oserializer.cpp \ - ${BOOST_SR_SRC}/basic_pointer_iserializer.cpp \ - ${BOOST_SR_SRC}/basic_pointer_oserializer.cpp \ - ${BOOST_SR_SRC}/basic_serializer_map.cpp \ - ${BOOST_SR_SRC}/basic_text_iprimitive.cpp \ - ${BOOST_SR_SRC}/basic_text_oprimitive.cpp \ - ${BOOST_SR_SRC}/basic_xml_archive.cpp \ - ${BOOST_SR_SRC}/binary_iarchive.cpp \ - ${BOOST_SR_SRC}/binary_oarchive.cpp \ - ${BOOST_SR_SRC}/codecvt_null.cpp \ - ${BOOST_SR_SRC}/extended_type_info.cpp \ - ${BOOST_SR_SRC}/extended_type_info_no_rtti.cpp \ - ${BOOST_SR_SRC}/extended_type_info_typeid.cpp \ - ${BOOST_SR_SRC}/polymorphic_iarchive.cpp \ - ${BOOST_SR_SRC}/polymorphic_oarchive.cpp \ - ${BOOST_SR_SRC}/text_iarchive.cpp \ - ${BOOST_SR_SRC}/text_oarchive.cpp \ - ${BOOST_SR_SRC}/void_cast.cpp \ - ${BOOST_SR_SRC}/xml_grammar.cpp \ - ${BOOST_SR_SRC}/xml_iarchive.cpp \ - ${BOOST_SR_SRC}/xml_oarchive.cpp This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-06-27 10:25:05
|
Revision: 1921 http://complement.svn.sourceforge.net/complement/?rev=1921&view=rev Author: complement Date: 2008-06-27 03:25:01 -0700 (Fri, 27 Jun 2008) Log Message: ----------- boost::program_options Added Paths: ----------- trunk/extern/custom/boost/libs/program_options/ trunk/extern/custom/boost/libs/program_options/Makefile trunk/extern/custom/boost/libs/program_options/Makefile.inc Added: trunk/extern/custom/boost/libs/program_options/Makefile =================================================================== --- trunk/extern/custom/boost/libs/program_options/Makefile (rev 0) +++ trunk/extern/custom/boost/libs/program_options/Makefile 2008-06-27 10:25:01 UTC (rev 1921) @@ -0,0 +1,9 @@ +# -*- makefile -*- Time-stamp: <03/03/31 15:18:29 ptr> + +SRCROOT := ../../../../../explore +COMPILER_NAME := gcc + +include Makefile.inc +include ${SRCROOT}/Makefiles/top.mak + +INCLUDES += -I${BOOST_INCLUDE_DIR} Added: trunk/extern/custom/boost/libs/program_options/Makefile.inc =================================================================== --- trunk/extern/custom/boost/libs/program_options/Makefile.inc (rev 0) +++ trunk/extern/custom/boost/libs/program_options/Makefile.inc 2008-06-27 10:25:01 UTC (rev 1921) @@ -0,0 +1,19 @@ +# -*- makefile -*- Time-stamp: <06/06/02 19:38:29 ptr> + +BOOST_SR_SRC = ${BOOST_INCLUDE_DIR}/libs/program_options/src + +LIBNAME = boost_program_options +MAJOR = 1 +MINOR = 33 +PATCH = 1 + +SRC_CPP = ${BOOST_SR_SRC}/cmdline.cpp \ + ${BOOST_SR_SRC}/config_file.cpp \ + ${BOOST_SR_SRC}/options_description.cpp \ + ${BOOST_SR_SRC}/parsers.cpp \ + ${BOOST_SR_SRC}/variables_map.cpp \ + ${BOOST_SR_SRC}/value_semantic.cpp \ + ${BOOST_SR_SRC}/positional_options.cpp \ + ${BOOST_SR_SRC}/utf8_codecvt_facet.cpp \ + ${BOOST_SR_SRC}/convert.cpp \ + ${BOOST_SR_SRC}/winmain.cpp This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-06-27 10:24:47
|
Revision: 1920 http://complement.svn.sourceforge.net/complement/?rev=1920&view=rev Author: complement Date: 2008-06-27 03:24:42 -0700 (Fri, 27 Jun 2008) Log Message: ----------- boost::serialization Added Paths: ----------- trunk/extern/ trunk/extern/custom/ trunk/extern/custom/boost/ trunk/extern/custom/boost/libs/ trunk/extern/custom/boost/libs/serialization/ trunk/extern/custom/boost/libs/serialization/Makefile trunk/extern/custom/boost/libs/serialization/Makefile.inc Added: trunk/extern/custom/boost/libs/serialization/Makefile =================================================================== --- trunk/extern/custom/boost/libs/serialization/Makefile (rev 0) +++ trunk/extern/custom/boost/libs/serialization/Makefile 2008-06-27 10:24:42 UTC (rev 1920) @@ -0,0 +1,11 @@ +# -*- makefile -*- Time-stamp: <03/03/31 15:18:29 ptr> + +SRCROOT := ../../../../../explore +COMPILER_NAME := gcc +POST_INSTALL = ln -sf ${SO_NAME} $(INSTALL_LIB_DIR)/libboost_serialization-gcc-mt.so +# POST_INSTALL_DBG = ln -sf ${SO_NAME_DBG} $(INSTALL_LIB_DIR_DBG)/libboost_serialization.so + +include Makefile.inc +include ${SRCROOT}/Makefiles/top.mak + +INCLUDES += -I${BOOST_INCLUDE_DIR} Added: trunk/extern/custom/boost/libs/serialization/Makefile.inc =================================================================== --- trunk/extern/custom/boost/libs/serialization/Makefile.inc (rev 0) +++ trunk/extern/custom/boost/libs/serialization/Makefile.inc 2008-06-27 10:24:42 UTC (rev 1920) @@ -0,0 +1,34 @@ +# -*- makefile -*- Time-stamp: <06/06/02 19:38:29 ptr> + +BOOST_SR_SRC = ${BOOST_INCLUDE_DIR}/libs/serialization/src +#BOOST_SR_SRC = src +LIBNAME = boost_serialization +MAJOR = 1 +MINOR = 33 +PATCH = 1 +SRC_CPP = ${BOOST_SR_SRC}/basic_archive.cpp \ + ${BOOST_SR_SRC}/basic_archive_impl.cpp \ + ${BOOST_SR_SRC}/basic_iarchive.cpp \ + ${BOOST_SR_SRC}/basic_iserializer.cpp \ + ${BOOST_SR_SRC}/basic_oarchive.cpp \ + ${BOOST_SR_SRC}/basic_oserializer.cpp \ + ${BOOST_SR_SRC}/basic_pointer_iserializer.cpp \ + ${BOOST_SR_SRC}/basic_pointer_oserializer.cpp \ + ${BOOST_SR_SRC}/basic_serializer_map.cpp \ + ${BOOST_SR_SRC}/basic_text_iprimitive.cpp \ + ${BOOST_SR_SRC}/basic_text_oprimitive.cpp \ + ${BOOST_SR_SRC}/basic_xml_archive.cpp \ + ${BOOST_SR_SRC}/binary_iarchive.cpp \ + ${BOOST_SR_SRC}/binary_oarchive.cpp \ + ${BOOST_SR_SRC}/codecvt_null.cpp \ + ${BOOST_SR_SRC}/extended_type_info.cpp \ + ${BOOST_SR_SRC}/extended_type_info_no_rtti.cpp \ + ${BOOST_SR_SRC}/extended_type_info_typeid.cpp \ + ${BOOST_SR_SRC}/polymorphic_iarchive.cpp \ + ${BOOST_SR_SRC}/polymorphic_oarchive.cpp \ + ${BOOST_SR_SRC}/text_iarchive.cpp \ + ${BOOST_SR_SRC}/text_oarchive.cpp \ + ${BOOST_SR_SRC}/void_cast.cpp \ + ${BOOST_SR_SRC}/xml_grammar.cpp \ + ${BOOST_SR_SRC}/xml_iarchive.cpp \ + ${BOOST_SR_SRC}/xml_oarchive.cpp This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-06-26 05:47:14
|
Revision: 1919 http://complement.svn.sourceforge.net/complement/?rev=1919&view=rev Author: complement Date: 2008-06-25 22:47:07 -0700 (Wed, 25 Jun 2008) Log Message: ----------- Use explicit counter (entry/exit) in tests when possible. Comment debug prints; code more-or-less work, but still remains unclean issues: duplicate removes from epoll vector (may be dangerous, due to reuse descriptor possibility); connection may be accepted after sockmgr's loop finished (?) --- may lead to stalling on server dtor; issue really unclean. 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 branches/complement-sockios/explore/include/sockios/sockstream.cc branches/complement-sockios/explore/include/sockios/sp.cc branches/complement-sockios/explore/include/sockios/sp.h branches/complement-sockios/explore/lib/sockios/ut/sockios2_test.cc Modified: branches/complement-sockios/explore/include/sockios/socksrv.cc =================================================================== --- branches/complement-sockios/explore/include/sockios/socksrv.cc 2008-06-26 05:46:44 UTC (rev 1918) +++ branches/complement-sockios/explore/include/sockios/socksrv.cc 2008-06-26 05:47:07 UTC (rev 1919) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/25 21:28:07 yeti> +// -*- C++ -*- Time-stamp: <08/06/26 09:00:54 ptr> /* * Copyright (c) 2008 @@ -72,7 +72,7 @@ if ( !basic_socket_t::is_open_unsafe() ) { return; } - std::cerr << __FILE__ << ":" << __LINE__ << " " << basic_socket_t::_fd << std::endl; + // std::cerr << __FILE__ << ":" << __LINE__ << " " << basic_socket_t::_fd << std::endl; #ifdef WIN32 ::closesocket( basic_socket_t::_fd ); @@ -87,7 +87,7 @@ 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::cerr << __FILE__ << ":" << __LINE__ << std::endl; std::tr2::lock_guard<std::tr2::mutex> lk(_fd_lck); if ( basic_socket_t::is_open_unsafe() ) { @@ -186,27 +186,6 @@ template<class Connect, class charT, class traits, class _Alloc, void (Connect::*C)( std::basic_sockstream<charT,traits,_Alloc>& )> char connect_processor<Connect, charT, traits, _Alloc, C>::Init_buf[128]; -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) - } - - { - 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(); - } -#endif -} - template <class Connect, class charT, class traits, class _Alloc, void (Connect::*C)( std::basic_sockstream<charT,traits,_Alloc>& )> typename connect_processor<Connect, charT, traits, _Alloc, C>::base_t::sockbuf_t* connect_processor<Connect, charT, traits, _Alloc, C>::operator ()( sock_base::socket_type fd, const sockaddr& addr ) { @@ -221,12 +200,12 @@ if ( s->rdbuf()->in_avail() ) { std::tr2::lock_guard<std::tr2::mutex> lk( rdlock ); ready_pool.push_back( processor( c, s ) ); - std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; + // std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; cnd.notify_one(); } else { std::tr2::lock_guard<std::tr2::mutex> lk( wklock ); worker_pool.insert( std::make_pair( fd, processor( c, s ) ) ); - std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; + // std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; } return s->rdbuf(); @@ -235,15 +214,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>::operator ()( sock_base::socket_type fd, const typename connect_processor<Connect, charT, traits, _Alloc, C>::base_t::adopt_close_t& ) { - std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; + // std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; { std::tr2::lock_guard<std::tr2::mutex> lk( wklock ); typename worker_pool_t::iterator i = worker_pool.find( fd ); if ( i != worker_pool.end() ) { - std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; + // std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; delete i->second.c; delete i->second.s; - // std::cerr << "oops\n"; worker_pool.erase( i ); return; } @@ -254,15 +232,12 @@ 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 ) */ fd ); if ( j != ready_pool.end() ) { - // std::cerr << "oops 2\n"; p = *j; ready_pool.erase( j ); } } if ( p.c != 0 ) { - // (*p.c)( *p.s ); - std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; - + // std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; (p.c->*C)( *p.s ); delete p.c; @@ -273,7 +248,7 @@ 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>::operator ()( sock_base::socket_type fd ) { - std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; + // std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; processor p; @@ -303,16 +278,11 @@ return false; } - std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; cnd.wait( lk, not_empty ); - std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; p = ready_pool.front(); // it may contain p.c == 0, p.s == 0, if !in_work() ready_pool.pop_front(); -#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 if ( _in_work ) { return true; @@ -328,7 +298,7 @@ while ( pop_ready( p ) ) { if ( p.c != 0 ) { - std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; (p.c->*C)( *p.s ); if ( p.s->rdbuf()->in_avail() ) { std::tr2::lock_guard<std::tr2::mutex> lk( rdlock ); @@ -337,30 +307,23 @@ std::tr2::lock_guard<std::tr2::mutex> lk( wklock ); worker_pool[p.s->rdbuf()->fd()] = p; } - } else { - std::cerr << __FILE__ << ":" << __LINE__ << std::endl; - } + } // else { + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + // } } - { - std::tr2::lock_guard<std::tr2::mutex> lk( wklock ); - std::cerr << __FILE__ << ":" << __LINE__ << " " << worker_pool.size() << std::endl; - } +// { +// std::tr2::lock_guard<std::tr2::mutex> lk( wklock ); +// std::cerr << __FILE__ << ":" << __LINE__ << " " << worker_pool.size() << std::endl; +// } - { - std::tr2::lock_guard<std::tr2::mutex> lk( rdlock ); - std::cerr << __FILE__ << ":" << __LINE__ << " " << ready_pool.size() << std::endl; - } +// { +// std::tr2::lock_guard<std::tr2::mutex> lk( rdlock ); +// std::cerr << __FILE__ << ":" << __LINE__ << " " << ready_pool.size() << std::endl; +// } } - 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() -{ - _stop(); -} - -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> lk2( rdlock ); @@ -368,11 +331,11 @@ _in_work = false; // <--- set before cnd.notify_one(); (below in this func) if ( ready_pool.empty() ) { ready_pool.push_back( processor() ); // make ready_pool not empty - std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; cnd.notify_one(); - } else { - std::cerr << __FILE__ << ":" << __LINE__ << std::endl; - } + } // else { + // 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:46:44 UTC (rev 1918) +++ branches/complement-sockios/explore/include/sockios/socksrv.h 2008-06-26 05:47:07 UTC (rev 1919) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/25 21:30:31 yeti> +// -*- C++ -*- Time-stamp: <08/06/26 08:59:54 ptr> /* * Copyright (c) 2008 @@ -65,14 +65,8 @@ { sock_processor_base::open( port, t, sock_base::inet ); } virtual ~sock_processor_base() - { - sock_processor_base::_close(); + { sock_processor_base::_close(); } - // Never uncomment next line: - // basic_socket<charT,traits,_Alloc>::mgr->final( *this ); - // this lead to virtual fuction call, that is already pure here. - } - void open( const in_addr& addr, int port, sock_base::stype type, sock_base::protocol prot ); void open( unsigned long addr, int port, sock_base::stype type, sock_base::protocol prot ) @@ -87,14 +81,8 @@ virtual void close() { _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; @@ -204,45 +192,23 @@ ploop.join(); } - // basic_socket<charT,traits,_Alloc>::mgr->final( *this ); + // { + // std::tr2::lock_guard<std::tr2::mutex> lk2( rdlock ); + // cerr << __FILE__ << ":" << __LINE__ << " " << ready_pool.size() << endl; + // } -#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; - } + // { + // std::tr2::lock_guard<std::tr2::mutex> lk2( wklock ); + // cerr << __FILE__ << ":" << __LINE__ << " " << worker_pool.size() << endl; + // } - for ( ; ; ) { - - } - } -#endif - - - { - std::tr2::lock_guard<std::tr2::mutex> lk2( rdlock ); - cerr << __FILE__ << ":" << __LINE__ << " " << ready_pool.size() << endl; - } - - { - 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() { connect_processor::_close(); } - virtual void stop(); + virtual void stop() + { connect_processor::_stop(); } void wait() { if ( ploop.joinable() ) { ploop.join(); } } @@ -304,7 +270,8 @@ }; bool pop_ready( processor& ); - void _close(); + void _close() + { base_t::_close(); } void _stop(); #ifdef __USE_STLPORT_HASH Modified: branches/complement-sockios/explore/include/sockios/sockstream =================================================================== --- branches/complement-sockios/explore/include/sockios/sockstream 2008-06-26 05:46:44 UTC (rev 1918) +++ branches/complement-sockios/explore/include/sockios/sockstream 2008-06-26 05:47:07 UTC (rev 1919) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/17 17:09:45 yeti> +// -*- C++ -*- Time-stamp: <08/06/26 08:57:00 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005-2008 @@ -448,8 +448,7 @@ virtual ~basic_sockbuf() { - std::cerr << __FILE__ << ":" << __LINE__ << " " << basic_socket_t::_fd << std::endl; - close(); + basic_sockbuf::close(); _M_deallocate_block(); } Modified: branches/complement-sockios/explore/include/sockios/sockstream.cc =================================================================== --- branches/complement-sockios/explore/include/sockios/sockstream.cc 2008-06-26 05:46:44 UTC (rev 1918) +++ branches/complement-sockios/explore/include/sockios/sockstream.cc 2008-06-26 05:47:07 UTC (rev 1919) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/25 18:48:36 yeti> +// -*- C++ -*- Time-stamp: <08/06/26 08:40:03 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005-2008 @@ -273,7 +273,7 @@ setg( this->epptr(), this->epptr(), this->epptr() ); // if ( basic_socket_t::_notify_close ) { - std::cerr << __FILE__ << ":" << __LINE__ << " " << basic_socket_t::_fd << std::endl; + // std::cerr << __FILE__ << ":" << __LINE__ << " " << basic_socket_t::_fd << std::endl; basic_socket_t::mgr->exit_notify( this, basic_socket_t::_fd ); // basic_socket_t::_notify_close = false; // } @@ -393,22 +393,22 @@ template<class charT, class traits, class _Alloc> int basic_sockbuf<charT, traits, _Alloc>::sync() { - std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; if ( !basic_socket_t::is_open() ) { return -1; } long count = this->pptr() - this->pbase(); if ( count ) { - std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; // _STLP_ASSERT( this->pbase() != 0 ); count *= sizeof(charT); long start = 0; while ( count > 0 ) { long offset = (this->*_xwrite)( this->pbase() + start, count ); - std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; if ( offset < 0 ) { - std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; if ( errno == EINTR ) { errno = 0; continue; @@ -436,7 +436,7 @@ return -1; } } - std::cerr << __FILE__ << ":" << __LINE__ << " " << basic_socket_t::_fd << std::endl; + // std::cerr << __FILE__ << ":" << __LINE__ << " " << basic_socket_t::_fd << std::endl; count -= offset; start += offset; } Modified: branches/complement-sockios/explore/include/sockios/sp.cc =================================================================== --- branches/complement-sockios/explore/include/sockios/sp.cc 2008-06-26 05:46:44 UTC (rev 1918) +++ branches/complement-sockios/explore/include/sockios/sp.cc 2008-06-26 05:47:07 UTC (rev 1919) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/25 22:25:48 yeti> +// -*- C++ -*- Time-stamp: <08/06/26 09:10:47 ptr> /* * Copyright (c) 2008 @@ -39,21 +39,16 @@ } // throw system_error } - // std::cerr << "epoll see " << n << std::endl; std::tr2::lock_guard<std::tr2::mutex> lk( dll ); for ( int i = 0; i < n; ++i ) { - // std::cerr << "epoll i = " << i << std::endl; if ( ev[i].data.fd == pipefd[0] ) { - // std::cerr << "on pipe\n"; cmd_from_pipe(); } else { - // std::cerr << "#\n"; - typename fd_container_type::iterator ifd = descr.find( ev[i].data.fd ); if ( ifd == descr.end() ) { - std::cerr << __FILE__ << ":" << __LINE__ << " " << ev[i].data.fd << std::endl; + // std::cerr << __FILE__ << ":" << __LINE__ << " " << ev[i].data.fd << std::endl; if ( epoll_ctl( efd, EPOLL_CTL_DEL, ev[i].data.fd, 0 ) < 0 ) { // throw system_error } @@ -63,10 +58,8 @@ fd_info& info = ifd->second; if ( info.flags & fd_info::listener ) { - // std::cerr << "%\n"; process_listener( ev[i], ifd ); } else { - // std::cerr << "not listener\n"; process_regular( ev[i], ifd ); } } @@ -90,10 +83,8 @@ int r = read( pipefd[0], &_ctl, sizeof(ctl) ); if ( r < 0 ) { // throw system_error - // std::cerr << "Read pipe\n"; throw std::detail::stop_request(); // runtime_error( "Stop request (normal flow)" ); } else if ( r == 0 ) { - // std::cerr << "Read pipe 0\n"; throw runtime_error( "Read pipe return 0" ); } @@ -114,7 +105,7 @@ return; } } else { - std::cerr << __FILE__ << ":" << __LINE__ << " " << ev_add.data.fd << std::endl; + // std::cerr << __FILE__ << ":" << __LINE__ << " " << ev_add.data.fd << std::endl; if ( epoll_ctl( efd, EPOLL_CTL_ADD, ev_add.data.fd, &ev_add ) < 0 ) { std::cerr << __FILE__ << ":" << __LINE__ << std::endl; // throw system_error @@ -136,7 +127,7 @@ return; } } else { - std::cerr << __FILE__ << ":" << __LINE__ << " " << ev_add.data.fd << std::endl; + // std::cerr << __FILE__ << ":" << __LINE__ << " " << ev_add.data.fd << std::endl; if ( epoll_ctl( efd, EPOLL_CTL_ADD, ev_add.data.fd, &ev_add ) < 0 ) { std::cerr << __FILE__ << ":" << __LINE__ << std::endl; // throw system_error @@ -148,13 +139,13 @@ break; case listener_on_exit: listeners_final.insert( _ctl.data.ptr ); - std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; { int lfd = check_closed_listener( reinterpret_cast<socks_processor_t*>(_ctl.data.ptr) ); if ( lfd != -1 ) { descr.erase( lfd ); } - dump_descr(); + // dump_descr(); } break; case rqstop: @@ -167,9 +158,9 @@ 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; + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; if ( ev.events & (EPOLLRDHUP | EPOLLHUP | EPOLLERR) ) { - std::cerr << __FILE__ << ":" << __LINE__ << " " << ifd->first << std::endl; + // 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; @@ -186,7 +177,7 @@ listeners_final.insert(static_cast<void *>(ifd->second.p)); - std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; socks_processor_t* p = ifd->second.p; @@ -198,13 +189,13 @@ descr.erase( lfd ); } - dump_descr(); + // dump_descr(); return; } if ( (ev.events & EPOLLIN) == 0 ) { - std::cerr << __FILE__ << ":" << __LINE__ << " " << std::hex << ev.events << std::dec << std::endl; + // std::cerr << __FILE__ << ":" << __LINE__ << " " << std::hex << ev.events << std::dec << std::endl; return; // I don't know what to do this case... } @@ -216,16 +207,14 @@ for ( ; ; ) { 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) */ ) { - std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; errno = 0; continue; } if ( !(errno == EAGAIN /* || errno == EWOULDBLOCK */ ) ) { // EWOULDBLOCK == EAGAIN - // std::cerr << "Accept, listener " << ev.data.fd << ", errno " << errno << std::endl; - std::cerr << __FILE__ << ":" << __LINE__ << " " << ifd->first << std::endl; + // std::cerr << __FILE__ << ":" << __LINE__ << " " << ifd->first << std::endl; if ( epoll_ctl( efd, EPOLL_CTL_DEL, ifd->first, 0 ) < 0 ) { std::cerr << __FILE__ << ":" << __LINE__ << " " << ifd->first << " " << errno << std::endl; @@ -241,7 +230,7 @@ } } - std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; socks_processor_t* p = ifd->second.p; listeners_final.insert( static_cast<void *>(p) ); @@ -250,18 +239,19 @@ check_closed_listener( p ); - std::cerr << __FILE__ << ":" << __LINE__ << std::endl; - dump_descr(); + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + // dump_descr(); } else { // back to listen errno = 0; epoll_event xev; xev.events = EPOLLIN | EPOLLRDHUP | EPOLLERR | EPOLLHUP | EPOLLET | EPOLLONESHOT; xev.data.fd = ev.data.fd; if ( epoll_ctl( efd, EPOLL_CTL_MOD, ev.data.fd, &xev ) < 0 ) { - std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + std::cerr << __FILE__ << ":" << __LINE__ << " " << ev.data.fd << " " + << errno << std::endl; } } - 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 ) { @@ -275,25 +265,25 @@ ev_add.data.fd = fd; if ( descr.find( fd ) != descr.end() ) { // reuse? - std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; if ( epoll_ctl( efd, EPOLL_CTL_MOD, fd, &ev_add ) < 0 ) { - std::cerr << __FILE__ << ":" << __LINE__ << " " << errno << std::endl; + std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << " " << errno << std::endl; descr.erase( fd ); // throw system_error return; // throw } } else { - std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; + // std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; if ( epoll_ctl( efd, EPOLL_CTL_ADD, fd, &ev_add ) < 0 ) { // throw system_error - std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << " " << errno << std::endl; return; // throw } } - std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; sockbuf_t* b = (*info.p)( fd, addr ); - std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; descr[fd] = fd_info( b, info.p ); } @@ -310,14 +300,13 @@ template<class charT, class traits, class _Alloc> void sockmgr<charT,traits,_Alloc>::process_regular( epoll_event& ev, typename sockmgr<charT,traits,_Alloc>::fd_container_type::iterator ifd ) { - std::cerr << __FILE__ << ":" << __LINE__ << std::endl; - fd_info& info = ifd->second; sockbuf_t* b = info.b; if ( b == 0 ) { // marginal case: sockbuf wasn't created by processor... - std::cerr << __FILE__ << ":" << __LINE__ << " " << ifd->first << std::endl; + // std::cerr << __FILE__ << ":" << __LINE__ << " " << ifd->first << std::endl; if ( epoll_ctl( efd, EPOLL_CTL_DEL, ifd->first, 0 ) < 0 ) { + std::cerr << __FILE__ << ":" << __LINE__ << " " << ifd->first << " " << errno << std::endl; // throw system_error } if ( info.p != 0 ) { // ... but controlled by processor @@ -332,19 +321,17 @@ } else { descr.erase( ifd ); } - std::cerr << __FILE__ << ":" << __LINE__ << std::endl; - dump_descr(); return; } errno = 0; - std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; if ( ev.events & EPOLLIN ) { - std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; for ( ; ; ) { if ( b->_ebuf == b->egptr() ) { - std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; // process extract data from buffer too slow for us! if ( (info.flags & fd_info::level_triggered) == 0 ) { epoll_event xev; @@ -352,20 +339,18 @@ xev.data.fd = ev.data.fd; info.flags |= fd_info::level_triggered; if ( epoll_ctl( efd, EPOLL_CTL_MOD, ev.data.fd, &xev ) < 0 ) { - // std::cerr << "X " << ev.data.fd << ", " << errno << std::endl; + std::cerr << __FILE__ << ":" << __LINE__ << " " << ev.data.fd << " " << errno << std::endl; } } - // std::cerr << "Z " << ev.data.fd << ", " << errno << std::endl; - if ( info.p != 0 ) { // or (info.flags & fd_info::owner) != 0 + if ( info.p != 0 ) { (*info.p)( ev.data.fd ); } break; } - // std::cerr << "ptr " << (void *)b->egptr() << ", " << errno << std::endl; + long offset = read( ev.data.fd, b->egptr(), sizeof(charT) * (b->_ebuf - b->egptr()) ); - // std::cerr << "offset " << offset << ", " << errno << std::endl; + if ( offset < 0 ) { - std::cerr << __FILE__ << ":" << __LINE__ << std::endl; switch ( errno ) { case EINTR: // read was interrupted errno = 0; @@ -383,17 +368,17 @@ 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__ << " " << ev.data.fd << " " << errno << std::endl; + } } break; default: - // std::cerr << "not listener, other " << ev.data.fd << std::hex << ev.events << std::dec << " : " << errno << std::endl; std::cerr << __FILE__ << ":" << __LINE__ << std::endl; break; } break; } else if ( offset > 0 ) { - std::cerr << __FILE__ << ":" << __LINE__ << std::endl; offset /= sizeof(charT); // if offset % sizeof(charT) != 0, rest will be lost! if ( info.flags & fd_info::level_triggered ) { @@ -402,19 +387,18 @@ xev.data.fd = ev.data.fd; info.flags &= ~static_cast<unsigned>(fd_info::level_triggered); if ( epoll_ctl( efd, EPOLL_CTL_MOD, ev.data.fd, &xev ) < 0 ) { - // std::cerr << "Y " << ev.data.fd << ", " << errno << std::endl; + std::cerr << __FILE__ << ":" << __LINE__ << " " << ev.data.fd << " " << errno << std::endl; } } std::tr2::lock_guard<std::tr2::mutex> lk( b->ulck ); b->setg( b->eback(), b->gptr(), b->egptr() + offset ); b->ucnd.notify_one(); if ( info.p != 0 ) { - std::cerr << __FILE__ << ":" << __LINE__ << " " << ev.data.fd << std::endl; + // std::cerr << __FILE__ << ":" << __LINE__ << " " << ev.data.fd << std::endl; (*info.p)( ev.data.fd ); } } else { - std::cerr << __FILE__ << ":" << __LINE__ << " " << ev.data.fd << std::endl; - // std::cerr << "K " << ev.data.fd << ", " << errno << std::endl; + // std::cerr << __FILE__ << ":" << __LINE__ << " " << ev.data.fd << std::endl; // EPOLLRDHUP may be missed in kernel, but offset 0 is the same ev.events |= EPOLLRDHUP; // will be processed below break; @@ -423,17 +407,16 @@ } if ( (ev.events & (EPOLLRDHUP | EPOLLHUP | EPOLLERR) ) != 0 ) { - // std::cerr << "Poll EPOLLRDHUP " << ev.data.fd << ", " << errno << std::endl; - std::cerr << __FILE__ << ":" << __LINE__ << " " << ifd->first << std::endl; + // 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__ << std::endl; + std::cerr << __FILE__ << ":" << __LINE__ << " " << ifd->first << " " << errno << std::endl; } if ( info.p != 0 ) { - std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; (*info.p)( ifd->first, typename socks_processor_t::adopt_close_t() ); - std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; socks_processor_t* p = info.p; @@ -445,14 +428,15 @@ } } else { b->_notify_close = false; // avoid deadlock - std::cerr << __FILE__ << ":" << __LINE__ << " " << ifd->first << std::endl; + // 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; } descr.erase( ifd ); b->close(); } - dump_descr(); + // dump_descr(); } // if ( ev.events & EPOLLHUP ) { // std::cerr << "Poll HUP" << std::endl; @@ -479,30 +463,29 @@ { int myfd = -1; - std::cerr << __FILE__ << ":" << __LINE__ << std::endl; if ( !listeners_final.empty() ) { - std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + // 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; + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; return -1; } myfd = i->first; - std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; } } - 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; + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; // if ( myfd != -1 ) { // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; - p->stop(); + p->stop(); // } } } Modified: branches/complement-sockios/explore/include/sockios/sp.h =================================================================== --- branches/complement-sockios/explore/include/sockios/sp.h 2008-06-26 05:46:44 UTC (rev 1918) +++ branches/complement-sockios/explore/include/sockios/sp.h 2008-06-26 05:47:07 UTC (rev 1919) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/25 22:10:36 yeti> +// -*- C++ -*- Time-stamp: <08/06/26 08:22:27 ptr> /* * Copyright (c) 2008 @@ -229,31 +229,28 @@ void exit_notify( sockbuf_t* b, sock_base::socket_type fd ) { - // fd_info info = { 0, 0, 0 }; - // std::tr2::lock_guard<std::tr2::mutex> lk( dll ); - try { - std::tr2::unique_lock<std::tr2::mutex> lk( dll, std::tr2::try_to_lock ); + std::tr2::unique_lock<std::tr2::mutex> lk( dll, std::tr2::defer_lock ); - if ( b->_notify_close ) { - std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; - typename fd_container_type::iterator i = descr.find( fd ); - if ( i != descr.end() ) { - if ( (i->second.b == b) && (i->second.p == 0) ) { - std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; - if ( epoll_ctl( efd, EPOLL_CTL_DEL, fd, 0 ) < 0 ) { - std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; - // throw system_error - } - std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; - descr.erase( i ); + if ( lk.try_lock() ) { + if ( b->_notify_close ) { + // std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; + typename fd_container_type::iterator i = descr.find( fd ); + if ( (i != descr.end()) && (i->second.b == b) && (i->second.p == 0) ) { + // std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; + if ( epoll_ctl( efd, EPOLL_CTL_DEL, fd, 0 ) < 0 ) { + // std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; + // throw system_error + } + // std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; + descr.erase( i ); } + b->_notify_close = false; } - b->_notify_close = false; } } catch ( const std::tr2::lock_error& ) { - std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; + // std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; } } 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:46:44 UTC (rev 1918) +++ branches/complement-sockios/explore/lib/sockios/ut/sockios2_test.cc 2008-06-26 05:47:07 UTC (rev 1919) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/25 17:59:36 yeti> +// -*- C++ -*- Time-stamp: <08/06/26 09:28:53 ptr> /* * @@ -263,14 +263,14 @@ { lock_guard<mutex> lk(lock); ++cnt; ++visits; cnd.notify_one(); } ~worker() - { lock_guard<mutex> lk(lock); --cnt; } + { lock_guard<mutex> lk(lock); --cnt; cnd.notify_one(); } void connect( sockstream& s ) { lock_guard<mutex> lk(lock); getline( s, line ); - cerr << __FILE__ << ":" << __LINE__ << " " << s.good() << " " - << s.rdbuf()->in_avail() << endl; + // cerr << __FILE__ << ":" << __LINE__ << " " << s.good() << " " + // << s.rdbuf()->in_avail() << endl; ++rd; line_cnd.notify_one(); } @@ -297,6 +297,9 @@ static bool rd_counter1() { return worker::rd == 1; } + + static bool counter0() + { return worker::cnt == 0; } }; mutex worker::lock; @@ -338,6 +341,13 @@ EXAM_CHECK( worker::cnd.timed_wait( lk, milliseconds( 500 ), worker::visits_counter1 ) ); worker::visits = 0; } + + // for ( int i = 0; i < 64; ++i ) { // give chance for system + // std::tr2::this_thread::yield(); + // } + + unique_lock<mutex> lksrv( worker::lock ); + EXAM_CHECK( worker::cnd.timed_wait( lksrv, milliseconds( 500 ), worker::counter0 ) ); } { lock_guard<mutex> lk( worker::lock ); @@ -370,6 +380,12 @@ EXAM_CHECK( worker::cnd.timed_wait( lk, milliseconds( 500 ), worker::visits_counter2 ) ); worker::visits = 0; } + + // for ( int i = 0; i < 64; ++i ) { // give chance for system + // std::tr2::this_thread::yield(); + // } + unique_lock<mutex> lksrv( worker::lock ); + EXAM_CHECK( worker::cnd.timed_wait( lksrv, milliseconds( 500 ), worker::counter0 ) ); } { lock_guard<mutex> lk( worker::lock ); @@ -400,6 +416,13 @@ worker::line = ""; worker::rd = 0; } + + // for ( int i = 0; i < 64; ++i ) { // give chance for system + // std::tr2::this_thread::yield(); + // } + + unique_lock<mutex> lksrv( worker::lock ); + EXAM_CHECK( worker::cnd.timed_wait( lksrv, milliseconds( 500 ), worker::counter0 ) ); } // check after sockstream was closed, i.e. ensure, that all data available @@ -420,12 +443,18 @@ } unique_lock<mutex> lk( worker::lock ); - EXAM_CHECK( worker::line_cnd.timed_wait( lk, milliseconds( 50000 ), worker::rd_counter1 ) ); + EXAM_CHECK( worker::line_cnd.timed_wait( lk, milliseconds( 500 ), worker::rd_counter1 ) ); // cerr << worker::line << endl; EXAM_CHECK( worker::line == "Hello, world!" ); worker::line = ""; worker::rd = 0; + + // for ( int i = 0; i < 64; ++i ) { // give chance for system + // std::tr2::this_thread::yield(); + // } + unique_lock<mutex> lksrv( worker::lock ); + EXAM_CHECK( worker::cnd.timed_wait( lksrv, milliseconds( 500 ), worker::counter0 ) ); } return EXAM_RESULT; @@ -471,6 +500,13 @@ unique_lock<mutex> lk( worker::lock ); EXAM_CHECK_ASYNC( worker::cnd.timed_wait( lk, milliseconds( 500 ), worker::visits_counter1 ) ); + + // for ( int i = 0; i < 64; ++i ) { // give chance for system + // std::tr2::this_thread::yield(); + // } + + unique_lock<mutex> lksrv( worker::lock ); + EXAM_CHECK( worker::cnd.timed_wait( lksrv, milliseconds( 500 ), worker::counter0 ) ); } exit( 0 ); @@ -601,6 +637,9 @@ EXAM_CHECK( r.good() ); EXAM_CHECK( r.is_open() ); + for ( int i = 0; i < 64; ++i ) { // give chance for system + std::tr2::this_thread::yield(); + } } shm.deallocate( &b ); seg.deallocate(); @@ -708,6 +747,10 @@ EXAM_CHECK( r.good() ); EXAM_CHECK( r.is_open() ); + + for ( int i = 0; i < 64; ++i ) { // give chance for system + std::tr2::this_thread::yield(); + } } shm.deallocate( &bnew ); shm.deallocate( &b ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-06-26 05:46:45
|
Revision: 1918 http://complement.svn.sourceforge.net/complement/?rev=1918&view=rev Author: complement Date: 2008-06-25 22:46:44 -0700 (Wed, 25 Jun 2008) Log Message: ----------- Seems problem in accepting connection after processor ready to exit. Problem coupled with fact, that connection_processor and client socket streams are in single process, but in different thread. This may lead to sequence: - connection_processor queue empty, it ready to exit - accept or epoll signal about incoming connection and connection_processor should process it 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.cc branches/complement-sockios/explore/include/sockios/sp.cc branches/complement-sockios/explore/include/sockios/sp.h branches/complement-sockios/explore/lib/sockios/ut/sockios2_test.cc Modified: branches/complement-sockios/explore/include/sockios/socksrv.cc =================================================================== --- branches/complement-sockios/explore/include/sockios/socksrv.cc 2008-06-26 05:46:17 UTC (rev 1917) +++ branches/complement-sockios/explore/include/sockios/socksrv.cc 2008-06-26 05:46:44 UTC (rev 1918) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/24 18:34:58 yeti> +// -*- C++ -*- Time-stamp: <08/06/25 21:28:07 yeti> /* * Copyright (c) 2008 @@ -66,13 +66,13 @@ } template<class charT, class traits, class _Alloc> -void sock_processor_base<charT,traits,_Alloc>::close() +void sock_processor_base<charT,traits,_Alloc>::_close() { std::tr2::lock_guard<std::tr2::mutex> lk(_fd_lck); if ( !basic_socket_t::is_open_unsafe() ) { return; } - std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + std::cerr << __FILE__ << ":" << __LINE__ << " " << basic_socket_t::_fd << std::endl; #ifdef WIN32 ::closesocket( basic_socket_t::_fd ); @@ -187,10 +187,10 @@ char connect_processor<Connect, charT, traits, _Alloc, C>::Init_buf[128]; 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() +void connect_processor<Connect, charT, traits, _Alloc, C>::_close() { std::cerr << __FILE__ << ":" << __LINE__ << std::endl; - base_t::close(); + base_t::_close(); #if 0 { @@ -218,14 +218,16 @@ 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 ) ); - // cnd.notify_one(); - // } else { - std::tr2::lock_guard<std::tr2::mutex> lk( wklock ); - worker_pool.insert( std::make_pair( fd, processor( c, s ) ) ); - // } + if ( s->rdbuf()->in_avail() ) { + std::tr2::lock_guard<std::tr2::mutex> lk( rdlock ); + ready_pool.push_back( processor( c, s ) ); + std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; + cnd.notify_one(); + } else { + std::tr2::lock_guard<std::tr2::mutex> lk( wklock ); + worker_pool.insert( std::make_pair( fd, processor( c, s ) ) ); + std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; + } return s->rdbuf(); } @@ -233,10 +235,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>::operator ()( sock_base::socket_type fd, const typename connect_processor<Connect, charT, traits, _Alloc, C>::base_t::adopt_close_t& ) { + std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; { std::tr2::lock_guard<std::tr2::mutex> lk( wklock ); typename worker_pool_t::iterator i = worker_pool.find( fd ); if ( i != worker_pool.end() ) { + std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; delete i->second.c; delete i->second.s; // std::cerr << "oops\n"; @@ -257,6 +261,10 @@ } if ( p.c != 0 ) { // (*p.c)( *p.s ); + std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; + + (p.c->*C)( *p.s ); + delete p.c; delete p.s; } @@ -265,6 +273,8 @@ 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>::operator ()( sock_base::socket_type fd ) { + std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; + processor p; { @@ -331,12 +341,28 @@ std::cerr << __FILE__ << ":" << __LINE__ << std::endl; } } + + { + std::tr2::lock_guard<std::tr2::mutex> lk( wklock ); + std::cerr << __FILE__ << ":" << __LINE__ << " " << worker_pool.size() << std::endl; + } + + { + std::tr2::lock_guard<std::tr2::mutex> lk( rdlock ); + std::cerr << __FILE__ << ":" << __LINE__ << " " << ready_pool.size() << std::endl; + } } 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() { + _stop(); +} + +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> lk2( rdlock ); _in_work = false; // <--- set before cnd.notify_one(); (below in this func) @@ -344,6 +370,8 @@ ready_pool.push_back( processor() ); // make ready_pool not empty std::cerr << __FILE__ << ":" << __LINE__ << std::endl; cnd.notify_one(); + } else { + 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:46:17 UTC (rev 1917) +++ branches/complement-sockios/explore/include/sockios/socksrv.h 2008-06-26 05:46:44 UTC (rev 1918) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/19 20:14:01 yeti> +// -*- C++ -*- Time-stamp: <08/06/25 21:30:31 yeti> /* * Copyright (c) 2008 @@ -66,7 +66,7 @@ virtual ~sock_processor_base() { - sock_processor_base::close(); + sock_processor_base::_close(); // Never uncomment next line: // basic_socket<charT,traits,_Alloc>::mgr->final( *this ); @@ -85,7 +85,8 @@ void open( int port, sock_base::stype type, sock_base::protocol prot ) { sock_processor_base::open(INADDR_ANY, port, type, prot); } - virtual void close(); + virtual void close() + { _close(); } #if 0 virtual void stop() = 0; #else @@ -122,8 +123,10 @@ return s; } - void (sock_processor_base::*_real_stop)(); + void _close(); + // 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(); } @@ -193,8 +196,10 @@ virtual ~connect_processor() { - connect_processor::close(); + connect_processor::_close(); + // _stop(); + if ( ploop.joinable() ) { ploop.join(); } @@ -235,7 +240,8 @@ ((Init *)Init_buf)->~Init(); } - virtual void close(); + virtual void close() + { connect_processor::_close(); } virtual void stop(); void wait() @@ -298,6 +304,8 @@ }; bool pop_ready( processor& ); + void _close(); + void _stop(); #ifdef __USE_STLPORT_HASH typedef std::hash_map<sock_base::socket_type, processor> worker_pool_t; Modified: branches/complement-sockios/explore/include/sockios/sockstream.cc =================================================================== --- branches/complement-sockios/explore/include/sockios/sockstream.cc 2008-06-26 05:46:17 UTC (rev 1917) +++ branches/complement-sockios/explore/include/sockios/sockstream.cc 2008-06-26 05:46:44 UTC (rev 1918) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/17 17:09:02 yeti> +// -*- C++ -*- Time-stamp: <08/06/25 18:48:36 yeti> /* * Copyright (c) 1997-1999, 2002, 2003, 2005-2008 @@ -272,10 +272,11 @@ setp( _bbuf, _bbuf + ((_ebuf - _bbuf)>>1) ); setg( this->epptr(), this->epptr(), this->epptr() ); - if ( basic_socket_t::_notify_close ) { - basic_socket_t::mgr->exit_notify( this, basic_socket_t::_fd ); - basic_socket_t::_notify_close = false; - } + // if ( basic_socket_t::_notify_close ) { + std::cerr << __FILE__ << ":" << __LINE__ << " " << basic_socket_t::_fd << std::endl; + basic_socket_t::mgr->exit_notify( this, basic_socket_t::_fd ); + // basic_socket_t::_notify_close = false; + // } basic_socket_t::_fd = -1; Modified: branches/complement-sockios/explore/include/sockios/sp.cc =================================================================== --- branches/complement-sockios/explore/include/sockios/sp.cc 2008-06-26 05:46:17 UTC (rev 1917) +++ branches/complement-sockios/explore/include/sockios/sp.cc 2008-06-26 05:46:44 UTC (rev 1918) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/25 12:00:59 ptr> +// -*- C++ -*- Time-stamp: <08/06/25 22:25:48 yeti> /* * Copyright (c) 2008 @@ -45,19 +45,6 @@ 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(); @@ -66,6 +53,7 @@ typename fd_container_type::iterator ifd = descr.find( ev[i].data.fd ); if ( ifd == descr.end() ) { + std::cerr << __FILE__ << ":" << __LINE__ << " " << ev[i].data.fd << std::endl; if ( epoll_ctl( efd, EPOLL_CTL_DEL, ev[i].data.fd, 0 ) < 0 ) { // throw system_error } @@ -103,6 +91,7 @@ if ( r < 0 ) { // throw system_error // std::cerr << "Read pipe\n"; + throw std::detail::stop_request(); // runtime_error( "Stop request (normal flow)" ); } else if ( r == 0 ) { // std::cerr << "Read pipe 0\n"; throw runtime_error( "Read pipe return 0" ); @@ -117,22 +106,44 @@ // std::cerr << "xxx " << errno << " " << std::tr2::getpid() << std::endl; throw std::runtime_error( "can't establish nonblock mode on listener" ); } + if ( descr.find( ev_add.data.fd ) != descr.end() ) { // reuse? + if ( epoll_ctl( efd, EPOLL_CTL_MOD, ev_add.data.fd, &ev_add ) < 0 ) { + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + // descr.erase( ev_add.data.fd ); + // throw system_error + return; + } + } else { + std::cerr << __FILE__ << ":" << __LINE__ << " " << ev_add.data.fd << std::endl; + if ( epoll_ctl( efd, EPOLL_CTL_ADD, ev_add.data.fd, &ev_add ) < 0 ) { + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + // throw system_error + return; + } + } 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 - } } break; case tcp_buffer: 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 ) { + if ( descr.find( ev_add.data.fd ) != descr.end() ) { // reuse? + if ( epoll_ctl( efd, EPOLL_CTL_MOD, ev_add.data.fd, &ev_add ) < 0 ) { + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + // descr.erase( ev_add.data.fd ); + // throw system_error + return; + } + } else { + std::cerr << __FILE__ << ":" << __LINE__ << " " << ev_add.data.fd << std::endl; + if ( epoll_ctl( efd, EPOLL_CTL_ADD, ev_add.data.fd, &ev_add ) < 0 ) { + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + // throw system_error + return; + } + } 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 - } } break; case listener_on_exit: @@ -158,8 +169,10 @@ { std::cerr << __FILE__ << ":" << __LINE__ << std::endl; if ( ev.events & (EPOLLRDHUP | EPOLLHUP | EPOLLERR) ) { + 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 ( ifd->second.p != 0 ) { @@ -212,9 +225,10 @@ } if ( !(errno == EAGAIN /* || errno == EWOULDBLOCK */ ) ) { // EWOULDBLOCK == EAGAIN // std::cerr << "Accept, listener " << ev.data.fd << ", errno " << errno << std::endl; - std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + std::cerr << __FILE__ << ":" << __LINE__ << " " << ifd->first << std::endl; if ( epoll_ctl( efd, EPOLL_CTL_DEL, ifd->first, 0 ) < 0 ) { - std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + std::cerr << __FILE__ << ":" << __LINE__ << " " << ifd->first << " " + << errno << std::endl; // throw system_error } @@ -260,11 +274,21 @@ ev_add.events = EPOLLIN | EPOLLRDHUP | EPOLLERR | EPOLLHUP | EPOLLET | EPOLLONESHOT; ev_add.data.fd = fd; - if ( epoll_ctl( efd, EPOLL_CTL_ADD, fd, &ev_add ) < 0 ) { - descr.erase( fd ); - // throw system_error + if ( descr.find( fd ) != descr.end() ) { // reuse? std::cerr << __FILE__ << ":" << __LINE__ << std::endl; - return; // throw + if ( epoll_ctl( efd, EPOLL_CTL_MOD, fd, &ev_add ) < 0 ) { + std::cerr << __FILE__ << ":" << __LINE__ << " " << errno << std::endl; + descr.erase( fd ); + // throw system_error + return; // throw + } + } else { + std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; + if ( epoll_ctl( efd, EPOLL_CTL_ADD, fd, &ev_add ) < 0 ) { + // throw system_error + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + return; // throw + } } std::cerr << __FILE__ << ":" << __LINE__ << std::endl; @@ -292,6 +316,7 @@ sockbuf_t* b = info.b; if ( b == 0 ) { // marginal case: sockbuf wasn't created by processor... + std::cerr << __FILE__ << ":" << __LINE__ << " " << ifd->first << std::endl; if ( epoll_ctl( efd, EPOLL_CTL_DEL, ifd->first, 0 ) < 0 ) { // throw system_error } @@ -399,7 +424,7 @@ if ( (ev.events & (EPOLLRDHUP | EPOLLHUP | EPOLLERR) ) != 0 ) { // std::cerr << "Poll EPOLLRDHUP " << ev.data.fd << ", " << errno << std::endl; - std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + 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__ << std::endl; @@ -412,7 +437,6 @@ socks_processor_t* p = info.p; - closed_queue.erase( ev.data.fd ); descr.erase( ifd ); int lfd = check_closed_listener( p ); @@ -420,10 +444,13 @@ descr.erase( lfd ); } } else { - std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + b->_notify_close = false; // avoid deadlock + std::cerr << __FILE__ << ":" << __LINE__ << " " << ifd->first << std::endl; + if ( epoll_ctl( efd, EPOLL_CTL_DEL, ifd->first, 0 ) < 0 ) { + // throw system_error + } + descr.erase( ifd ); b->close(); - closed_queue.erase( ev.data.fd ); - descr.erase( ifd ); } dump_descr(); } @@ -452,6 +479,7 @@ { int myfd = -1; + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; if ( !listeners_final.empty() ) { std::cerr << __FILE__ << ":" << __LINE__ << std::endl; if ( listeners_final.find( static_cast<void*>(p) ) != listeners_final.end() ) { @@ -472,7 +500,10 @@ std::cerr << __FILE__ << ":" << __LINE__ << std::endl; - p->stop(); + // if ( myfd != -1 ) { + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + p->stop(); + // } } } Modified: branches/complement-sockios/explore/include/sockios/sp.h =================================================================== --- branches/complement-sockios/explore/include/sockios/sp.h 2008-06-26 05:46:17 UTC (rev 1917) +++ branches/complement-sockios/explore/include/sockios/sp.h 2008-06-26 05:46:44 UTC (rev 1918) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/25 11:54:39 ptr> +// -*- C++ -*- Time-stamp: <08/06/25 22:10:36 yeti> /* * Copyright (c) 2008 @@ -225,17 +225,36 @@ 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 exit_notify( sockbuf_t* b, sock_base::socket_type fd ) { // fd_info info = { 0, 0, 0 }; - std::tr2::lock_guard<std::tr2::mutex> lk( cll ); - closed_queue[fd] = fd_info(); + // std::tr2::lock_guard<std::tr2::mutex> lk( dll ); + + try { + std::tr2::unique_lock<std::tr2::mutex> lk( dll, std::tr2::try_to_lock ); + + if ( b->_notify_close ) { + std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; + typename fd_container_type::iterator i = descr.find( fd ); + if ( i != descr.end() ) { + if ( (i->second.b == b) && (i->second.p == 0) ) { + std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; + if ( epoll_ctl( efd, EPOLL_CTL_DEL, fd, 0 ) < 0 ) { + std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; + // throw system_error + } + std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; + descr.erase( i ); + } + } + b->_notify_close = false; + } + } + catch ( const std::tr2::lock_error& ) { + std::cerr << __FILE__ << ":" << __LINE__ << " " << fd << std::endl; + } } private: @@ -271,9 +290,7 @@ const int n_ret; fd_container_type descr; - fd_container_type closed_queue; listener_container_type listeners_final; - std::tr2::mutex cll; std::tr2::mutex dll; }; 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:46:17 UTC (rev 1917) +++ branches/complement-sockios/explore/lib/sockios/ut/sockios2_test.cc 2008-06-26 05:46:44 UTC (rev 1918) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/17 16:35:39 yeti> +// -*- C++ -*- Time-stamp: <08/06/25 17:59:36 yeti> /* * @@ -266,7 +266,14 @@ { lock_guard<mutex> lk(lock); --cnt; } void connect( sockstream& s ) - { lock_guard<mutex> lk(lock); getline( s, line ); ++rd; line_cnd.notify_one(); } + { + lock_guard<mutex> lk(lock); + getline( s, line ); + cerr << __FILE__ << ":" << __LINE__ << " " << s.good() << " " + << s.rdbuf()->in_avail() << endl; + ++rd; + line_cnd.notify_one(); + } // void close() // { } @@ -294,7 +301,7 @@ mutex worker::lock; int worker::cnt = 0; -/* volatile */ int worker::visits = 0; +int worker::visits = 0; condition_variable worker::cnd; string worker::line; condition_variable worker::line_cnd; @@ -413,7 +420,7 @@ } unique_lock<mutex> lk( worker::lock ); - EXAM_CHECK( worker::line_cnd.timed_wait( lk, milliseconds( 500 ), worker::rd_counter1 ) ); + EXAM_CHECK( worker::line_cnd.timed_wait( lk, milliseconds( 50000 ), worker::rd_counter1 ) ); // cerr << worker::line << endl; EXAM_CHECK( worker::line == "Hello, world!" ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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. |
From: <com...@us...> - 2008-06-26 05:46:05
|
Revision: 1916 http://complement.svn.sourceforge.net/complement/?rev=1916&view=rev Author: complement Date: 2008-06-25 22:46:02 -0700 (Wed, 25 Jun 2008) Log Message: ----------- Info for debug: order of exit/ready pool notification Modified Paths: -------------- branches/complement-sockios/explore/include/sockios/socksrv.cc Modified: branches/complement-sockios/explore/include/sockios/socksrv.cc =================================================================== --- branches/complement-sockios/explore/include/sockios/socksrv.cc 2008-06-26 05:45:45 UTC (rev 1915) +++ branches/complement-sockios/explore/include/sockios/socksrv.cc 2008-06-26 05:46:02 UTC (rev 1916) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/19 21:01:20 yeti> +// -*- C++ -*- Time-stamp: <08/06/24 18:34:58 yeti> /* * Copyright (c) 2008 @@ -289,10 +289,13 @@ std::tr2::unique_lock<std::tr2::mutex> lk( rdlock ); if ( !_in_work && ready_pool.empty() ) { + // std::cerr << __FILE__ << ":" << __LINE__ << std::endl; return false; } + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; cnd.wait( lk, not_empty ); + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; p = ready_pool.front(); // it may contain p.c == 0, p.s == 0, if !in_work() ready_pool.pop_front(); #if 0 @@ -339,6 +342,7 @@ _in_work = false; // <--- set before cnd.notify_one(); (below in this func) if ( ready_pool.empty() ) { ready_pool.push_back( processor() ); // make ready_pool not empty + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; cnd.notify_one(); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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. |
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. |
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. |
From: <com...@us...> - 2008-06-26 05:44:55
|
Revision: 1912 http://complement.svn.sourceforge.net/complement/?rev=1912&view=rev Author: complement Date: 2008-06-25 22:44:53 -0700 (Wed, 25 Jun 2008) Log Message: ----------- Under debugging; Detected problem use case: after close fd next assigned fd may has same number. Suggestion: clean close_quere ASAP, and remove appropriate fd from epoll's vector too. 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 branches/complement-sockios/explore/include/sockios/sockstream.cc branches/complement-sockios/explore/include/sockios/sp.cc branches/complement-sockios/explore/include/sockios/sp.h branches/complement-sockios/explore/lib/sockios/ut/sockios2_test.cc Modified: branches/complement-sockios/explore/include/sockios/socksrv.cc =================================================================== --- branches/complement-sockios/explore/include/sockios/socksrv.cc 2008-06-26 05:44:26 UTC (rev 1911) +++ branches/complement-sockios/explore/include/sockios/socksrv.cc 2008-06-26 05:44:53 UTC (rev 1912) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/16 20:25:28 yeti> +// -*- C++ -*- Time-stamp: <08/06/17 14:54:16 yeti> /* * Copyright (c) 2008 @@ -205,16 +205,20 @@ { typename base_t::sockstream_t* s = base_t::create_stream( fd, addr ); + if ( s == 0 ) { + return 0; + } + 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 ) ); - cnd.notify_one(); - } else { - std::tr2::lock_guard<std::tr2::mutex> lk( wklock ); - worker_pool.insert( std::make_pair( fd, processor( c, s ) ) ); - } + // if ( s->rdbuf()->in_avail() ) { + // std::tr2::lock_guard<std::tr2::mutex> lk( rdlock ); + // ready_pool.push_back( processor( c, s ) ); + // cnd.notify_one(); + // } else { + std::tr2::lock_guard<std::tr2::mutex> lk( wklock ); + worker_pool.insert( std::make_pair( fd, processor( c, s ) ) ); + // } return s->rdbuf(); } Modified: branches/complement-sockios/explore/include/sockios/socksrv.h =================================================================== --- branches/complement-sockios/explore/include/sockios/socksrv.h 2008-06-26 05:44:26 UTC (rev 1911) +++ branches/complement-sockios/explore/include/sockios/socksrv.h 2008-06-26 05:44:53 UTC (rev 1912) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/17 09:17:05 ptr> +// -*- C++ -*- Time-stamp: <08/06/17 15:44:44 yeti> /* * Copyright (c) 2008 @@ -109,7 +109,9 @@ sockstream_t* create_stream( int fd, const sockaddr& addr ) { sockstream_t* s = new sockstream_t(); - s->rdbuf()->_open_sockmgr( fd, addr ); + if ( s != 0 ) { + s->rdbuf()->_open_sockmgr( fd, addr ); + } return s; } @@ -197,7 +199,11 @@ { std::tr2::lock_guard<std::tr2::mutex> lk2( wklock ); - cerr << __FILE__ << ":" << __LINE__ << " " << worker_pool.size() << endl; + cerr << __FILE__ << ":" << __LINE__ << " " << worker_pool.size() << endl; + for ( typename worker_pool_t::iterator i = worker_pool.begin(); i != worker_pool.end(); ++i ) { + delete i->second.c; + delete i->second.s; + } } ((Init *)Init_buf)->~Init(); Modified: branches/complement-sockios/explore/include/sockios/sockstream =================================================================== --- branches/complement-sockios/explore/include/sockios/sockstream 2008-06-26 05:44:26 UTC (rev 1911) +++ branches/complement-sockios/explore/include/sockios/sockstream 2008-06-26 05:44:53 UTC (rev 1912) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/15 17:11:29 ptr> +// -*- C++ -*- Time-stamp: <08/06/17 17:09:45 yeti> /* * Copyright (c) 1997-1999, 2002, 2003, 2005-2008 @@ -448,8 +448,10 @@ virtual ~basic_sockbuf() { + 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, Modified: branches/complement-sockios/explore/include/sockios/sockstream.cc =================================================================== --- branches/complement-sockios/explore/include/sockios/sockstream.cc 2008-06-26 05:44:26 UTC (rev 1911) +++ branches/complement-sockios/explore/include/sockios/sockstream.cc 2008-06-26 05:44:53 UTC (rev 1912) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/11 14:47:58 yeti> +// -*- C++ -*- Time-stamp: <08/06/17 17:09:02 yeti> /* * Copyright (c) 1997-1999, 2002, 2003, 2005-2008 @@ -392,19 +392,26 @@ template<class charT, class traits, class _Alloc> int basic_sockbuf<charT, traits, _Alloc>::sync() { + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; if ( !basic_socket_t::is_open() ) { return -1; } long count = this->pptr() - this->pbase(); if ( count ) { + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; // _STLP_ASSERT( this->pbase() != 0 ); count *= sizeof(charT); long start = 0; while ( count > 0 ) { long offset = (this->*_xwrite)( this->pbase() + start, count ); + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; if ( offset < 0 ) { - if ( errno == EAGAIN ) { + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + if ( errno == EINTR ) { + errno = 0; + continue; + } else if ( errno == EAGAIN ) { pollfd wpfd; wpfd.fd = basic_socket_t::_fd; wpfd.events = POLLOUT | POLLHUP | POLLWRNORM; @@ -412,6 +419,7 @@ while ( poll( &wpfd, 1, basic_socket_t::_use_wrtimeout ? basic_socket_t::_wrtimeout.count() : -1 ) <= 0 ) { // wait infinite if ( errno == EINTR ) { // may be interrupted, check and ignore errno = 0; + // reduce timeout? continue; } return -1; @@ -427,6 +435,7 @@ return -1; } } + std::cerr << __FILE__ << ":" << __LINE__ << " " << basic_socket_t::_fd << std::endl; count -= offset; start += offset; } Modified: branches/complement-sockios/explore/include/sockios/sp.cc =================================================================== --- branches/complement-sockios/explore/include/sockios/sp.cc 2008-06-26 05:44:26 UTC (rev 1911) +++ branches/complement-sockios/explore/include/sockios/sp.cc 2008-06-26 05:44:53 UTC (rev 1912) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/17 13:10:39 yeti> +// -*- C++ -*- Time-stamp: <08/06/17 17:41:00 yeti> /* * Copyright (c) 2008 @@ -116,8 +116,21 @@ 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 = { fd_info::buffer, static_cast<sockbuf_t*>(_ctl.data.ptr), 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 @@ -164,19 +177,19 @@ return; // I don't know what to do this case... } - { - 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 closing, ignore all incoming connects - closed_queue.erase( closed_ifd ); - if ( epoll_ctl( efd, EPOLL_CTL_DEL, ifd->first, 0 ) < 0 ) { - // throw system_error - } - descr.erase( ifd ); - return; - } + // { + 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 ); @@ -189,11 +202,13 @@ // std::cerr << "Accept, listener # " << ev.data.fd << ", errno " << errno << std::endl; std::cerr << __FILE__ << ":" << __LINE__ /* << " " << std::tr2::getpid() */ << std::endl; if ( (errno == EINTR) || (errno == ECONNABORTED) /* || (errno == ERESTARTSYS) */ ) { + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; errno = 0; continue; } if ( !(errno == EAGAIN /* || errno == EWOULDBLOCK */ ) ) { // EWOULDBLOCK == EAGAIN // std::cerr << "Accept, listener " << ev.data.fd << ", errno " << errno << std::endl; + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; if ( epoll_ctl( efd, EPOLL_CTL_DEL, ifd->first, 0 ) < 0 ) { std::cerr << __FILE__ << ":" << __LINE__ << std::endl; // throw system_error @@ -211,7 +226,7 @@ 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 ); +// 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 @@ -237,20 +252,23 @@ } 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; ev_add.data.fd = fd; - fd_info new_info = { fd_info::owner, b, info.p }; - descr[fd] = new_info; if ( epoll_ctl( efd, EPOLL_CTL_ADD, fd, &ev_add ) < 0 ) { descr.erase( fd ); // throw system_error + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + return; // throw } + + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + 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; } catch ( const std::bad_alloc& ) { // nothing @@ -265,53 +283,45 @@ template<class charT, class traits, class _Alloc> void sockmgr<charT,traits,_Alloc>::process_regular( epoll_event& ev, typename sockmgr<charT,traits,_Alloc>::fd_container_type::iterator ifd ) { + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + 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 ); + + 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 ) { // throw system_error } + if ( info.p != 0 ) { // ... but controlled by processor + (*info.p)( ifd->first, typename socks_processor_t::adopt_close_t() ); + } descr.erase( ifd ); + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; return; } + errno = 0; + + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; if ( ev.events & EPOLLIN ) { -#if 0 - if ( (info.flags & fd_info::owner) == 0 ) { - /* - marginal case: sockmgr isn't owner (registerd via push(), - when I owner, I know destroy point), - already closed, but I don't see closed event yet; - object may be deleted already, so I can't - call b->egptr() etc. here - */ - 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; - } - } -#endif - - sockbuf_t* b = info.b; - errno = 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 ); - return; - } + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; for ( ; ; ) { if ( b->_ebuf == b->egptr() ) { + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; // process extract data from buffer too slow for us! if ( (info.flags & fd_info::level_triggered) == 0 ) { epoll_event xev; @@ -332,6 +342,7 @@ long offset = read( ev.data.fd, b->egptr(), sizeof(charT) * (b->_ebuf - b->egptr()) ); // std::cerr << "offset " << offset << ", " << errno << std::endl; if ( offset < 0 ) { + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; switch ( errno ) { case EINTR: // read was interrupted errno = 0; @@ -339,10 +350,12 @@ break; case EFAULT: // Bad address case ECONNRESET: // Connection reset by peer + errno = 0; ev.events |= EPOLLRDHUP; // will be processed below break; case EAGAIN: // case EWOULDBLOCK: + errno = 0; { epoll_event xev; xev.events = EPOLLIN | EPOLLRDHUP | EPOLLERR | EPOLLHUP | EPOLLET | EPOLLONESHOT; @@ -352,10 +365,12 @@ break; default: // std::cerr << "not listener, other " << ev.data.fd << std::hex << ev.events << std::dec << " : " << errno << std::endl; + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; break; } break; } else if ( offset > 0 ) { + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; offset /= sizeof(charT); // if offset % sizeof(charT) != 0, rest will be lost! if ( info.flags & fd_info::level_triggered ) { @@ -371,9 +386,11 @@ b->setg( b->eback(), b->gptr(), b->egptr() + offset ); b->ucnd.notify_one(); if ( info.p != 0 ) { + std::cerr << __FILE__ << ":" << __LINE__ << " " << ev.data.fd << std::endl; (*info.p)( ev.data.fd ); } } else { + std::cerr << __FILE__ << ":" << __LINE__ << 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 @@ -384,15 +401,18 @@ if ( (ev.events & (EPOLLRDHUP | EPOLLHUP | EPOLLERR) ) != 0 ) { // std::cerr << "Poll EPOLLRDHUP " << ev.data.fd << ", " << errno << std::endl; + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; if ( epoll_ctl( efd, EPOLL_CTL_DEL, ifd->first, 0 ) < 0 ) { // throw system_error + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; } if ( info.p != 0 ) { + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; (*info.p)( ifd->first, typename socks_processor_t::adopt_close_t() ); - } /* else */ - if ( (info.flags & fd_info::buffer) != 0 ) { - info.b->close(); + } else { + std::cerr << __FILE__ << ":" << __LINE__ << std::endl; + b->close(); } // std::tr2::lock_guard<std::tr2::mutex> lck( cll ); closed_queue.erase( ev.data.fd ); Modified: branches/complement-sockios/explore/include/sockios/sp.h =================================================================== --- branches/complement-sockios/explore/include/sockios/sp.h 2008-06-26 05:44:26 UTC (rev 1911) +++ branches/complement-sockios/explore/include/sockios/sp.h 2008-06-26 05:44:53 UTC (rev 1912) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/15 23:21:50 ptr> +// -*- C++ -*- Time-stamp: <08/06/17 15:09:45 yeti> /* * Copyright (c) 2008 @@ -87,9 +87,7 @@ { enum { listener = 0x1, - level_triggered = 0x2, - owner = 0x4, - buffer = 0x8 + level_triggered = 0x2 }; unsigned flags; 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:44:26 UTC (rev 1911) +++ branches/complement-sockios/explore/lib/sockios/ut/sockios2_test.cc 2008-06-26 05:44:53 UTC (rev 1912) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/17 13:47:21 yeti> +// -*- C++ -*- Time-stamp: <08/06/17 16:35:39 yeti> /* * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-06-26 05:44:28
|
Revision: 1911 http://complement.svn.sourceforge.net/complement/?rev=1911&view=rev Author: complement Date: 2008-06-25 22:44:26 -0700 (Wed, 25 Jun 2008) Log Message: ----------- One deadlock in sockmgr removed; fixed test. Double lock of closed_queue removed. In test barrier replaced by condition_variable, to avoid deadlock in sockmgr; fixed usage of condition---line_cnd should be on line check instead of cnd. test with rest data reading not pass, but should. Modified Paths: -------------- 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/sp.cc =================================================================== --- branches/complement-sockios/explore/include/sockios/sp.cc 2008-06-26 05:44:09 UTC (rev 1910) +++ branches/complement-sockios/explore/include/sockios/sp.cc 2008-06-26 05:44:26 UTC (rev 1911) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/17 10:35:40 ptr> +// -*- C++ -*- Time-stamp: <08/06/17 13:10:39 yeti> /* * Copyright (c) 2008 @@ -394,7 +394,7 @@ if ( (info.flags & fd_info::buffer) != 0 ) { info.b->close(); } - std::tr2::lock_guard<std::tr2::mutex> lck( cll ); + // std::tr2::lock_guard<std::tr2::mutex> lck( cll ); closed_queue.erase( ev.data.fd ); descr.erase( ifd ); } 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:44:09 UTC (rev 1910) +++ branches/complement-sockios/explore/lib/sockios/ut/sockios2_test.cc 2008-06-26 05:44:26 UTC (rev 1911) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/17 09:11:57 ptr> +// -*- C++ -*- Time-stamp: <08/06/17 13:47:21 yeti> /* * @@ -68,25 +68,32 @@ protected: virtual sock_basic_processor::sockbuf_t* operator ()( sock_base::socket_type, const sockaddr& ) - { lock_guard<mutex> lk(lock); b.wait(); ++n_cnt; return 0; } + { lock_guard<mutex> lk(lock); ++n_cnt; cnd.notify_one(); return 0; } virtual void operator ()( sock_base::socket_type, const adopt_close_t& ) - { lock_guard<mutex> lk(lock); b.wait(); ++c_cnt; } + { lock_guard<mutex> lk(lock); ++c_cnt; cnd.notify_one(); } virtual void operator ()( sock_base::socket_type ) - { lock_guard<mutex> lk(lock); ++d_cnt; } + { lock_guard<mutex> lk(lock); ++d_cnt; cnd.notify_one(); } public: static mutex lock; static int n_cnt; static int c_cnt; static int d_cnt; - static barrier b; + static condition_variable cnd; + + static bool n_cnt_check() + { return n_cnt == 1; } + static bool c_cnt_check() + { return c_cnt == 1; } + static bool d_cnt_check() + { return d_cnt == 1; } }; mutex simple_mgr::lock; int simple_mgr::n_cnt = 0; int simple_mgr::c_cnt = 0; int simple_mgr::d_cnt = 0; -barrier simple_mgr::b; +condition_variable simple_mgr::cnd; class simple_mgr2 : public sock_basic_processor @@ -104,8 +111,8 @@ virtual sock_basic_processor::sockbuf_t* operator ()( sock_base::socket_type fd, const sockaddr& addr ) { lock_guard<mutex> lk(lock); - b.wait(); ++n_cnt; + cnd.notify_one(); sockstream_t* s = sock_basic_processor::create_stream( fd, addr ); cons[fd] = s; @@ -116,8 +123,8 @@ virtual void operator ()( sock_base::socket_type fd, const adopt_close_t& ) { lock_guard<mutex> lk(lock); - b.wait(); ++c_cnt; + cnd.notify_one(); delete cons[fd]; cons.erase( fd ); } @@ -125,8 +132,8 @@ virtual void operator ()( sock_base::socket_type fd ) { lock_guard<mutex> lk(lock); - b.wait(); ++d_cnt; + cnd.notify_one(); string str; getline( *cons[fd], str ); // map fd -> s EXAM_CHECK_ASYNC( str == "Hello" ); @@ -137,8 +144,15 @@ static int n_cnt; static int c_cnt; static int d_cnt; - static barrier b; + static condition_variable cnd; + static bool n_cnt_check() + { return n_cnt == 1; } + static bool c_cnt_check() + { return c_cnt == 1; } + static bool d_cnt_check() + { return d_cnt == 1; } + private: #ifdef __USE_STLPORT_HASH @@ -158,7 +172,7 @@ int simple_mgr2::n_cnt = 0; int simple_mgr2::c_cnt = 0; int simple_mgr2::d_cnt = 0; -barrier simple_mgr2::b; +condition_variable simple_mgr2::cnd; int EXAM_IMPL(sockios2_test::srv_core) @@ -190,9 +204,9 @@ EXAM_CHECK( s.good() ); { - simple_mgr::b.wait(); - lock_guard<mutex> lk(simple_mgr::lock); - EXAM_CHECK( simple_mgr::n_cnt == 1 ); + unique_lock<mutex> lk( simple_mgr::lock ); + + EXAM_CHECK( simple_mgr::cnd.timed_wait( lk, milliseconds( 500 ), simple_mgr::n_cnt_check ) ); } { lock_guard<mutex> lk(simple_mgr::lock); @@ -204,9 +218,10 @@ } } - simple_mgr::b.wait(); - lock_guard<mutex> lk(simple_mgr::lock); - EXAM_CHECK( simple_mgr::c_cnt == 1 ); + unique_lock<mutex> lk( simple_mgr::lock ); + + EXAM_CHECK( simple_mgr::cnd.timed_wait( lk, milliseconds( 500 ), simple_mgr::c_cnt_check ) ); + EXAM_CHECK( simple_mgr::d_cnt == 0 ); } { @@ -221,22 +236,19 @@ EXAM_CHECK( s.good() ); { - simple_mgr2::b.wait(); - lock_guard<mutex> lk(simple_mgr2::lock); - EXAM_CHECK( simple_mgr2::n_cnt == 1 ); + unique_lock<mutex> lk( simple_mgr2::lock ); + EXAM_CHECK( simple_mgr2::cnd.timed_wait( lk, milliseconds( 500 ), simple_mgr2::n_cnt_check ) ); } { s << "Hello" << endl; EXAM_CHECK( s.good() ); - simple_mgr2::b.wait(); - lock_guard<mutex> lk(simple_mgr2::lock); - EXAM_CHECK( simple_mgr2::d_cnt == 1 ); + unique_lock<mutex> lk( simple_mgr2::lock ); + EXAM_CHECK( simple_mgr2::cnd.timed_wait( lk, milliseconds( 500 ), simple_mgr2::d_cnt_check ) ); } s.close(); { - simple_mgr2::b.wait(); - lock_guard<mutex> lk(simple_mgr2::lock); - EXAM_CHECK( simple_mgr2::c_cnt == 1 ); + unique_lock<mutex> lk( simple_mgr2::lock ); + EXAM_CHECK( simple_mgr2::cnd.timed_wait( lk, milliseconds( 500 ), simple_mgr2::c_cnt_check ) ); } } } @@ -269,7 +281,15 @@ static string line; static condition_variable line_cnd; static int rd; - // static barrier b; + + static bool visits_counter1() + { return worker::visits == 1; } + + static bool visits_counter2() + { return worker::visits == 2; } + + static bool rd_counter1() + { return worker::rd == 1; } }; mutex worker::lock; @@ -288,21 +308,6 @@ // prss->close(); // } -bool visits_counter1() -{ - return worker::visits == 1; -} - -bool visits_counter2() -{ - return worker::visits == 2; -} - -bool rd_counter1() -{ - return worker::rd > 0; // == 1; -} - int EXAM_IMPL(sockios2_test::processor_core) { { @@ -323,9 +328,7 @@ unique_lock<mutex> lk( worker::lock ); - worker::cnd.timed_wait( lk, milliseconds( 500 ), visits_counter1 ); - - EXAM_CHECK( worker::visits == 1 ); + EXAM_CHECK( worker::cnd.timed_wait( lk, milliseconds( 500 ), worker::visits_counter1 ) ); worker::visits = 0; } } @@ -354,11 +357,10 @@ // for ( int i = 0; i < 1024; ++i ) { // give chance to process it // std::tr2::this_thread::yield(); // } + unique_lock<mutex> lk( worker::lock ); - worker::cnd.timed_wait( lk, milliseconds( 500 ), visits_counter2 ); - - EXAM_CHECK( worker::visits == 2 ); + EXAM_CHECK( worker::cnd.timed_wait( lk, milliseconds( 500 ), worker::visits_counter2 ) ); worker::visits = 0; } } @@ -368,7 +370,7 @@ } - // check before sockstream was closed + // check income data before sockstream was closed { connect_processor<worker> prss( 2008 ); @@ -384,7 +386,7 @@ s1 << "Hello, world!" << endl; unique_lock<mutex> lk( worker::lock ); - worker::cnd.timed_wait( lk, milliseconds( 100 ), rd_counter1 ); + EXAM_CHECK( worker::line_cnd.timed_wait( lk, milliseconds( 500 ), worker::rd_counter1 ) ); // cerr << worker::line << endl; EXAM_CHECK( worker::line == "Hello, world!" ); @@ -393,10 +395,8 @@ } } - EXAM_CHECK( worker::line == "" ); - EXAM_CHECK( worker::rd == 0 ); - - // check after sockstream2 was closed, i.e. ensure, that all data available read before close + // check after sockstream was closed, i.e. ensure, that all data available + // was read before stream was closed { connect_processor<worker> prss( 2008 ); @@ -413,16 +413,14 @@ } unique_lock<mutex> lk( worker::lock ); - worker::cnd.timed_wait( lk, milliseconds( 100 ), rd_counter1 ); + EXAM_CHECK( worker::line_cnd.timed_wait( lk, milliseconds( 500 ), worker::rd_counter1 ) ); - cerr << worker::line << endl; + // cerr << worker::line << endl; EXAM_CHECK( worker::line == "Hello, world!" ); worker::line = ""; worker::rd = 0; } - EXAM_CHECK( worker::line == "" ); - return EXAM_RESULT; } @@ -465,9 +463,7 @@ EXAM_CHECK_ASYNC( prss.is_open() ); unique_lock<mutex> lk( worker::lock ); - worker::cnd.timed_wait( lk, milliseconds( 100 ), visits_counter1 ); - - EXAM_CHECK_ASYNC( worker::visits == 1 ); + EXAM_CHECK_ASYNC( worker::cnd.timed_wait( lk, milliseconds( 500 ), worker::visits_counter1 ) ); } exit( 0 ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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. |
From: <com...@us...> - 2008-06-26 05:43:49
|
Revision: 1909 http://complement.svn.sourceforge.net/complement/?rev=1909&view=rev Author: complement Date: 2008-06-25 22:43:48 -0700 (Wed, 25 Jun 2008) Log Message: ----------- final method may lead to deadlock: process close via sockmgr When server closed, all sockets (connections) should be closed, but via sockmgr/epoll (via descriptors); this done with sock_buf::shutdown; but I'm not sure that all connections really closed/destroyed at connection_processor dtor, but this is MUST (otherwise call of unexistent object happens) 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/lib/sockios/ut/sockios2_test.cc Modified: branches/complement-sockios/explore/include/sockios/socksrv.cc =================================================================== --- branches/complement-sockios/explore/include/sockios/socksrv.cc 2008-06-26 05:43:27 UTC (rev 1908) +++ branches/complement-sockios/explore/include/sockios/socksrv.cc 2008-06-26 05:43:48 UTC (rev 1909) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/16 10:45:56 ptr> +// -*- C++ -*- Time-stamp: <08/06/16 20:25:28 yeti> /* * Copyright (c) 2008 @@ -198,12 +198,6 @@ // std::cerr << "=== " << ready_pool.size() << std::endl; cnd.notify_one(); } - - basic_socket<charT,traits,_Alloc>::mgr->final( *this ); - - if ( ploop.joinable() ) { - ploop.join(); - } } template <class Connect, class charT, class traits, class _Alloc, void (Connect::*C)( std::basic_sockstream<charT,traits,_Alloc>& )> Modified: branches/complement-sockios/explore/include/sockios/socksrv.h =================================================================== --- branches/complement-sockios/explore/include/sockios/socksrv.h 2008-06-26 05:43:27 UTC (rev 1908) +++ branches/complement-sockios/explore/include/sockios/socksrv.h 2008-06-26 05:43:48 UTC (rev 1909) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/15 23:29:23 ptr> +// -*- C++ -*- Time-stamp: <08/06/16 22:07:54 yeti> /* * Copyright (c) 2008 @@ -175,6 +175,22 @@ { connect_processor::close(); + if ( ploop.joinable() ) { + ploop.join(); + } + + basic_socket<charT,traits,_Alloc>::mgr->final( *this ); + + { + std::tr2::lock_guard<std::tr2::mutex> lk2( rdlock ); + cerr << __FILE__ << ":" << __LINE__ << " " << ready_pool.size() << endl; + } + + { + std::tr2::lock_guard<std::tr2::mutex> lk2( wklock ); + cerr << __FILE__ << ":" << __LINE__ << " " << worker_pool.size() << endl; + } + ((Init *)Init_buf)->~Init(); } Modified: branches/complement-sockios/explore/include/sockios/sp.cc =================================================================== --- branches/complement-sockios/explore/include/sockios/sp.cc 2008-06-26 05:43:27 UTC (rev 1908) +++ branches/complement-sockios/explore/include/sockios/sp.cc 2008-06-26 05:43:48 UTC (rev 1909) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/16 11:05:56 ptr> +// -*- C++ -*- Time-stamp: <08/06/16 20:24:51 yeti> /* * Copyright (c) 2008 @@ -140,6 +140,11 @@ if ( ifd->second.p != 0 ) { ifd->second.p->close(); + for ( typename fd_container_type::iterator i = descr.begin(); i != descr.end(); ++i ) { + if ( (i->second.p == ifd->second.p) && (i->second.b != 0) ) { + i->second.b->shutdown( sock_base::stop_in | sock_base::stop_out ); + } + } } descr.erase( ifd ); @@ -194,6 +199,11 @@ if ( ifd->second.p != 0 ) { ifd->second.p->close(); + for ( typename fd_container_type::iterator i = descr.begin(); i != descr.end(); ++i ) { + if ( (i->second.p == ifd->second.p) && (i->second.b != 0) ) { + i->second.b->shutdown( sock_base::stop_in | sock_base::stop_out ); + } + } } descr.erase( ifd ); @@ -388,6 +398,7 @@ 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(); ) { @@ -403,6 +414,7 @@ ++ifd; } } +#endif std::tr2::lock_guard<std::tr2::mutex> lk( cll ); 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:27 UTC (rev 1908) +++ branches/complement-sockios/explore/lib/sockios/ut/sockios2_test.cc 2008-06-26 05:43:48 UTC (rev 1909) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/15 21:52:52 ptr> +// -*- C++ -*- Time-stamp: <08/06/16 20:35:30 yeti> /* * @@ -393,8 +393,8 @@ } } - EXAM_CHECK( worker::line == "" ); + EXAM_CHECK( worker::rd == 0 ); // check after sockstream2 was closed, i.e. ensure, that all data available read before close { @@ -413,9 +413,9 @@ } unique_lock<mutex> lk( worker::lock ); - worker::cnd.timed_wait( lk, milliseconds( 500 ), rd_counter1 ); + worker::cnd.timed_wait( lk, milliseconds( 100 ), rd_counter1 ); - // cerr << worker::line << endl; + cerr << worker::line << endl; EXAM_CHECK( worker::line == "Hello, world!" ); worker::line = ""; worker::rd = 0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-06-26 05:43:30
|
Revision: 1908 http://complement.svn.sourceforge.net/complement/?rev=1908&view=rev Author: complement Date: 2008-06-25 22:43:27 -0700 (Wed, 25 Jun 2008) Log Message: ----------- Review processing in sockmgr. Server's finalization still not work properly: problem in interrupted_server test on finalization (still read socket) in dbg mode. 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 branches/complement-sockios/explore/include/sockios/sp.cc branches/complement-sockios/explore/include/sockios/sp.h branches/complement-sockios/explore/lib/sockios/_sp.cc branches/complement-sockios/explore/lib/sockios/ut/sockios2_test.cc Modified: branches/complement-sockios/explore/include/sockios/socksrv.cc =================================================================== --- branches/complement-sockios/explore/include/sockios/socksrv.cc 2008-06-26 05:43:01 UTC (rev 1907) +++ branches/complement-sockios/explore/include/sockios/socksrv.cc 2008-06-26 05:43:27 UTC (rev 1908) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/11 21:41:27 yeti> +// -*- C++ -*- Time-stamp: <08/06/16 10:45:56 ptr> /* * Copyright (c) 2008 @@ -192,10 +192,18 @@ _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::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(); + } + + basic_socket<charT,traits,_Alloc>::mgr->final( *this ); + + if ( ploop.joinable() ) { + ploop.join(); + } } template <class Connect, class charT, class traits, class _Alloc, void (Connect::*C)( std::basic_sockstream<charT,traits,_Alloc>& )> Modified: branches/complement-sockios/explore/include/sockios/socksrv.h =================================================================== --- branches/complement-sockios/explore/include/sockios/socksrv.h 2008-06-26 05:43:01 UTC (rev 1907) +++ branches/complement-sockios/explore/include/sockios/socksrv.h 2008-06-26 05:43:27 UTC (rev 1908) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/11 21:40:56 yeti> +// -*- C++ -*- Time-stamp: <08/06/15 23:29:23 ptr> /* * Copyright (c) 2008 @@ -68,7 +68,6 @@ { sock_processor_base::close(); - std::cerr << __FILE__ << ":" << __LINE__ << " " << (void*)this << " " << std::tr2::getpid() << std::endl; // Never uncomment next line: // basic_socket<charT,traits,_Alloc>::mgr->final( *this ); // this lead to virtual fuction call, that is already pure here. @@ -175,26 +174,7 @@ virtual ~connect_processor() { connect_processor::close(); - if ( ploop.joinable() ) { - ploop.join(); - } - // { - // std::tr2::lock_guard<std::tr2::mutex> lk( wklock ); - for ( typename worker_pool_t::iterator i = worker_pool.begin(); i != worker_pool.end(); ++i ) { - // delete i->second; - delete i->second.s; - delete i->second.c; - } - worker_pool.clear(); - // } - for ( typename ready_pool_t::iterator j = ready_pool.begin(); j != ready_pool.end(); ++j ) { - delete j->c; - } - ready_pool.clear(); - std::cerr << __FILE__ << ":" << __LINE__ << " " << (void*)this << " " << std::tr2::getpid() << std::endl; - basic_socket<charT,traits,_Alloc>::mgr->final( *this ); - ((Init *)Init_buf)->~Init(); } Modified: branches/complement-sockios/explore/include/sockios/sockstream =================================================================== --- branches/complement-sockios/explore/include/sockios/sockstream 2008-06-26 05:43:01 UTC (rev 1907) +++ branches/complement-sockios/explore/include/sockios/sockstream 2008-06-26 05:43:27 UTC (rev 1908) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/11 14:45:16 yeti> +// -*- C++ -*- Time-stamp: <08/06/15 17:11:29 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005-2008 @@ -316,7 +316,7 @@ } #endif // _sock_processor_base::_idx = std::tr2::this_thread::xalloc(); - std::cerr << __FILE__ << ":" << __LINE__ << " new mgr " << std::tr2::getpid() << std::endl; + // std::cerr << __FILE__ << ":" << __LINE__ << " new mgr " << std::tr2::getpid() << std::endl; } } else { std::tr2::lock_guard<std::tr2::mutex> lk( _init_lock ); @@ -324,7 +324,7 @@ if ( basic_socket<charT,traits,_Alloc>::mgr == 0 ) { std::cerr << __FILE__ << ":" << __LINE__ << " shit happens\n"; } - std::cerr << __FILE__ << ":" << __LINE__ << " mgr destroyed " << std::tr2::getpid() << std::endl; + // std::cerr << __FILE__ << ":" << __LINE__ << " mgr destroyed " << std::tr2::getpid() << std::endl; delete basic_socket<charT,traits,_Alloc>::mgr; basic_socket<charT,traits,_Alloc>::mgr = 0; } Modified: branches/complement-sockios/explore/include/sockios/sp.cc =================================================================== --- branches/complement-sockios/explore/include/sockios/sp.cc 2008-06-26 05:43:01 UTC (rev 1907) +++ branches/complement-sockios/explore/include/sockios/sp.cc 2008-06-26 05:43:27 UTC (rev 1908) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/11 21:42:37 yeti> +// -*- C++ -*- Time-stamp: <08/06/16 11:05:56 ptr> /* * Copyright (c) 2008 @@ -134,90 +134,112 @@ void sockmgr<charT,traits,_Alloc>::process_listener( epoll_event& ev, typename sockmgr<charT,traits,_Alloc>::fd_container_type::iterator ifd ) { if ( ev.events & EPOLLRDHUP ) { - epoll_ctl( efd, EPOLL_CTL_DEL, ifd->first, 0 ); - // walk through descr and detach every .p ? + if ( epoll_ctl( efd, EPOLL_CTL_DEL, ifd->first, 0 ) < 0 ) { + // throw system_error + } + + if ( ifd->second.p != 0 ) { + ifd->second.p->close(); + } + descr.erase( ifd ); - std::cerr << "Remove listener EPOLLRDHUP\n"; - } else if ( ev.events & EPOLLIN ) { - sockaddr addr; - socklen_t sz = sizeof( sockaddr_in ); - 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_ifd->second.p == ifd->second.p ) { + // listener in process of close + closed_queue.erase( closed_ifd ); + } - for ( ; ; ) { - 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; - if ( (errno == EINTR) || (errno == ECONNABORTED) /* || (errno == ERESTARTSYS) */ ) { - continue; - } - if ( !(errno == EAGAIN || errno == EWOULDBLOCK) ) { - // std::cerr << "Accept, listener " << ev[i].data.fd << ", errno " << errno << std::endl; - // throw system_error ? - } -#if 0 - { - 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() ) { - typename fd_container_type::iterator ifd = descr.begin(); - for ( ; ifd != descr.end(); ) { - if ( ifd->second.p == closed_ifd->second.p ) { - descr.erase( ifd++ ); - } else { - ++ifd; - } - } - closed_queue.erase( closed_ifd ); - } - } -#endif - break; + return; + } + + if ( (ev.events & EPOLLIN) == 0 ) { + return; // I don't know what to do this case... + } + + { + 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 closing, ignore all incoming connects + closed_queue.erase( closed_ifd ); + if ( epoll_ctl( efd, EPOLL_CTL_DEL, ifd->first, 0 ) < 0 ) { + // throw system_error } - // std::cerr << "listener accept " << fd << std::endl; - if ( fcntl( fd, F_SETFL, fcntl( fd, F_GETFL ) | O_NONBLOCK ) != 0 ) { - throw std::runtime_error( "can't establish nonblock mode" ); - } - - try { - std::cerr << __FILE__ << ":" << __LINE__ << " new sockstream_t" << std::endl; - sockbuf_t* b = (*info.p)( fd, addr ); + descr.erase( ifd ); + return; + } + } - 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, b, info.p }; - descr[fd] = new_info; + sockaddr addr; + socklen_t sz = sizeof( sockaddr_in ); - if ( epoll_ctl( efd, EPOLL_CTL_ADD, fd, &ev_add ) < 0 ) { - std::cerr << "Accept, add " << fd << ", errno " << errno << std::endl; - descr.erase( fd ); + fd_info info = ifd->second; + + for ( ; ; ) { + 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; + if ( (errno == EINTR) || (errno == ECONNABORTED) /* || (errno == ERESTARTSYS) */ ) { + errno = 0; + continue; + } + 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 ) { // throw system_error } - 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 ( ifd->second.p != 0 ) { + ifd->second.p->close(); } + + 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 ? + } 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 ); } - catch ( const std::bad_alloc& ) { - // nothing - } - catch ( ... ) { + return; + } + if ( fcntl( fd, F_SETFL, fcntl( fd, F_GETFL ) | O_NONBLOCK ) != 0 ) { + throw std::runtime_error( "can't establish nonblock mode" ); + } + + try { + sockbuf_t* b = (*info.p)( 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, b, info.p }; + descr[fd] = new_info; + + if ( epoll_ctl( efd, EPOLL_CTL_ADD, fd, &ev_add ) < 0 ) { descr.erase( fd ); + // throw system_error } } - } else { - // std::cerr << "listener: " << std::hex << ev.events << std::dec << std::endl; + catch ( const std::bad_alloc& ) { + // nothing + descr.erase( fd ); + } + catch ( ... ) { + descr.erase( fd ); + } } } @@ -228,11 +250,13 @@ if ( ev.events & EPOLLIN ) { if ( (info.flags & fd_info::owner) == 0 ) { - // marginal case: me not owner (registerd via push(), - // when I owner, I know destroy point), - // already closed, but I not see closed event yet; - // object may be deleted already, so I can't - // call b->egptr() etc. here + /* + marginal case: sockmgr isn't owner (registerd via push(), + when I owner, I know destroy point), + already closed, but I don't see closed event yet; + object may be deleted already, so I can't + call b->egptr() etc. here + */ 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() ) { @@ -262,26 +286,12 @@ xev.data.fd = ev.data.fd; info.flags |= fd_info::level_triggered; if ( epoll_ctl( efd, EPOLL_CTL_MOD, ev.data.fd, &xev ) < 0 ) { - std::cerr << "X " << ev.data.fd << ", " << errno << std::endl; + // std::cerr << "X " << ev.data.fd << ", " << errno << std::endl; } } - std::cerr << "Z " << ev.data.fd << ", " << errno << std::endl; + // std::cerr << "Z " << ev.data.fd << ", " << errno << std::endl; if ( info.p != 0 ) { // or (info.flags & fd_info::owner) != 0 - bool is_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 ) { - is_closed = true; - std::cerr << "@@@ 2\n" << std::endl; - break; - } - } - } - if ( !is_closed ) { - (*info.p)( ev.data.fd ); - } + (*info.p)( ev.data.fd ); } break; } @@ -289,28 +299,29 @@ long offset = read( ev.data.fd, b->egptr(), sizeof(charT) * (b->_ebuf - b->egptr()) ); // std::cerr << "offset " << offset << ", " << errno << std::endl; if ( offset < 0 ) { - if ( (errno == EAGAIN) || (errno == EINTR) ) { - 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 ); - break; - } else { - switch ( errno ) { - // case EINTR: // read was interrupted - // continue; - // break; - case EFAULT: // Bad address - case ECONNRESET: // Connection reset by peer - ev.events |= EPOLLRDHUP; // will be processed below - break; - default: - // std::cerr << "not listener, other " << ev.data.fd << std::hex << ev.events << std::dec << " : " << errno << std::endl; - break; - } - break; + switch ( errno ) { + case EINTR: // read was interrupted + errno = 0; + continue; + break; + case EFAULT: // Bad address + case ECONNRESET: // Connection reset by peer + ev.events |= EPOLLRDHUP; // will be processed below + break; + case EAGAIN: + // case EWOULDBLOCK: + { + 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 ); + } + break; + default: + // std::cerr << "not listener, other " << ev.data.fd << std::hex << ev.events << std::dec << " : " << errno << std::endl; + break; } + break; } else if ( offset > 0 ) { offset /= sizeof(charT); // if offset % sizeof(charT) != 0, rest will be lost! @@ -320,39 +331,22 @@ xev.data.fd = ev.data.fd; info.flags &= ~static_cast<unsigned>(fd_info::level_triggered); if ( epoll_ctl( efd, EPOLL_CTL_MOD, ev.data.fd, &xev ) < 0 ) { - std::cerr << "Y " << ev.data.fd << ", " << errno << std::endl; + // std::cerr << "Y " << ev.data.fd << ", " << errno << std::endl; } } std::tr2::lock_guard<std::tr2::mutex> lk( b->ulck ); b->setg( b->eback(), b->gptr(), b->egptr() + offset ); b->ucnd.notify_one(); if ( info.p != 0 ) { - // std::cerr << "data here" << std::endl; - bool is_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 ) { - is_closed = true; - std::cerr << "@@@ 3\n" << std::endl; - break; - } - } - } - if ( !is_closed ) { - (*info.p)( ev.data.fd ); - } + (*info.p)( ev.data.fd ); } } else { - std::cerr << "K " << ev.data.fd << ", " << errno << 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 break; } } - } else { - std::cerr << "Q\n"; } if ( (ev.events & (EPOLLRDHUP | EPOLLHUP | EPOLLERR) ) != 0 ) { @@ -360,36 +354,15 @@ if ( epoll_ctl( efd, EPOLL_CTL_DEL, ifd->first, 0 ) < 0 ) { // throw system_error } - bool need_delete = true; + if ( info.p != 0 ) { - std::cerr << __FILE__ << ":" << __LINE__ << endl; - { - 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 ) { - need_delete = false; // will be deleted in 'final' method - std::cerr << "@@@ 4\n" << std::endl; - break; - } - } - } - if ( need_delete ) { - std::cerr << __FILE__ << ":" << __LINE__ << " " << (void*)info.b << std::endl; - (*info.p)( ifd->first, typename socks_processor_t::adopt_close_t() ); - std::cerr << __FILE__ << ":" << __LINE__ << " " << (void*)info.b << std::endl; - } + (*info.p)( ifd->first, typename socks_processor_t::adopt_close_t() ); } - if ( (info.flags & fd_info::owner) != 0 && need_delete ) { - std::cerr << __FILE__ << ":" << __LINE__ << " " << (void*)info.b << std::endl; - } else { - std::cerr << __FILE__ << ":" << __LINE__ << " " << (void*)info.b << std::endl; - if ( (info.flags & fd_info::buffer) != 0 ) { - info.b->close(); - } - std::tr2::lock_guard<std::tr2::mutex> lck( cll ); - closed_queue.erase( ev.data.fd ); + if ( (info.flags & fd_info::buffer) != 0 ) { + info.b->close(); } + std::tr2::lock_guard<std::tr2::mutex> lck( cll ); + closed_queue.erase( ev.data.fd ); descr.erase( ifd ); } // if ( ev.events & EPOLLHUP ) { @@ -433,11 +406,12 @@ 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(); ++closed_ifd ) { + // 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 ); - break; + closed_queue.erase( closed_ifd++ ); + } else { + ++closed_ifd; } } } Modified: branches/complement-sockios/explore/include/sockios/sp.h =================================================================== --- branches/complement-sockios/explore/include/sockios/sp.h 2008-06-26 05:43:01 UTC (rev 1907) +++ branches/complement-sockios/explore/include/sockios/sp.h 2008-06-26 05:43:27 UTC (rev 1908) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/11 21:05:35 yeti> +// -*- C++ -*- Time-stamp: <08/06/15 23:21:50 ptr> /* * Copyright (c) 2008 @@ -185,7 +185,6 @@ fd_info info = { fd_info::listener, 0, &p }; std::tr2::lock_guard<std::tr2::mutex> lk( cll ); closed_queue[_fd] = info; - std::cerr << __FILE__ << ":" << __LINE__ << " " << (void*)&p << " " << std::tr2::getpid() << std::endl; } void final( socks_processor_t& p ); @@ -195,7 +194,6 @@ fd_info info = { 0, 0, 0 }; std::tr2::lock_guard<std::tr2::mutex> lk( cll ); closed_queue[fd] = info; - std::cerr << __FILE__ << ":" << __LINE__ << " " << (void*)b << " " << std::tr2::getpid() << std::endl; } private: Modified: branches/complement-sockios/explore/lib/sockios/_sp.cc =================================================================== --- branches/complement-sockios/explore/lib/sockios/_sp.cc 2008-06-26 05:43:01 UTC (rev 1907) +++ branches/complement-sockios/explore/lib/sockios/_sp.cc 2008-06-26 05:43:27 UTC (rev 1908) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/03/06 12:09:33 ptr> +// -*- C++ -*- Time-stamp: <08/06/13 22:59:17 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005-2008 @@ -17,7 +17,7 @@ #include <config/feature.h> #include <cerrno> -#include <sockios/sockstream2> +#include <sockios/sockstream> #ifdef STLPORT _STLP_BEGIN_NAMESPACE 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:01 UTC (rev 1907) +++ branches/complement-sockios/explore/lib/sockios/ut/sockios2_test.cc 2008-06-26 05:43:27 UTC (rev 1908) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/11 21:46:19 yeti> +// -*- C++ -*- Time-stamp: <08/06/15 21:52:52 ptr> /* * @@ -300,7 +300,7 @@ bool rd_counter1() { - return worker::rd == 1; + return worker::rd > 0; // == 1; } int EXAM_IMPL(sockios2_test::processor_core) @@ -311,7 +311,6 @@ EXAM_CHECK( prss.good() ); EXAM_CHECK( prss.is_open() ); - std::cerr << __FILE__ << ":" << __LINE__ << " " << std::tr2::getpid() << std::endl; { sockstream s( "localhost", 2008 ); @@ -329,7 +328,6 @@ EXAM_CHECK( worker::visits == 1 ); worker::visits = 0; } - std::cerr << __FILE__ << ":" << __LINE__ << " " << std::tr2::getpid() << std::endl; } { lock_guard<mutex> lk( worker::lock ); @@ -415,7 +413,7 @@ } unique_lock<mutex> lk( worker::lock ); - worker::cnd.timed_wait( lk, milliseconds( 100 ), rd_counter1 ); + worker::cnd.timed_wait( lk, milliseconds( 500 ), rd_counter1 ); // cerr << worker::line << endl; EXAM_CHECK( worker::line == "Hello, world!" ); @@ -456,8 +454,6 @@ this_thread::fork(); - std::cerr << __FILE__ << ":" << __LINE__ << " " << std::tr2::getpid() << std::endl; - { connect_processor<worker> prss( 2008 ); @@ -474,8 +470,6 @@ EXAM_CHECK_ASYNC( worker::visits == 1 ); } - std::cerr << __FILE__ << ":" << __LINE__ << " " << std::tr2::getpid() << std::endl; - exit( 0 ); } catch ( std::tr2::fork_in_parent& child ) { @@ -626,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 ) { } @@ -645,9 +639,9 @@ 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 pass" << endl; EXAM_CHECK_ASYNC( s.read( (char *)&buff, sizeof(int) ).good() ); // <---- key line EXAM_CHECK_ASYNC( buff == 1 ); @@ -681,12 +675,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. |
From: <com...@us...> - 2008-06-26 05:43:02
|
Revision: 1907 http://complement.svn.sourceforge.net/complement/?rev=1907&view=rev Author: complement Date: 2008-06-25 22:43:01 -0700 (Wed, 25 Jun 2008) Log Message: ----------- sync with STLport for cygwin/mingw Modified Paths: -------------- branches/complement-sockios/explore/Makefiles/gmake/app/gcc.mak branches/complement-sockios/explore/Makefiles/gmake/lib/gcc.mak Modified: branches/complement-sockios/explore/Makefiles/gmake/app/gcc.mak =================================================================== --- branches/complement-sockios/explore/Makefiles/gmake/app/gcc.mak 2008-06-26 05:42:44 UTC (rev 1906) +++ branches/complement-sockios/explore/Makefiles/gmake/app/gcc.mak 2008-06-26 05:43:01 UTC (rev 1907) @@ -1,6 +1,6 @@ -# -*- Makefile -*- Time-stamp: <08/06/12 13:54:55 ptr> +# -*- Makefile -*- Time-stamp: <08/06/12 16:01:09 ptr> # -# Copyright (c) 1997-1999, 2002, 2003, 2005-2007 +# Copyright (c) 1997-1999, 2002, 2003, 2005-2008 # Petr Ovtchenkov # # Portion Copyright (c) 1999-2001 @@ -63,6 +63,7 @@ ifndef WITHOUT_STLPORT ifeq (${STLPORT_LIB_DIR},) +ifneq ($(OSNAME),windows) release-shared: STLPORT_LIB = -lstlport release-static: STLPORT_LIB = -Wl,-Bstatic -lstlport -Wl,-Bdynamic dbg-shared: STLPORT_LIB = -lstlportg @@ -70,20 +71,27 @@ stldbg-shared: STLPORT_LIB = -lstlportstlg stldbg-static: STLPORT_LIB = -Wl,-Bstatic -lstlportstlg -Wl,-Bdynamic else +LIB_VERSION = ${LIBMAJOR}.${LIBMINOR} +release-shared : STLPORT_LIB = -lstlport.${LIB_VERSION} +dbg-shared : STLPORT_LIB = -lstlportg.${LIB_VERSION} +stldbg-shared : STLPORT_LIB = -lstlportstlg.${LIB_VERSION} +endif +else +# STLPORT_LIB_DIR not empty +ifneq ($(OSNAME),windows) release-shared: STLPORT_LIB = -L${STLPORT_LIB_DIR} -lstlport release-static: STLPORT_LIB = -L${STLPORT_LIB_DIR} -Wl,-Bstatic -lstlport -Wl,-Bdynamic dbg-shared: STLPORT_LIB = -L${STLPORT_LIB_DIR} -lstlportg dbg-static: STLPORT_LIB = -L${STLPORT_LIB_DIR} -Wl,-Bstatic -lstlportg -Wl,-Bdynamic stldbg-shared: STLPORT_LIB = -L${STLPORT_LIB_DIR} -lstlportstlg stldbg-static: STLPORT_LIB = -L${STLPORT_LIB_DIR} -Wl,-Bstatic -lstlportstlg -Wl,-Bdynamic -endif - -ifeq ($(OSNAME),windows) +else LIB_VERSION = ${LIBMAJOR}.${LIBMINOR} -release-shared : STLPORT_LIB = -lstlport.${LIB_VERSION} -dbg-shared : STLPORT_LIB = -lstlportg.${LIB_VERSION} -stldbg-shared : STLPORT_LIB = -lstlportstlg.${LIB_VERSION} +release-shared : STLPORT_LIB = -L${STLPORT_LIB_DIR} -lstlport.${LIB_VERSION} +dbg-shared : STLPORT_LIB = -L${STLPORT_LIB_DIR} -lstlportg.${LIB_VERSION} +stldbg-shared : STLPORT_LIB = -L${STLPORT_LIB_DIR} -lstlportstlg.${LIB_VERSION} endif +endif endif Modified: branches/complement-sockios/explore/Makefiles/gmake/lib/gcc.mak =================================================================== --- branches/complement-sockios/explore/Makefiles/gmake/lib/gcc.mak 2008-06-26 05:42:44 UTC (rev 1906) +++ branches/complement-sockios/explore/Makefiles/gmake/lib/gcc.mak 2008-06-26 05:43:01 UTC (rev 1907) @@ -1,4 +1,4 @@ -# -*- makefile -*- Time-stamp: <08/06/12 14:08:48 ptr> +# -*- makefile -*- Time-stamp: <08/06/12 15:44:41 ptr> # # Copyright (c) 1997-1999, 2002, 2003, 2005-2008 # Petr Ovtchenkov @@ -73,21 +73,29 @@ ifndef WITHOUT_STLPORT ifeq (${STLPORT_LIB_DIR},) +ifneq ($(OSNAME),windows) release-shared: STLPORT_LIB = -lstlport dbg-shared: STLPORT_LIB = -lstlportg stldbg-shared: STLPORT_LIB = -lstlportstlg else +LIB_VERSION = ${LIBMAJOR}.${LIBMINOR} +release-shared: STLPORT_LIB = -lstlport.${LIB_VERSION} +dbg-shared: STLPORT_LIB = -lstlportg.${LIB_VERSION} +stldbg-shared: STLPORT_LIB = -lstlportstlg.${LIB_VERSION} +endif +else +# STLPORT_LIB_DIR not empty +ifneq ($(OSNAME),windows) release-shared: STLPORT_LIB = -L${STLPORT_LIB_DIR} -lstlport dbg-shared: STLPORT_LIB = -L${STLPORT_LIB_DIR} -lstlportg stldbg-shared: STLPORT_LIB = -L${STLPORT_LIB_DIR} -lstlportstlg -endif - -ifeq ($(OSNAME),windows) +else LIB_VERSION = ${LIBMAJOR}.${LIBMINOR} -release-shared : STLPORT_LIB = -lstlport.${LIB_VERSION} -dbg-shared : STLPORT_LIB = -lstlportg.${LIB_VERSION} -stldbg-shared : STLPORT_LIB = -lstlportstlg.${LIB_VERSION} +release-shared: STLPORT_LIB = -L${STLPORT_LIB_DIR} -lstlport.${LIB_VERSION} +dbg-shared: STLPORT_LIB = -L${STLPORT_LIB_DIR} -lstlportg.${LIB_VERSION} +stldbg-shared: STLPORT_LIB = -L${STLPORT_LIB_DIR} -lstlportstlg.${LIB_VERSION} endif +endif endif @@ -126,7 +134,7 @@ _LSUPCPP := $(shell ${CXX} ${CXXFLAGS} -print-file-name=libsupc++.a) ifeq (${OSNAME},darwin) ifdef GCC_APPLE_CC -_LSUPCPP := $(shell lipo ${_LSUPCPP} -thin ${M_ARCH} -output $(PRE_OUTPUT_DIR)/libsupc++.a && echo $(PRE_OUTPUT_DIR)/libsupc++.a) +_LSUPCPP := $(shell mkdir -p $(PRE_OUTPUT_DIR) && lipo ${_LSUPCPP} -thin ${M_ARCH} -output $(PRE_OUTPUT_DIR)/libsupc++.a && echo $(PRE_OUTPUT_DIR)/libsupc++.a) endif endif ifneq (${_LSUPCPP},libsupc++.a) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-06-26 05:42:46
|
Revision: 1906 http://complement.svn.sourceforge.net/complement/?rev=1906&view=rev Author: complement Date: 2008-06-25 22:42:44 -0700 (Wed, 25 Jun 2008) Log Message: ----------- Remove LDSEARCH macro; add option for STLport includes in configure Modified Paths: -------------- branches/complement-sockios/explore/Makefiles/gmake/app/gcc.mak branches/complement-sockios/explore/Makefiles/gmake/app/top.mak branches/complement-sockios/explore/Makefiles/gmake/extern.mak branches/complement-sockios/explore/Makefiles/gmake/icc.mak branches/complement-sockios/explore/Makefiles/gmake/lib/CC.mak branches/complement-sockios/explore/Makefiles/gmake/lib/aCC.mak branches/complement-sockios/explore/Makefiles/gmake/lib/gcc.mak branches/complement-sockios/explore/Makefiles/gmake/lib/icc.mak branches/complement-sockios/explore/Makefiles/gmake/lib/vc6.mak branches/complement-sockios/explore/configure branches/complement-sockios/explore/lib/DB/PgSQL/Makefile branches/complement-sockios/explore/lib/exam/ut/Makefile branches/complement-sockios/explore/lib/janus/Makefile branches/complement-sockios/explore/lib/janus/ut/Makefile branches/complement-sockios/explore/lib/misc/ut/Makefile branches/complement-sockios/explore/lib/mt/ut/Makefile branches/complement-sockios/explore/lib/net/samples/httpclient/Makefile branches/complement-sockios/explore/lib/net/ut/Makefile branches/complement-sockios/explore/lib/sockios/perf/Makefile branches/complement-sockios/explore/lib/sockios/ut/Makefile branches/complement-sockios/explore/lib/stem/ut/Makefile branches/complement-sockios/explore/lib/stem/ut/dl/Makefile Removed Paths: ------------- branches/complement-sockios/explore/lib/mt/Makefile.mwccnlm branches/complement-sockios/explore/lib/mt/gcc-libstd.mak branches/complement-sockios/explore/lib/mt/mwccnlm.mak branches/complement-sockios/explore/lib/mt/ut/gcc-libstd.mak Modified: branches/complement-sockios/explore/Makefiles/gmake/app/gcc.mak =================================================================== --- branches/complement-sockios/explore/Makefiles/gmake/app/gcc.mak 2008-06-26 05:41:25 UTC (rev 1905) +++ branches/complement-sockios/explore/Makefiles/gmake/app/gcc.mak 2008-06-26 05:42:44 UTC (rev 1906) @@ -1,4 +1,4 @@ -# -*- Makefile -*- Time-stamp: <07/05/30 23:54:39 ptr> +# -*- Makefile -*- Time-stamp: <08/06/12 13:54:55 ptr> # # Copyright (c) 1997-1999, 2002, 2003, 2005-2007 # Petr Ovtchenkov @@ -62,14 +62,21 @@ endif ifndef WITHOUT_STLPORT -LDSEARCH += -L${STLPORT_LIB_DIR} - +ifeq (${STLPORT_LIB_DIR},) release-shared: STLPORT_LIB = -lstlport release-static: STLPORT_LIB = -Wl,-Bstatic -lstlport -Wl,-Bdynamic dbg-shared: STLPORT_LIB = -lstlportg dbg-static: STLPORT_LIB = -Wl,-Bstatic -lstlportg -Wl,-Bdynamic stldbg-shared: STLPORT_LIB = -lstlportstlg stldbg-static: STLPORT_LIB = -Wl,-Bstatic -lstlportstlg -Wl,-Bdynamic +else +release-shared: STLPORT_LIB = -L${STLPORT_LIB_DIR} -lstlport +release-static: STLPORT_LIB = -L${STLPORT_LIB_DIR} -Wl,-Bstatic -lstlport -Wl,-Bdynamic +dbg-shared: STLPORT_LIB = -L${STLPORT_LIB_DIR} -lstlportg +dbg-static: STLPORT_LIB = -L${STLPORT_LIB_DIR} -Wl,-Bstatic -lstlportg -Wl,-Bdynamic +stldbg-shared: STLPORT_LIB = -L${STLPORT_LIB_DIR} -lstlportstlg +stldbg-static: STLPORT_LIB = -L${STLPORT_LIB_DIR} -Wl,-Bstatic -lstlportstlg -Wl,-Bdynamic +endif ifeq ($(OSNAME),windows) LIB_VERSION = ${LIBMAJOR}.${LIBMINOR} Modified: branches/complement-sockios/explore/Makefiles/gmake/app/top.mak =================================================================== --- branches/complement-sockios/explore/Makefiles/gmake/app/top.mak 2008-06-26 05:41:25 UTC (rev 1905) +++ branches/complement-sockios/explore/Makefiles/gmake/app/top.mak 2008-06-26 05:42:44 UTC (rev 1906) @@ -1,6 +1,6 @@ -# -*- makefile -*- Time-stamp: <07/06/08 23:35:09 ptr> +# -*- makefile -*- Time-stamp: <08/06/12 13:55:47 ptr> # -# Copyright (c) 1997-1999, 2002, 2003, 2005-2007 +# Copyright (c) 1997-1999, 2002, 2003, 2005-2008 # Petr Ovtchenkov # # Portion Copyright (c) 1999-2001 @@ -31,8 +31,6 @@ $(foreach prg,$(PRGNAMES),$(eval $(call prog_prog,$(prg)))) -LDFLAGS += ${LDSEARCH} - include ${RULESBASE}/gmake/app/${COMPILER_NAME}.mak include ${RULESBASE}/gmake/app/rules.mak include ${RULESBASE}/gmake/app/rules-install.mak Modified: branches/complement-sockios/explore/Makefiles/gmake/extern.mak =================================================================== --- branches/complement-sockios/explore/Makefiles/gmake/extern.mak 2008-06-26 05:41:25 UTC (rev 1905) +++ branches/complement-sockios/explore/Makefiles/gmake/extern.mak 2008-06-26 05:42:44 UTC (rev 1906) @@ -31,10 +31,12 @@ # STLport library ifndef STLPORT_DIR +ifndef STLPORT_INCLUDE_DIR ifndef WITHOUT_STLPORT WITHOUT_STLPORT = 1 endif endif +endif ifdef STLPORT_DIR STLPORT_LIB_DIR ?= $(STLPORT_DIR)/${TARGET_NAME}lib Modified: branches/complement-sockios/explore/Makefiles/gmake/icc.mak =================================================================== --- branches/complement-sockios/explore/Makefiles/gmake/icc.mak 2008-06-26 05:41:25 UTC (rev 1905) +++ branches/complement-sockios/explore/Makefiles/gmake/icc.mak 2008-06-26 05:42:44 UTC (rev 1906) @@ -1,6 +1,6 @@ -# Time-stamp: <07/03/08 21:41:21 ptr> +# Time-stamp: <08/06/12 14:57:58 ptr> # -# Copyright (c) 1997-1999, 2002, 2003, 2005-2007 +# Copyright (c) 1997-1999, 2002, 2003, 2005-2008 # Petr Ovtchenkov # # Portion Copyright (c) 1999-2001 Modified: branches/complement-sockios/explore/Makefiles/gmake/lib/CC.mak =================================================================== --- branches/complement-sockios/explore/Makefiles/gmake/lib/CC.mak 2008-06-26 05:41:25 UTC (rev 1905) +++ branches/complement-sockios/explore/Makefiles/gmake/lib/CC.mak 2008-06-26 05:42:44 UTC (rev 1906) @@ -1,6 +1,6 @@ -# -*- makefile -*- Time-stamp: <07/03/08 21:39:22 ptr> +# -*- makefile -*- Time-stamp: <08/06/12 14:58:49 ptr> # -# Copyright (c) 1997-1999, 2002, 2003, 2005-2007 +# Copyright (c) 1997-1999, 2002, 2003, 2005-2008 # Petr Ovtchenkov # # Portion Copyright (c) 1999-2001 @@ -11,12 +11,9 @@ OPT += -xcode=pic32 -dbg-shared: LDFLAGS += -G -Qoption ld -z,initfirst -h$(SO_NAME_DBGxx) ${LDSEARCH} ${NOSTDLIB} -stldbg-shared: LDFLAGS += -G -Qoption ld -z,initfirst -h$(SO_NAME_STLDBGxx) ${LDSEARCH} ${NOSTDLIB} -release-shared: LDFLAGS += -G -Qoption ld -z,initfirst -h$(SO_NAMExx) ${LDSEARCH} ${NOSTDLIB} -dbg-static: LDFLAGS += ${LDSEARCH} -stldbg-static: LDFLAGS += ${LDSEARCH} -release-static: LDFLAGS += ${LDSEARCH} +dbg-shared: LDFLAGS += -G -Qoption ld -z,initfirst -h$(SO_NAME_DBGxx) ${NOSTDLIB} +stldbg-shared: LDFLAGS += -G -Qoption ld -z,initfirst -h$(SO_NAME_STLDBGxx) ${NOSTDLIB} +release-shared: LDFLAGS += -G -Qoption ld -z,initfirst -h$(SO_NAMExx) ${NOSTDLIB} DEPENDS_COLLECTION_SUNPRO := $(DEPENDS_COLLECTION).sunpro Modified: branches/complement-sockios/explore/Makefiles/gmake/lib/aCC.mak =================================================================== --- branches/complement-sockios/explore/Makefiles/gmake/lib/aCC.mak 2008-06-26 05:41:25 UTC (rev 1905) +++ branches/complement-sockios/explore/Makefiles/gmake/lib/aCC.mak 2008-06-26 05:42:44 UTC (rev 1906) @@ -1,6 +1,6 @@ -# -*- makefile -*- Time-stamp: <07/05/31 00:50:40 ptr> +# -*- makefile -*- Time-stamp: <08/06/12 14:59:23 ptr> # -# Copyright (c) 1997-1999, 2002, 2003, 2005-2007 +# Copyright (c) 1997-1999, 2002, 2003, 2005-2008 # Petr Ovtchenkov # # Portion Copyright (c) 1999-2001 @@ -9,6 +9,6 @@ # Licensed under the Academic Free License version 3.0 # -dbg-shared: LDFLAGS += -b +nostl -Wl,+h$(SO_NAME_DBGxx) ${LDSEARCH} -stldbg-shared: LDFLAGS += -b +nostl -Wl,+h$(SO_NAME_STLDBGxx) ${LDSEARCH} -release-shared: LDFLAGS += -b +nostl -Wl,+h$(SO_NAMExx) ${LDSEARCH} +dbg-shared: LDFLAGS += -b +nostl -Wl,+h$(SO_NAME_DBGxx) +stldbg-shared: LDFLAGS += -b +nostl -Wl,+h$(SO_NAME_STLDBGxx) +release-shared: LDFLAGS += -b +nostl -Wl,+h$(SO_NAMExx) Modified: branches/complement-sockios/explore/Makefiles/gmake/lib/gcc.mak =================================================================== --- branches/complement-sockios/explore/Makefiles/gmake/lib/gcc.mak 2008-06-26 05:41:25 UTC (rev 1905) +++ branches/complement-sockios/explore/Makefiles/gmake/lib/gcc.mak 2008-06-26 05:42:44 UTC (rev 1906) @@ -1,6 +1,6 @@ -# -*- makefile -*- Time-stamp: <07/05/31 00:55:13 ptr> +# -*- makefile -*- Time-stamp: <08/06/12 14:08:48 ptr> # -# Copyright (c) 1997-1999, 2002, 2003, 2005-2007 +# Copyright (c) 1997-1999, 2002, 2003, 2005-2008 # Petr Ovtchenkov # # Portion Copyright (c) 1999-2001 @@ -71,11 +71,16 @@ endif ifndef WITHOUT_STLPORT -LDSEARCH += -L${STLPORT_LIB_DIR} +ifeq (${STLPORT_LIB_DIR},) release-shared: STLPORT_LIB = -lstlport dbg-shared: STLPORT_LIB = -lstlportg stldbg-shared: STLPORT_LIB = -lstlportstlg +else +release-shared: STLPORT_LIB = -L${STLPORT_LIB_DIR} -lstlport +dbg-shared: STLPORT_LIB = -L${STLPORT_LIB_DIR} -lstlportg +stldbg-shared: STLPORT_LIB = -L${STLPORT_LIB_DIR} -lstlportstlg +endif ifeq ($(OSNAME),windows) LIB_VERSION = ${LIBMAJOR}.${LIBMINOR} @@ -196,64 +201,52 @@ endif ifeq ($(OSNAME),hp-ux) -dbg-shared: LDFLAGS += -shared -Wl,-dynamic -Wl,+h$(SO_NAME_DBGxx) ${LDSEARCH} -stldbg-shared: LDFLAGS += -shared -Wl,-dynamic -Wl,+h$(SO_NAME_STLDBGxx) ${LDSEARCH} -release-shared: LDFLAGS += -shared -Wl,-dynamic -Wl,+h$(SO_NAMExx) ${LDSEARCH} +dbg-shared: LDFLAGS += -shared -Wl,-dynamic -Wl,+h$(SO_NAME_DBGxx) +stldbg-shared: LDFLAGS += -shared -Wl,-dynamic -Wl,+h$(SO_NAME_STLDBGxx) +release-shared: LDFLAGS += -shared -Wl,-dynamic -Wl,+h$(SO_NAMExx) endif ifeq ($(OSNAME),sunos) -dbg-shared: LDFLAGS += -shared -Wl,-h$(SO_NAME_DBGxx) ${NOSTDLIB} ${LDSEARCH} -stldbg-shared: LDFLAGS += -shared -Wl,-h$(SO_NAME_STLDBGxx) ${NOSTDLIB} ${LDSEARCH} -release-shared: LDFLAGS += -shared -Wl,-h$(SO_NAMExx) ${NOSTDLIB} ${LDSEARCH} -dbg-static: LDFLAGS += ${LDSEARCH} -stldbg-static: LDFLAGS += ${LDSEARCH} -release-static: LDFLAGS += ${LDSEARCH} +dbg-shared: LDFLAGS += -shared -Wl,-h$(SO_NAME_DBGxx) ${NOSTDLIB} +stldbg-shared: LDFLAGS += -shared -Wl,-h$(SO_NAME_STLDBGxx) ${NOSTDLIB} +release-shared: LDFLAGS += -shared -Wl,-h$(SO_NAMExx) ${NOSTDLIB} endif ifeq ($(OSNAME),linux) -dbg-shared: LDFLAGS += -shared -Wl,-h$(SO_NAME_DBGxx) ${NOSTDLIB} ${LDSEARCH} -stldbg-shared: LDFLAGS += -shared -Wl,-h$(SO_NAME_STLDBGxx) ${NOSTDLIB} ${LDSEARCH} -release-shared: LDFLAGS += -shared -Wl,-h$(SO_NAMExx) ${NOSTDLIB} ${LDSEARCH} -dbg-static: LDFLAGS += ${LDSEARCH} -stldbg-static: LDFLAGS += ${LDSEARCH} -release-static: LDFLAGS += ${LDSEARCH} +dbg-shared: LDFLAGS += -shared -Wl,-h$(SO_NAME_DBGxx) ${NOSTDLIB} +stldbg-shared: LDFLAGS += -shared -Wl,-h$(SO_NAME_STLDBGxx) ${NOSTDLIB} +release-shared: LDFLAGS += -shared -Wl,-h$(SO_NAMExx) ${NOSTDLIB} endif ifeq ($(OSNAME),windows) dbg-shared: LDFLAGS += -shared -Wl,--out-implib=${LIB_NAME_OUT_DBG},--enable-auto-image-base stldbg-shared: LDFLAGS += -shared -Wl,--out-implib=${LIB_NAME_OUT_STLDBG},--enable-auto-image-base release-shared: LDFLAGS += -shared -Wl,--out-implib=${LIB_NAME_OUT},--enable-auto-image-base -dbg-static: LDFLAGS += -static ${LDSEARCH} -stldbg-static: LDFLAGS += -static ${LDSEARCH} -release-static: LDFLAGS += -static ${LDSEARCH} +dbg-static: LDFLAGS += -static +stldbg-static: LDFLAGS += -static +release-static: LDFLAGS += -static endif ifeq ($(OSNAME),freebsd) -dbg-shared: LDFLAGS += -shared -Wl,-h$(SO_NAME_DBGxx) ${NOSTDLIB} ${LDSEARCH} -stldbg-shared: LDFLAGS += -shared -Wl,-h$(SO_NAME_STLDBGxx) ${NOSTDLIB} ${LDSEARCH} -release-shared: LDFLAGS += -shared -Wl,-h$(SO_NAMExx) ${NOSTDLIB} ${LDSEARCH} -dbg-static: LDFLAGS += ${LDSEARCH} -stldbg-static: LDFLAGS += ${LDSEARCH} -release-static: LDFLAGS += ${LDSEARCH} +dbg-shared: LDFLAGS += -shared -Wl,-h$(SO_NAME_DBGxx) ${NOSTDLIB} +stldbg-shared: LDFLAGS += -shared -Wl,-h$(SO_NAME_STLDBGxx) ${NOSTDLIB} +release-shared: LDFLAGS += -shared -Wl,-h$(SO_NAMExx) ${NOSTDLIB} endif ifeq ($(OSNAME),darwin) CURRENT_VERSION := ${MAJOR}.${MINOR}.${PATCH} COMPATIBILITY_VERSION := $(CURRENT_VERSION) -dbg-shared: LDFLAGS += -dynamic -dynamiclib -compatibility_version $(COMPATIBILITY_VERSION) -current_version $(CURRENT_VERSION) -install_name $(SO_NAME_DBGxx) ${LDSEARCH} ${NOSTDLIB} -stldbg-shared: LDFLAGS += -dynamic -dynamiclib -compatibility_version $(COMPATIBILITY_VERSION) -current_version $(CURRENT_VERSION) -install_name $(SO_NAME_STLDBGxx) ${LDSEARCH} ${NOSTDLIB} -release-shared: LDFLAGS += -dynamic -dynamiclib -compatibility_version $(COMPATIBILITY_VERSION) -current_version $(CURRENT_VERSION) -install_name $(SO_NAMExx) ${LDSEARCH} ${NOSTDLIB} -dbg-static: LDFLAGS += -staticlib ${LDSEARCH} -stldbg-static: LDFLAGS += -staticlib ${LDSEARCH} -release-static: LDFLAGS += -staticlib ${LDSEARCH} +dbg-shared: LDFLAGS += -dynamic -dynamiclib -compatibility_version $(COMPATIBILITY_VERSION) -current_version $(CURRENT_VERSION) -install_name $(SO_NAME_DBGxx) ${NOSTDLIB} +stldbg-shared: LDFLAGS += -dynamic -dynamiclib -compatibility_version $(COMPATIBILITY_VERSION) -current_version $(CURRENT_VERSION) -install_name $(SO_NAME_STLDBGxx) ${NOSTDLIB} +release-shared: LDFLAGS += -dynamic -dynamiclib -compatibility_version $(COMPATIBILITY_VERSION) -current_version $(CURRENT_VERSION) -install_name $(SO_NAMExx) ${NOSTDLIB} +dbg-static: LDFLAGS += -staticlib +stldbg-static: LDFLAGS += -staticlib +release-static: LDFLAGS += -staticlib endif ifeq ($(OSNAME),openbsd) -dbg-shared: LDFLAGS += -shared -Wl,-soname -Wl,$(SO_NAME_DBGxx) ${NOSTDLIB} ${LDSEARCH} -stldbg-shared: LDFLAGS += -shared -Wl,-soname -Wl,$(SO_NAME_STLDBGxx) ${NOSTDLIB} ${LDSEARCH} -release-shared: LDFLAGS += -shared -Wl,-soname -Wl,$(SO_NAMExx) ${NOSTDLIB} ${LDSEARCH} -dbg-static: LDFLAGS += ${LDSEARCH} -stldbg-static: LDFLAGS += ${LDSEARCH} -release-static: LDFLAGS += ${LDSEARCH} +dbg-shared: LDFLAGS += -shared -Wl,-soname -Wl,$(SO_NAME_DBGxx) ${NOSTDLIB} +stldbg-shared: LDFLAGS += -shared -Wl,-soname -Wl,$(SO_NAME_STLDBGxx) ${NOSTDLIB} +release-shared: LDFLAGS += -shared -Wl,-soname -Wl,$(SO_NAMExx) ${NOSTDLIB} endif Modified: branches/complement-sockios/explore/Makefiles/gmake/lib/icc.mak =================================================================== --- branches/complement-sockios/explore/Makefiles/gmake/lib/icc.mak 2008-06-26 05:41:25 UTC (rev 1905) +++ branches/complement-sockios/explore/Makefiles/gmake/lib/icc.mak 2008-06-26 05:42:44 UTC (rev 1906) @@ -1,6 +1,6 @@ -# -*- makefile -*- Time-stamp: <07/03/08 21:37:08 ptr> +# -*- makefile -*- Time-stamp: <08/06/12 15:00:07 ptr> # -# Copyright (c) 1997-1999, 2002, 2003, 2005-2007 +# Copyright (c) 1997-1999, 2002, 2003, 2005-2008 # Petr Ovtchenkov # # Portion Copyright (c) 1999-2001 @@ -9,19 +9,11 @@ # Licensed under the Academic Free License version 3.0 # -# Oh, the commented below work for gmake 3.78.1 and above, -# but phrase without tag not work for it. Since gmake 3.79 -# tag with assignment fail, but work assignment for all tags -# (really that more correct). - OPT += -KPIC ifeq ($(OSNAME),linux) -dbg-shared: LDFLAGS += -shared -Wl,-h$(SO_NAME_DBGxx) ${LDSEARCH} -stldbg-shared: LDFLAGS += -shared -Wl,-h$(SO_NAME_STLDBGxx) ${LDSEARCH} -release-shared: LDFLAGS += -shared -Wl,-h$(SO_NAMExx) ${LDSEARCH} -dbg-static: LDFLAGS += ${LDSEARCH} -stldbg-static: LDFLAGS += ${LDSEARCH} -release-static: LDFLAGS += ${LDSEARCH} +dbg-shared: LDFLAGS += -shared -Wl,-h$(SO_NAME_DBGxx) +stldbg-shared: LDFLAGS += -shared -Wl,-h$(SO_NAME_STLDBGxx) +release-shared: LDFLAGS += -shared -Wl,-h$(SO_NAMExx) endif Modified: branches/complement-sockios/explore/Makefiles/gmake/lib/vc6.mak =================================================================== --- branches/complement-sockios/explore/Makefiles/gmake/lib/vc6.mak 2008-06-26 05:41:25 UTC (rev 1905) +++ branches/complement-sockios/explore/Makefiles/gmake/lib/vc6.mak 2008-06-26 05:42:44 UTC (rev 1906) @@ -1,6 +1,6 @@ -# -*- makefile -*- Time-stamp: <07/03/08 21:35:57 ptr> +# -*- makefile -*- Time-stamp: <08/06/12 15:03:15 ptr> # -# Copyright (c) 1997-1999, 2002, 2003, 2005-2007 +# Copyright (c) 1997-1999, 2002, 2003, 2005-2008 # Petr Ovtchenkov # # Portion Copyright (c) 1999-2001 @@ -9,13 +9,7 @@ # Licensed under the Academic Free License version 3.0 # -# Oh, the commented below work for gmake 3.78.1 and above, -# but phrase without tag not work for it. Since gmake 3.79 -# tag with assignment fail, but work assignment for all tags -# (really that more correct). - LDLIBS ?= -LDSEARCH += /LIBPATH:"$(MSVC_LIB_DIR)" dbg-shared: OPT += /MDd stldbg-shared: OPT += /MDd @@ -30,11 +24,8 @@ stldbg-static: DEFS += /D_LIB -dbg-shared: LDFLAGS += /DLL ${LDSEARCH} -stldbg-shared: LDFLAGS += /DLL ${LDSEARCH} -release-shared: LDFLAGS += /DLL ${LDSEARCH} -dbg-static: LDFLAGS += ${LDSEARCH} -stldbg-static: LDFLAGS += ${LDSEARCH} -release-static: LDFLAGS += ${LDSEARCH} +dbg-shared: LDFLAGS += /DLL +stldbg-shared: LDFLAGS += /DLL +release-shared: LDFLAGS += /DLL -LDFLAGS += /VERSION:$(MAJOR).$(MINOR) +LDFLAGS += /LIBPATH:"$(MSVC_LIB_DIR)" /VERSION:$(MAJOR).$(MINOR) Modified: branches/complement-sockios/explore/configure =================================================================== --- branches/complement-sockios/explore/configure 2008-06-26 05:41:25 UTC (rev 1905) +++ branches/complement-sockios/explore/configure 2008-06-26 05:42:44 UTC (rev 1906) @@ -40,6 +40,7 @@ --help print this help message and exit --with-stlport=<dir> use STLport in catalog <dir> + --with-stlport-headers=<dir> use STLport headers in catalog <dir> --without-stlport compile without STLport (default) --with-boost=<dir> use boost headers in catalog <dir> --with-system-boost use boost installed on this system @@ -82,6 +83,7 @@ } default_settings () { + : # if [ "$boost_set" = "" ]; then # write_option "${PWD}/external/boost" BOOST_DIR # fi @@ -140,6 +142,10 @@ write_option "$option" STLPORT_DIR stlport_set=y ;; + --with-stlport-headers=*) + write_option "$option" STLPORT_INCLUDE_DIR + stlport_set=y + ;; --without-stlport) write_option "1" WITHOUT_STLPORT stlport_set=y Modified: branches/complement-sockios/explore/lib/DB/PgSQL/Makefile =================================================================== --- branches/complement-sockios/explore/lib/DB/PgSQL/Makefile 2008-06-26 05:41:25 UTC (rev 1905) +++ branches/complement-sockios/explore/lib/DB/PgSQL/Makefile 2008-06-26 05:42:44 UTC (rev 1906) @@ -1,14 +1,21 @@ -# -*- Makefile -*- Time-stamp: <03/09/25 12:02:31 ptr> +# -*- Makefile -*- Time-stamp: <08/06/12 15:09:05 ptr> SRCROOT := ../../.. -PG_INCLUDE := /opt/pgsql/include -PG_LIB := /opt/pgsql/lib +# PG_INCLUDE := /opt/pgsql/include +# PG_LIB_DIR := /opt/pgsql/lib include Makefile.inc include ${SRCROOT}/Makefiles/gmake/top.mak -INCLUDES += -I$(SRCROOT)/include -I${PG_INCLUDE} +INCLUDES += -I$(SRCROOT)/include -LDSEARCH += -L${PG_LIB} +ifneq (${PG_INCLUDE},) +INCLUDES += -I${PG_INCLUDE} +endif + +ifneq (${PG_LIB_DIR},) +LDFLAGS += -L${PG_LIB_DIR} +endif + LDLIBS = -lpq Modified: branches/complement-sockios/explore/lib/exam/ut/Makefile =================================================================== --- branches/complement-sockios/explore/lib/exam/ut/Makefile 2008-06-26 05:41:25 UTC (rev 1905) +++ branches/complement-sockios/explore/lib/exam/ut/Makefile 2008-06-26 05:42:44 UTC (rev 1906) @@ -1,4 +1,4 @@ -# -*- Makefile -*- Time-stamp: <07/09/03 22:27:45 ptr> +# -*- Makefile -*- Time-stamp: <08/06/12 14:00:05 ptr> SRCROOT := ../../.. @@ -15,12 +15,12 @@ ifeq ($(OSNAME),linux) -release-shared: LDSEARCH += -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L$(LIBXMT_DIR)/${OUTPUT_DIR} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR}:$(LIBXMT_DIR)/${OUTPUT_DIR}:${STLPORT_LIB_DIR} +release-shared: LDFLAGS += -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L$(LIBXMT_DIR)/${OUTPUT_DIR} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR}:$(LIBXMT_DIR)/${OUTPUT_DIR}:${STLPORT_LIB_DIR} -dbg-shared: LDSEARCH += -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L$(LIBXMT_DIR)/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:$(LIBXMT_DIR)/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} +dbg-shared: LDFLAGS += -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L$(LIBXMT_DIR)/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:$(LIBXMT_DIR)/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} ifndef WITHOUT_STLPORT -stldbg-shared: LDSEARCH += -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L$(LIBXMT_DIR)/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:$(LIBXMT_DIR)/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} +stldbg-shared: LDFLAGS += -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L$(LIBXMT_DIR)/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:$(LIBXMT_DIR)/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} endif endif Modified: branches/complement-sockios/explore/lib/janus/Makefile =================================================================== --- branches/complement-sockios/explore/lib/janus/Makefile 2008-06-26 05:41:25 UTC (rev 1905) +++ branches/complement-sockios/explore/lib/janus/Makefile 2008-06-26 05:42:44 UTC (rev 1906) @@ -1,4 +1,4 @@ -# -*- Makefile -*- Time-stamp: <07/02/07 12:28:46 ptr> +# -*- Makefile -*- Time-stamp: <08/06/12 15:26:16 ptr> SRCROOT := ../.. COMPILER_NAME := gcc @@ -12,7 +12,7 @@ LIBSOCK_DIR = ${CoMT_DIR}/lib/sockios LIBSTEM_DIR = ${CoMT_DIR}/lib/stem -LDSEARCH += -L${CoMT_LIB_DIR} -Wl,--rpath=${CoMT_LIB_DIR} +LDFLAGS += -L${CoMT_LIB_DIR} -Wl,--rpath=${CoMT_LIB_DIR} release-shared : LDLIBS = -lxmt -lsockios -lstem ifndef WITHOUT_STLPORT Modified: branches/complement-sockios/explore/lib/janus/ut/Makefile =================================================================== --- branches/complement-sockios/explore/lib/janus/ut/Makefile 2008-06-26 05:41:25 UTC (rev 1905) +++ branches/complement-sockios/explore/lib/janus/ut/Makefile 2008-06-26 05:42:44 UTC (rev 1906) @@ -1,4 +1,4 @@ -# -*- Makefile -*- Time-stamp: <07/08/08 22:18:48 ptr> +# -*- Makefile -*- Time-stamp: <08/06/12 15:26:38 ptr> SRCROOT := ../../.. COMPILER_NAME := gcc @@ -20,12 +20,12 @@ ifeq ($(OSNAME),linux) -release-shared: LDSEARCH += -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L$(LIBXMT_DIR)/${OUTPUT_DIR} -L$(LIBSOCKIOS_DIR)/${OUTPUT_DIR} -L$(LIBSTEM_DIR)/${OUTPUT_DIR} -L$(LIBJANUS_DIR)/${OUTPUT_DIR} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR}:$(LIBXMT_DIR)/${OUTPUT_DIR}:${LIBSOCKIOS_DIR}/${OUTPUT_DIR}:${LIBSTEM_DIR}/${OUTPUT_DIR}:${LIBJANUS_DIR}${OUTPUT_DIR}:${STLPORT_LIB_DIR} +release-shared: LDFLAGS += -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L$(LIBXMT_DIR)/${OUTPUT_DIR} -L$(LIBSOCKIOS_DIR)/${OUTPUT_DIR} -L$(LIBSTEM_DIR)/${OUTPUT_DIR} -L$(LIBJANUS_DIR)/${OUTPUT_DIR} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR}:$(LIBXMT_DIR)/${OUTPUT_DIR}:${LIBSOCKIOS_DIR}/${OUTPUT_DIR}:${LIBSTEM_DIR}/${OUTPUT_DIR}:${LIBJANUS_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} -dbg-shared: LDSEARCH += -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L$(LIBXMT_DIR)/${OUTPUT_DIR_DBG} -L$(LIBSOCKIOS_DIR)/${OUTPUT_DIR_DBG} -L$(LIBSTEM_DIR)/${OUTPUT_DIR_DBG} -L$(LIBJANUS_DIR)/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:$(LIBXMT_DIR)/${OUTPUT_DIR_DBG}:${LIBSOCKIOS_DIR}/${OUTPUT_DIR_DBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_DBG}:${LIBJANUS_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} +dbg-shared: LDFLAGS += -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L$(LIBXMT_DIR)/${OUTPUT_DIR_DBG} -L$(LIBSOCKIOS_DIR)/${OUTPUT_DIR_DBG} -L$(LIBSTEM_DIR)/${OUTPUT_DIR_DBG} -L$(LIBJANUS_DIR)/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:$(LIBXMT_DIR)/${OUTPUT_DIR_DBG}:${LIBSOCKIOS_DIR}/${OUTPUT_DIR_DBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_DBG}:${LIBJANUS_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} ifndef WITHOUT_STLPORT -stldbg-shared: LDSEARCH += -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L$(LIBXMT_DIR)/${OUTPUT_DIR_STLDBG} -L$(LIBSOCKIOS_DIR)/${OUTPUT_DIR_STLDBG} -L$(LIBSTEM_DIR)/${OUTPUT_DIR_STLDBG} -L$(LIBJANUS_DIR)/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:$(LIBXMT_DIR)/${OUTPUT_DIR_STLDBG}:${LIBSOCKIOS_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBJANUS_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} +stldbg-shared: LDFLAGS += -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L$(LIBXMT_DIR)/${OUTPUT_DIR_STLDBG} -L$(LIBSOCKIOS_DIR)/${OUTPUT_DIR_STLDBG} -L$(LIBSTEM_DIR)/${OUTPUT_DIR_STLDBG} -L$(LIBJANUS_DIR)/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:$(LIBXMT_DIR)/${OUTPUT_DIR_STLDBG}:${LIBSOCKIOS_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBJANUS_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} endif endif Modified: branches/complement-sockios/explore/lib/misc/ut/Makefile =================================================================== --- branches/complement-sockios/explore/lib/misc/ut/Makefile 2008-06-26 05:41:25 UTC (rev 1905) +++ branches/complement-sockios/explore/lib/misc/ut/Makefile 2008-06-26 05:42:44 UTC (rev 1906) @@ -1,4 +1,4 @@ -# -*- Makefile -*- Time-stamp: <07/11/23 23:30:57 ptr> +# -*- Makefile -*- Time-stamp: <08/06/12 15:20:10 ptr> SRCROOT := ../../.. @@ -14,24 +14,22 @@ ifeq ($(OSNAME),linux) -release-shared: LDSEARCH += -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L${LIBXMT_DIR}/${OUTPUT_DIR} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR}:${LIBXMT_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} +release-shared: LDFLAGS += -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L${LIBXMT_DIR}/${OUTPUT_DIR} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR}:${LIBXMT_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} -dbg-shared: LDSEARCH += -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L${LIBXMT_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:${LIBXMT_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} +dbg-shared: LDFLAGS += -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L${LIBXMT_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:${LIBXMT_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} ifndef WITHOUT_STLPORT -stldbg-shared: LDSEARCH += -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBXMT_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBXMT_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} +stldbg-shared: LDFLAGS += -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBXMT_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBXMT_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} endif endif ifeq ($(OSNAME),openbsd) -release-shared: LDSEARCH += -Wl,-R:${STLPORT_LIB_DIR} - -dbg-shared: LDSEARCH += -Wl,-R:${STLPORT_LIB_DIR} - ifndef WITHOUT_STLPORT -stldbg-shared: LDSEARCH += -Wl,-R:${STLPORT_LIB_DIR} +release-shared: LDFLAGS += -Wl,-R:${STLPORT_LIB_DIR} +dbg-shared: LDFLAGS += -Wl,-R:${STLPORT_LIB_DIR} +stldbg-shared: LDFLAGS += -Wl,-R:${STLPORT_LIB_DIR} endif endif Deleted: branches/complement-sockios/explore/lib/mt/Makefile.mwccnlm =================================================================== --- branches/complement-sockios/explore/lib/mt/Makefile.mwccnlm 2008-06-26 05:41:25 UTC (rev 1905) +++ branches/complement-sockios/explore/lib/mt/Makefile.mwccnlm 2008-06-26 05:42:44 UTC (rev 1906) @@ -1,32 +0,0 @@ -# -*- Makefile -*- Time-stamp: <03/06/13 16:51:25 ptr> -# $Id$ - -BASEDIR := $(shell xtmp=`pwd`; xtmp=`dirname $$xtmp`; dirname $$xtmp) -LIBDIR := $(shell xtmp=`pwd`; dirname $$xtmp) - -COMPILER_NAME = mwccnlm -include $(BASEDIR)/lib/mt/Makefile.inc - -all: all-release all-debug - -install: install-dbg-shared install-stldbg-shared install-release-shared - -all-shared: release-shared dbg-shared stldbg-shared - -all-debug: dbg-shared stldbg-shared - -all-release: release-shared - -include ${BASEDIR}/Makefiles/lib/Makefile.inc - -INCLUDES += -I$(STLPORT_INCLUDE_DIR) -I../../include - -release-shared: LDSEARCH = -L${STLPORT_LIB_DIR} -stldbg-shared: LDSEARCH = -L${STLPORT_LIB_DIR} -dbg-shared: LDSEARCH = -L${STLPORT_LIB_DIR} - -release-shared : LDLIBS = -lstlport_gcc -stldbg-shared : LDLIBS = -lstlport_gcc_stldebug -dbg-shared : LDLIBS = -lstlport_gcc - - Deleted: branches/complement-sockios/explore/lib/mt/gcc-libstd.mak =================================================================== --- branches/complement-sockios/explore/lib/mt/gcc-libstd.mak 2008-06-26 05:41:25 UTC (rev 1905) +++ branches/complement-sockios/explore/lib/mt/gcc-libstd.mak 2008-06-26 05:42:44 UTC (rev 1906) @@ -1,13 +0,0 @@ -# -*- Makefile -*- Time-stamp: <03/09/25 12:02:31 ptr> -# $Id$ - -SRCROOT := ../.. -COMPILER_NAME := gcc - -ALL_TAGS = release-shared dbg-shared - -include Makefile.inc -include ${SRCROOT}/Makefiles/top.mak - -INCLUDES += -I$(SRCROOT)/include - Deleted: branches/complement-sockios/explore/lib/mt/mwccnlm.mak =================================================================== --- branches/complement-sockios/explore/lib/mt/mwccnlm.mak 2008-06-26 05:41:25 UTC (rev 1905) +++ branches/complement-sockios/explore/lib/mt/mwccnlm.mak 2008-06-26 05:42:44 UTC (rev 1906) @@ -1,11 +0,0 @@ -# -*- Makefile -*- Time-stamp: <05/06/03 21:45:55 ptr> -# $Id$ - -SRCROOT := ../.. -COMPILER_NAME := mwccnlm - -STLPORT_DIR := ../../../Novell-STLP/STLport -include Makefile.inc -include ${SRCROOT}/Makefiles/top.mak - -INCLUDES += -I$(SRCROOT)/include -I$(STLPORT_INCLUDE_DIR) Modified: branches/complement-sockios/explore/lib/mt/ut/Makefile =================================================================== --- branches/complement-sockios/explore/lib/mt/ut/Makefile 2008-06-26 05:41:25 UTC (rev 1905) +++ branches/complement-sockios/explore/lib/mt/ut/Makefile 2008-06-26 05:42:44 UTC (rev 1906) @@ -1,4 +1,4 @@ -# -*- Makefile -*- Time-stamp: <07/08/03 22:38:12 ptr> +# -*- Makefile -*- Time-stamp: <08/06/12 15:11:40 ptr> SRCROOT := ../../.. @@ -27,24 +27,24 @@ ifeq ($(OSNAME),linux) -release-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR} -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L${LIBFS_DIR}/${OUTPUT_DIR} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR}:${LIBEXAM_DIR}/${OUTPUT_DIR}:${LIBFS_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} +release-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR} -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L${LIBFS_DIR}/${OUTPUT_DIR} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR}:${LIBEXAM_DIR}/${OUTPUT_DIR}:${LIBFS_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} -dbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_DBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L${LIBFS_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_DBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:${LIBFS_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} +dbg-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR_DBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L${LIBFS_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_DBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:${LIBFS_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} ifndef WITHOUT_STLPORT -stldbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBFS_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_STLDBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBFS_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} +stldbg-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBFS_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_STLDBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBFS_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} endif endif ifeq ($(OSNAME),openbsd) -release-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR} -Wl,-R${LIBMT_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} +release-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR} -Wl,-R${LIBMT_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} -dbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_DBG} -Wl,-R${LIBMT_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} +dbg-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR_DBG} -Wl,-R${LIBMT_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} ifndef WITHOUT_STLPORT -stldbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_STLDBG} -Wl,-R${LIBMT_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} +stldbg-shared: LDFLAGS += -L${LIBMT_DIR}/${OUTPUT_DIR_STLDBG} -Wl,-R${LIBMT_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} endif endif Deleted: branches/complement-sockios/explore/lib/mt/ut/gcc-libstd.mak =================================================================== --- branches/complement-sockios/explore/lib/mt/ut/gcc-libstd.mak 2008-06-26 05:41:25 UTC (rev 1905) +++ branches/complement-sockios/explore/lib/mt/ut/gcc-libstd.mak 2008-06-26 05:42:44 UTC (rev 1906) @@ -1,48 +0,0 @@ -# -*- Makefile -*- Time-stamp: <03/11/21 08:02:55 ptr> -# $Id$ - -SRCROOT := ../../.. -COMPILER_NAME := gcc -ALL_TAGS = release-shared dbg-shared - -include Makefile.inc -include ${SRCROOT}/Makefiles/top.mak - - -INCLUDES += -I$(SRCROOT)/include -I$(BOOST_INCLUDE_DIR) - -# temporary, before dums fix strings: -# DEFS += -D_STLP_DONT_USE_TEMPLATE_EXPRESSION - -ifeq ($(OSNAME),linux) -release-shared: LDSEARCH = -L${CoMT_LIB_DIR} -Wl,--rpath=${CoMT_LIB_DIR} -stldbg-shared: LDSEARCH = -L${CoMT_LIB_DIR_STLDBG} -Wl,--rpath=${CoMT_LIB_DIR_STLDBG} -dbg-shared: LDSEARCH = -L${CoMT_LIB_DIR_DBG} -Wl,--rpath=${CoMT_LIB_DIR_DBG} -endif - -ifeq ($(OSNAME),openbsd) -release-shared: LDSEARCH = -L${CoMT_LIB_DIR} -Wl,-R${CoMT_LIB_DIR} -stldbg-shared: LDSEARCH = -L${CoMT_LIB_DIR_STLDBG} -Wl,-R${CoMT_LIB_DIR_STLDBG} -dbg-shared: LDSEARCH = -L${CoMT_LIB_DIR_DBG} -Wl,-R${CoMT_LIB_DIR_DBG} -endif - -release-shared : LDLIBS = -lxmt_gcc -lboost_test_utf_gcc -stldbg-shared : LDLIBS = -lxmt_gcc_stl-g -lboost_test_utf_gcc_stl-g -dbg-shared : LDLIBS = -lxmt_gcc-g -lboost_test_utf_gcc-g - -ifeq ($(OSNAME),freebsd) -release-shared : LDLIBS += -lthr -stldbg-shared : LDLIBS += -lthr -dbg-shared : LDLIBS += -lthr -endif - -ifeq ($(OSNAME),sunos) -release-shared : LDLIBS += -lrt -stldbg-shared : LDLIBS += -lrt -dbg-shared : LDLIBS += -lrt -endif - -ifeq ($(OSNAME),openbsd) -release-shared: LDLIBS = -lxmt_gcc -lboost_test_utf_gcc -endif - Modified: branches/complement-sockios/explore/lib/net/samples/httpclient/Makefile =================================================================== --- branches/complement-sockios/explore/lib/net/samples/httpclient/Makefile 2008-06-26 05:41:25 UTC (rev 1905) +++ branches/complement-sockios/explore/lib/net/samples/httpclient/Makefile 2008-06-26 05:42:44 UTC (rev 1906) @@ -1,4 +1,4 @@ -# -*- Makefile -*- Time-stamp: <07/02/21 15:30:59 ptr> +# -*- Makefile -*- Time-stamp: <08/06/12 15:27:19 ptr> SRCROOT := ../../../.. # CoMT_DIR := ../../external/complement/explore @@ -18,15 +18,15 @@ ifeq ($(OSNAME),linux) -release-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR} -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L${LIBSOCK_DIR}/${OUTPUT_DIR} -L${LIBSTEM_DIR}/${OUTPUT_DIR} -L${LIBBOOSTFS_DIR}/${OUTPUT_DIR} -L${LIBBOOSTRE_DIR}/${OUTPUT_DIR} -L${LIBNET_DIR}/${OUTPUT_DIR} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR}:${LIBEXAM_DIR}/${OUTPUT_DIR}:${LIBSOCK_DIR}/${OUTPUT_DIR}:${LIBSTEM_DIR}/${OUTPUT_DIR}:${LIBBOOSTFS_DIR}/${OUTPUT_DIR}:${LIBBOOSTRE_DIR}/${OUTPUT_DIR}:${LIBNET_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${LIBSTEM_DIR}/${OUTPUT_DIR} -L${LIBBOOSTFS_DIR}/${OUTPUT_DIR} -L${LIBBOOSTRE_DIR}/${OUTPUT_DIR} -L${LIBNET_DIR}/${OUTPUT_DIR} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR}:${LIBEXAM_DIR}/${OUTPUT_DIR}:${LIBSOCK_DIR}/${OUTPUT_DIR}:${LIBSTEM_DIR}/${OUTPUT_DIR}:${LIBBOOSTFS_DIR}/${OUTPUT_DIR}:${LIBBOOSTRE_DIR}/${OUTPUT_DIR}:${LIBNET_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} ifndef WITHOUT_STLPORT -stldbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBBOOSTFS_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBBOOSTRE_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBNET_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_STLDBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBBOOSTFS_DIR}/${OUTPUT_DIR_STLDBG}:${LIBBOOSTRE_DIR}/${OUTPUT_DIR_STLDBG}:${LIBNET_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${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBBOOSTFS_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBBOOSTRE_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBNET_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_STLDBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBBOOSTFS_DIR}/${OUTPUT_DIR_STLDBG}:${LIBBOOSTRE_DIR}/${OUTPUT_DIR_STLDBG}:${LIBNET_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} endif -dbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_DBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_DBG} -L${LIBSTEM_DIR}/${OUTPUT_DIR_DBG} -L${LIBBOOSTFS_DIR}/${OUTPUT_DIR_DBG} -L${LIBBOOSTRE_DIR}/${OUTPUT_DIR_DBG} -L${LIBNET_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_DBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_DBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_DBG}:${LIBBOOSTFS_DIR}/${OUTPUT_DIR_DBG}:${LIBBOOSTRE_DIR}/${OUTPUT_DIR_DBG}:${LIBNET_DIR}/${OUTPUT_DIR_DBG}:${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${LIBSTEM_DIR}/${OUTPUT_DIR_DBG} -L${LIBBOOSTFS_DIR}/${OUTPUT_DIR_DBG} -L${LIBBOOSTRE_DIR}/${OUTPUT_DIR_DBG} -L${LIBNET_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_DBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_DBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_DBG}:${LIBBOOSTFS_DIR}/${OUTPUT_DIR_DBG}:${LIBBOOSTRE_DIR}/${OUTPUT_DIR_DBG}:${LIBNET_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} endif Modified: branches/complement-sockios/explore/lib/net/ut/Makefile =================================================================== --- branches/complement-sockios/explore/lib/net/ut/Makefile 2008-06-26 05:41:25 UTC (rev 1905) +++ branches/complement-sockios/explore/lib/net/ut/Makefile 2008-06-26 05:42:44 UTC (rev 1906) @@ -1,4 +1,4 @@ -# -*- Makefile -*- Time-stamp: <07/02/21 15:30:59 ptr> +# -*- Makefile -*- Time-stamp: <08/06/12 15:17:05 ptr> SRCROOT := ../../.. # CoMT_DIR := ../../external/complement/explore @@ -18,15 +18,15 @@ ifeq ($(OSNAME),linux) -release-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR} -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L${LIBSOCK_DIR}/${OUTPUT_DIR} -L${LIBSTEM_DIR}/${OUTPUT_DIR} -L${LIBBOOSTFS_DIR}/${OUTPUT_DIR} -L${LIBBOOSTRE_DIR}/${OUTPUT_DIR} -L${LIBNET_DIR}/${OUTPUT_DIR} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR}:${LIBEXAM_DIR}/${OUTPUT_DIR}:${LIBSOCK_DIR}/${OUTPUT_DIR}:${LIBSTEM_DIR}/${OUTPUT_DIR}:${LIBBOOSTFS_DIR}/${OUTPUT_DIR}:${LIBBOOSTRE_DIR}/${OUTPUT_DIR}:${LIBNET_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${LIBSTEM_DIR}/${OUTPUT_DIR} -L${LIBBOOSTFS_DIR}/${OUTPUT_DIR} -L${LIBBOOSTRE_DIR}/${OUTPUT_DIR} -L${LIBNET_DIR}/${OUTPUT_DIR} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR}:${LIBEXAM_DIR}/${OUTPUT_DIR}:${LIBSOCK_DIR}/${OUTPUT_DIR}:${LIBSTEM_DIR}/${OUTPUT_DIR}:${LIBBOOSTFS_DIR}/${OUTPUT_DIR}:${LIBBOOSTRE_DIR}/${OUTPUT_DIR}:${LIBNET_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} ifndef WITHOUT_STLPORT -stldbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBBOOSTFS_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBBOOSTRE_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBNET_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_STLDBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBBOOSTFS_DIR}/${OUTPUT_DIR_STLDBG}:${LIBBOOSTRE_DIR}/${OUTPUT_DIR_STLDBG}:${LIBNET_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${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBBOOSTFS_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBBOOSTRE_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBNET_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_STLDBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBBOOSTFS_DIR}/${OUTPUT_DIR_STLDBG}:${LIBBOOSTRE_DIR}/${OUTPUT_DIR_STLDBG}:${LIBNET_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} endif -dbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_DBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_DBG} -L${LIBSTEM_DIR}/${OUTPUT_DIR_DBG} -L${LIBBOOSTFS_DIR}/${OUTPUT_DIR_DBG} -L${LIBBOOSTRE_DIR}/${OUTPUT_DIR_DBG} -L${LIBNET_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_DBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_DBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_DBG}:${LIBBOOSTFS_DIR}/${OUTPUT_DIR_DBG}:${LIBBOOSTRE_DIR}/${OUTPUT_DIR_DBG}:${LIBNET_DIR}/${OUTPUT_DIR_DBG}:${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${LIBSTEM_DIR}/${OUTPUT_DIR_DBG} -L${LIBBOOSTFS_DIR}/${OUTPUT_DIR_DBG} -L${LIBBOOSTRE_DIR}/${OUTPUT_DIR_DBG} -L${LIBNET_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_DBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_DBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_DBG}:${LIBBOOSTFS_DIR}/${OUTPUT_DIR_DBG}:${LIBBOOSTRE_DIR}/${OUTPUT_DIR_DBG}:${LIBNET_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} endif Modified: branches/complement-sockios/explore/lib/sockios/perf/Makefile =================================================================== --- branches/complement-sockios/explore/lib/sockios/perf/Makefile 2008-06-26 05:41:25 UTC (rev 1905) +++ branches/complement-sockios/explore/lib/sockios/perf/Makefile 2008-06-26 05:42:44 UTC (rev 1906) @@ -1,4 +1,4 @@ -# -*- Makefile -*- Time-stamp: <07/09/05 22:48:46 ptr> +# -*- Makefile -*- Time-stamp: <08/06/12 15:23:48 ptr> SRCROOT := ../../.. @@ -18,11 +18,11 @@ # LIBUTF_DIR = ${CoMT_DIR}/../extern/custom/boost/libs/test/unit_test_framework ifeq ($(OSNAME),linux) -release-shared: LDSEARCH += -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} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR}:${LIBEXAM_DIR}/${OUTPUT_DIR}:${LIBSOCK_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} ifndef WITHOUT_STLPORT -stldbg-shared: LDSEARCH += -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} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_STLDBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} endif -dbg-shared: LDSEARCH += -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} +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 Modified: branches/complement-sockios/explore/lib/sockios/ut/Makefile =================================================================== --- branches/complement-sockios/explore/lib/sockios/ut/Makefile 2008-06-26 05:41:25 UTC (rev 1905) +++ branches/complement-sockios/explore/lib/sockios/ut/Makefile 2008-06-26 05:42:44 UTC (rev 1906) @@ -1,4 +1,4 @@ -# -*- Makefile -*- Time-stamp: <07/08/03 23:06:43 ptr> +# -*- Makefile -*- Time-stamp: <08/06/12 15:24:26 ptr> SRCROOT := ../../.. @@ -18,11 +18,11 @@ # LIBUTF_DIR = ${CoMT_DIR}/../extern/custom/boost/libs/test/unit_test_framework ifeq ($(OSNAME),linux) -release-shared: LDSEARCH += -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} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR}:${LIBEXAM_DIR}/${OUTPUT_DIR}:${LIBSOCK_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} ifndef WITHOUT_STLPORT -stldbg-shared: LDSEARCH += -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} -Wl,--rpath=${LIBMT_DIR}/${OUTPUT_DIR_STLDBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} endif -dbg-shared: LDSEARCH += -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} +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 Modified: branches/complement-sockios/explore/lib/stem/ut/Makefile =================================================================== --- branches/complement-sockios/explore/lib/stem/ut/Makefile 2008-06-26 05:41:25 UTC (rev 1905) +++ branches/complement-sockios/explore/lib/stem/ut/Makefile 2008-06-26 05:42:44 UTC (rev 1906) @@ -1,4 +1,4 @@ -# -*- Makefile -*- Time-stamp: <07/08/03 23:55:05 ptr> +# -*- Makefile -*- Time-stamp: <08/06/12 15:25:10 ptr> SRCROOT := ../../.. @@ -19,15 +19,15 @@ ifeq ($(OSNAME),linux) -release-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR} -L${LIBEXAM_DIR}/${OUTPUT_DIR} -L${LIBSOCK_DIR}/${OUTPUT_DIR} -L${LIBSTEM_DIR}/${OUTPUT_DIR} -Wl,--rpath=./dl/${OUTPUT_DIR}:${LIBMT_DIR}/${OUTPUT_DIR}:${LIBEXAM_DIR}/${OUTPUT_DIR}:${LIBSOCK_DIR}/${OUTPUT_DIR}:${LIBSTEM_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${LIBSTEM_DIR}/${OUTPUT_DIR} -Wl,--rpath=./dl/${OUTPUT_DIR}:${LIBMT_DIR}/${OUTPUT_DIR}:${LIBEXAM_DIR}/${OUTPUT_DIR}:${LIBSOCK_DIR}/${OUTPUT_DIR}:${LIBSTEM_DIR}/${OUTPUT_DIR}:${STLPORT_LIB_DIR} ifndef WITHOUT_STLPORT -stldbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=./dl/${OUTPUT_DIR_STLDBG}:${LIBMT_DIR}/${OUTPUT_DIR_STLDBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSTEM_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${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG} -Wl,--rpath=./dl/${OUTPUT_DIR_STLDBG}:${LIBMT_DIR}/${OUTPUT_DIR_STLDBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_STLDBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} endif -dbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_DBG} -L${LIBEXAM_DIR}/${OUTPUT_DIR_DBG} -L${LIBSOCK_DIR}/${OUTPUT_DIR_DBG} -L${LIBSTEM_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=./dl/${OUTPUT_DIR_DBG}:${LIBMT_DIR}/${OUTPUT_DIR_DBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_DBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_DBG}:${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${LIBSTEM_DIR}/${OUTPUT_DIR_DBG} -Wl,--rpath=./dl/${OUTPUT_DIR_DBG}:${LIBMT_DIR}/${OUTPUT_DIR_DBG}:${LIBEXAM_DIR}/${OUTPUT_DIR_DBG}:${LIBSOCK_DIR}/${OUTPUT_DIR_DBG}:${LIBSTEM_DIR}/${OUTPUT_DIR_DBG}:${STLPORT_LIB_DIR} endif Modified: branches/complement-sockios/explore/lib/stem/ut/dl/Makefile =================================================================== --- branches/complement-sockios/explore/lib/stem/ut/dl/Makefile 2008-06-26 05:41:25 UTC (rev 1905) +++ branches/complement-sockios/explore/lib/stem/ut/dl/Makefile 2008-06-26 05:42:44 UTC (rev 1906) @@ -1,4 +1,4 @@ -# -*- Makefile -*- Time-stamp: <07/08/03 23:59:51 ptr> +# -*- Makefile -*- Time-stamp: <08/06/12 15:25:51 ptr> SRCROOT := ../../../.. @@ -12,11 +12,11 @@ INCLUDES += -I$(SRCROOT)/include -#LDSEARCH = -L${STLPORT_LIB_DIR} -L${CoMT_LIB_DIR} -release-shared: LDSEARCH += -L${LIBSTEM_DIR}/${OUTPUT_DIR} -dbg-shared: LDSEARCH += -L${LIBSTEM_DIR}/${OUTPUT_DIR_DBG} +#LDFLAGS = -L${STLPORT_LIB_DIR} -L${CoMT_LIB_DIR} +release-shared: LDFLAGS += -L${LIBSTEM_DIR}/${OUTPUT_DIR} +dbg-shared: LDFLAGS += -L${LIBSTEM_DIR}/${OUTPUT_DIR_DBG} ifndef WITHOUT_STLPORT -stldbg-shared: LDSEARCH += -L${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG} +stldbg-shared: LDFLAGS += -L${LIBSTEM_DIR}/${OUTPUT_DIR_STLDBG} endif #release-shared : LDLIBS = -lxmt -lsockios -lstem -lboost_test_utf This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-06-26 05:41:27
|
Revision: 1905 http://complement.svn.sourceforge.net/complement/?rev=1905&view=rev Author: complement Date: 2008-06-25 22:41:25 -0700 (Wed, 25 Jun 2008) Log Message: ----------- don't duplicate options in config.mak, that has default values in makefiles Modified Paths: -------------- branches/complement-sockios/explore/Makefiles/ChangeLog branches/complement-sockios/explore/configure Modified: branches/complement-sockios/explore/Makefiles/ChangeLog =================================================================== --- branches/complement-sockios/explore/Makefiles/ChangeLog 2008-06-26 05:41:09 UTC (rev 1904) +++ branches/complement-sockios/explore/Makefiles/ChangeLog 2008-06-26 05:41:25 UTC (rev 1905) @@ -1,3 +1,8 @@ +2008-06-07 Petr Ovtchenkov <pt...@is...> + + * configure: don't duplicate options in config.mak, that + has default values in makefiles. + 2008-06-06 Petr Ovtchenkov <pt...@is...> * gmake/targetdirs.mak: use $(DESTDIR) as in common practice Modified: branches/complement-sockios/explore/configure =================================================================== --- branches/complement-sockios/explore/configure 2008-06-26 05:41:09 UTC (rev 1904) +++ branches/complement-sockios/explore/configure 2008-06-26 05:41:25 UTC (rev 1905) @@ -1,6 +1,6 @@ #!/bin/sh -# Time-stamp: <08/06/06 17:44:52 yeti> +# Time-stamp: <08/06/07 15:22:06 yeti> base=`cd \`dirname $0\`; echo $PWD` @@ -86,27 +86,26 @@ # write_option "${PWD}/external/boost" BOOST_DIR # fi - if [ "$stlport_set" = "" ]; then - # write_option "${PWD}/external/STLport" STLPORT_DIR - write_option "1" WITHOUT_STLPORT - fi + # Set in Makefiles/gmake/extern.mak + # if [ -z "${stlport_set}" ]; then + # # write_option "${PWD}/external/STLport" STLPORT_DIR + # write_option "1" WITHOUT_STLPORT + # fi + # write_option "${PWD}/build/" BASE_INSTALL_DIR '${DESTDIR}' - if [ "$compiler_family_set" = "" ]; then - write_option gcc COMPILER_NAME - fi - # if [ "$prefix_set" = "" ]; then + + # Set in Makefiles/gmake/top.mak + # if [ -z "${compiler_family_set}" ]; then + # write_option gcc COMPILER_NAME + # fi + + # Set in Makefiles/gmake/targetdirs.mak + # if [ -z "${prefix_set}" ]; then # write_option "/usr/local" BASE_INSTALL_DIR '${DESTDIR}' # fi } -case $# in - 0) - if [ ! -f ${configmak} ]; then - default_settings - fi - exit 0 - ;; -esac +[ $# -eq 0 ] && { >${configmak}; default_settings; exit 0; } for a in $@ ; do case $a in @@ -121,8 +120,7 @@ esac done -rm -f ${configmak} -touch ${configmak} +>${configmak} while : do @@ -207,7 +205,7 @@ ;; --prefix=*) write_option "$option" BASE_INSTALL_DIR '${DESTDIR}' - # prefix_set=y + prefix_set=y ;; --bindir=*) write_option "$option" INSTALL_BIN_DIR '${DESTDIR}' @@ -221,46 +219,46 @@ esac done -if [ "$CXX" != "" ]; then - if [ "$cxx_set" != "" ]; then +if [ -n "${CXX}" ]; then + if [ -n "${cxx_set}" ]; then echo "Both --with-cxx and \$CXX set, using the first" - elif [ "$target_set" = "" ]; then - write_option "$CXX" _FORCE_CXX + elif [ -z "${target_set}" ]; then + write_option "${CXX}" _FORCE_CXX else echo "For cross-compilation with gcc use --target option only" fi - if [ "$CC" = "" ] && [ "$cc_set" = "" ]; then + if [ -z "${CC}" -a -z "${cc_set}" ]; then echo "\$CXX set, but I don't see \$CC!" fi fi -if [ "$CC" != "" ]; then - if [ "$cxx_set" != "" ]; then +if [ -n "${CC}" ]; then + if [ -n "${cxx_set}" ]; then echo "Both --with-cc and \$CC set, using the first" else - write_option "$CC" _FORCE_CC + write_option "${CC}" _FORCE_CC fi fi -if [ "$CXXFLAGS" != "" ]; then - if [ "$cxxflags_set" = "" ]; then - write_option "$CXXFLAGS" EXTRA_CXXFLAGS +if [ -n "${CXXFLAGS}" ]; then + if [ -z "${cxxflags_set}" ]; then + write_option "${CXXFLAGS}" EXTRA_CXXFLAGS else echo "Both --with-extra-cxxflags and \$CXXFLAGS set, using the first" fi fi -if [ "$CFLAGS" != "" ]; then - if [ "$cflags_set" = "" ]; then - write_option "$CFLAGS" EXTRA_CFLAGS +if [ -n "${CFLAGS}" ]; then + if [ -z "${cflags_set}" ]; then + write_option "${CFLAGS}" EXTRA_CFLAGS else echo "Both --with-extra-cflags and \$CFLAGS set, using the first" fi fi -if [ "$LDFLAGS" != "" ]; then - if [ "$ldflags_set" = "" ]; then - write_option "$LDFLAGS" EXTRA_LDFLAGS +if [ -n "${LDFLAGS}" ]; then + if [ -z "${ldflags_set}" ]; then + write_option "${LDFLAGS}" EXTRA_LDFLAGS else echo "Both --with-extra-ldflags and \$LDFLAGS set, using the first" fi This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-06-26 05:41:11
|
Revision: 1904 http://complement.svn.sourceforge.net/complement/?rev=1904&view=rev Author: complement Date: 2008-06-25 22:41:09 -0700 (Wed, 25 Jun 2008) Log Message: ----------- take into account extra CFLAGS and LDFLAGS; configurable via 'configure'; don't assume presence of STLport. Modified Paths: -------------- branches/complement-sockios/explore/Makefiles/ChangeLog branches/complement-sockios/explore/Makefiles/gmake/extern.mak branches/complement-sockios/explore/Makefiles/gmake/gcc.mak branches/complement-sockios/explore/Makefiles/gmake/top.mak branches/complement-sockios/explore/configure Modified: branches/complement-sockios/explore/Makefiles/ChangeLog =================================================================== --- branches/complement-sockios/explore/Makefiles/ChangeLog 2008-06-26 05:40:45 UTC (rev 1903) +++ branches/complement-sockios/explore/Makefiles/ChangeLog 2008-06-26 05:41:09 UTC (rev 1904) @@ -3,8 +3,13 @@ * gmake/targetdirs.mak: use $(DESTDIR) as in common practice (change root of installation, but don't change run paths); - * gmake/depend.mak: fix options for ctags/etags. + * gmake/depend.mak: fix options for ctags/etags; + * gmake/gcc.mak, gmake/top.mak, configure: take into account + extra CFLAGS and LDFLAGS; configurable via 'configure'; + + * gmake/extern.mak: don't assume presence of STLport. + 2008-02-27 Petr Ovtchenkov <pt...@is...> * gmake/lib/gcc.mak: 3.3 is normal compiler, just some Modified: branches/complement-sockios/explore/Makefiles/gmake/extern.mak =================================================================== --- branches/complement-sockios/explore/Makefiles/gmake/extern.mak 2008-06-26 05:40:45 UTC (rev 1903) +++ branches/complement-sockios/explore/Makefiles/gmake/extern.mak 2008-06-26 05:41:09 UTC (rev 1904) @@ -1,6 +1,6 @@ -# Time-stamp: <07/03/08 22:41:26 ptr> +# Time-stamp: <08/06/06 17:06:16 yeti> # -# Copyright (c) 1997-1999, 2002, 2003, 2005, 2006 +# Copyright (c) 1997-1999, 2002, 2003, 2005, 2006, 2008 # Petr Ovtchenkov # # Portion Copyright (c) 1999-2001 @@ -30,9 +30,11 @@ # STLport library +ifndef STLPORT_DIR ifndef WITHOUT_STLPORT -STLPORT_DIR ?= ${HOME}/STLport.lab/STLport +WITHOUT_STLPORT = 1 endif +endif ifdef STLPORT_DIR STLPORT_LIB_DIR ?= $(STLPORT_DIR)/${TARGET_NAME}lib Modified: branches/complement-sockios/explore/Makefiles/gmake/gcc.mak =================================================================== --- branches/complement-sockios/explore/Makefiles/gmake/gcc.mak 2008-06-26 05:40:45 UTC (rev 1903) +++ branches/complement-sockios/explore/Makefiles/gmake/gcc.mak 2008-06-26 05:41:09 UTC (rev 1904) @@ -1,4 +1,4 @@ -# Time-stamp: <08/02/26 13:46:36 ptr> +# Time-stamp: <08/06/06 17:38:26 yeti> # # Copyright (c) 1997-1999, 2002, 2003, 2005-2008 # Petr Ovtchenkov @@ -179,6 +179,10 @@ CXXFLAGS += ${EXTRA_CXXFLAGS} endif +ifdef EXTRA_CFLAGS +CFLAGS += ${EXTRA_CFLAGS} +endif + CDEPFLAGS = -E -M CCDEPFLAGS = -E -M Modified: branches/complement-sockios/explore/Makefiles/gmake/top.mak =================================================================== --- branches/complement-sockios/explore/Makefiles/gmake/top.mak 2008-06-26 05:40:45 UTC (rev 1903) +++ branches/complement-sockios/explore/Makefiles/gmake/top.mak 2008-06-26 05:41:09 UTC (rev 1904) @@ -1,4 +1,4 @@ -# Time-stamp: <07/07/12 10:55:41 ptr> +# Time-stamp: <08/06/06 17:28:38 yeti> # # Copyright (c) 1997-1999, 2002, 2003, 2005-2007 # Petr Ovtchenkov @@ -25,6 +25,10 @@ COMPILER_NAME := gcc endif +ifndef LDFLAGS +LDFLAGS := +endif + ifndef ALL_TAGS ifndef _NO_SHARED_BUILD @@ -91,6 +95,8 @@ # os-specific local rules (or other project-specific definitions) -include specific.mak +LDFLAGS += ${EXTRA_LDFLAGS} + # derive common targets (*.o, *.d), # build rules (including output catalogs) include ${RULESBASE}/gmake/targets.mak Modified: branches/complement-sockios/explore/configure =================================================================== --- branches/complement-sockios/explore/configure 2008-06-26 05:40:45 UTC (rev 1903) +++ branches/complement-sockios/explore/configure 2008-06-26 05:41:09 UTC (rev 1904) @@ -1,6 +1,6 @@ #!/bin/sh -# Time-stamp: <08/02/26 16:02:32 yeti> +# Time-stamp: <08/06/06 17:44:52 yeti> base=`cd \`dirname $0\`; echo $PWD` @@ -47,6 +47,10 @@ --with-mssdk=<dir> use MS SDK from this catalog --with-extra-cxxflags=<options> pass extra options to C++ compiler + --with-extra-cflags=<options> + pass extra options to C compiler + --with-extra-ldflags=<options> + pass extra options to linker (via C/C++) --use-static-gcc use static gcc libs instead of shared libgcc_s (useful for gcc compiler, that was builded with --enable-shared [default]; if compiler was builded with --disable-shared, static libraries will be used in any case) @@ -69,6 +73,8 @@ \$CXX C++ compiler name (use --target= for cross-compilation) \$CC C compiler name (use --target= for cross-compilation) \$CXXFLAGS pass extra options to C++ compiler + \$CFLAGS pass extra options to C compiler + \$LDFLAGS pass extra options to linker (via C/C++) Options has preference over environment variables. @@ -156,6 +162,14 @@ write_option "$option" EXTRA_CXXFLAGS cxxflags_set=y ;; + --with-extra-cflags=*) + write_option "$option" EXTRA_CFLAGS + cflags_set=y + ;; + --with-extra-ldflags=*) + write_option "$option" EXTRA_LDFLAGS + ldflags_set=y + ;; --use-static-gcc) write_option "1" USE_STATIC_LIBGCC ;; @@ -236,6 +250,22 @@ fi fi +if [ "$CFLAGS" != "" ]; then + if [ "$cflags_set" = "" ]; then + write_option "$CFLAGS" EXTRA_CFLAGS + else + echo "Both --with-extra-cflags and \$CFLAGS set, using the first" + fi +fi + +if [ "$LDFLAGS" != "" ]; then + if [ "$ldflags_set" = "" ]; then + write_option "$LDFLAGS" EXTRA_LDFLAGS + else + echo "Both --with-extra-ldflags and \$LDFLAGS set, using the first" + fi +fi + # default settings default_settings This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |