[complement-svn] SF.net SVN: complement: [1875] trunk/complement/explore/app/SMTP-tools/ smtp_serve
Status: Pre-Alpha
Brought to you by:
complement
From: <oke...@us...> - 2008-05-15 08:36:12
|
Revision: 1875 http://complement.svn.sourceforge.net/complement/?rev=1875&view=rev Author: okechina Date: 2008-05-15 01:35:35 -0700 (Thu, 15 May 2008) Log Message: ----------- A new class "session" is created. All the server methods are collected in the class. Server checks if there is data available. Modified Paths: -------------- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.cc trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.h trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc Modified: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.cc =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.cc 2008-05-14 08:53:23 UTC (rev 1874) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.cc 2008-05-15 08:35:35 UTC (rev 1875) @@ -9,8 +9,15 @@ using namespace std; -command setCom( const string& str ) +session::session ( std::basic_istream<char>& is, std::basic_ostream<char>& os ) : + in(is), + out(os) { + st = connect; +}; + +command session::setCom( const string& str ) +{ string Str; for ( string::const_iterator i = str.begin(); i != str.end(); ++i ) { @@ -64,8 +71,9 @@ return none; } -void change( state& st, const command& com, const string& param, string& stout ) +void session::changeSt( const string& str, const string& param, std::string& stout ) { + com = session::setCom( str ); switch ( com ) { case helo: if (st == connect) { @@ -178,34 +186,35 @@ } } - -int ServerWork() +int session::checkData () { - state st = connect; - command com; - string param, message, stout; - - while ( st != disconnect ) { - if ( st != letter ) { - string str; - cin >> str; - getline(cin, param); - com = setCom(str); - change(st, com, param, stout); - cout << stout; + string str, param, stout; + if ( st != letter ) { + in >> str; + if ( str.empty() ) + return -1; + getline( in, param ); + changeSt( str, param, stout ); + out << stout << endl; + } else { + getline( in, param ); + if ( param.empty() ) + return -1; + if ( param != "." ) { + message += param + "\n"; } else { - getline( cin, param ); - if ( param != "." ) { - message += param + "\n"; - } else { - st = hello; - cout << message; - message = ""; - } + st = hello; +// cerr << message; + message = ""; } } - return 0; } + +state session::getState () +{ + return st; +} + } // namespace smtp Modified: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.h =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.h 2008-05-14 08:53:23 UTC (rev 1874) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.h 2008-05-15 08:35:35 UTC (rev 1875) @@ -4,6 +4,7 @@ #define __SMPT_SERVER_H #include <string> +#include <iostream> namespace smtp { @@ -33,12 +34,28 @@ none }; -int ServerWork(); +class session +{ + private: + state st; + command com; + std::string message; -command setCom( const std::string& str ); + std::basic_istream<char>& in; + std::basic_ostream<char>& out; -void change( state& st, const command& com, const std::string& param, std::string& stout ); + command setCom ( const std::string& str ); + void changeSt ( const std::string& str, const std::string& param, std::string& stout ); + public: + session ( std::basic_istream<char>& is, std::basic_ostream<char>& os ); + ~session () + { }; + int checkData (); + + state getState (); +}; + } // namespace smtp #endif // __SMPT_SERVER_H Modified: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc 2008-05-14 08:53:23 UTC (rev 1874) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc 2008-05-15 08:35:35 UTC (rev 1875) @@ -80,32 +80,11 @@ basic_ostream<char> out( &_out_buf ); #endif - state st = connect; - command com; - string param, message, stout; + smtp::session ss (in, out); - while ( st != disconnect ) { - if ( st != letter ) { - string str; - in >> str; - if ( str.empty() ) - break; - getline( in, param ); - com = setCom( str ); - change( st, com, param, stout ); - out << stout << endl; - } else { - getline( in, param ); - if ( param.empty() ) - break; - if ( param != "." ) { - message += param + "\n"; - } else { - st = hello; -// cerr << message; - message = ""; - } - } + while ( ss.getState() != disconnect ) { + int t = ss.checkData(); + if ( t < 0 ) break; } close(fd2[0]); @@ -142,14 +121,14 @@ getline( in_tst, s ); if ( !s.empty() ) { out << s << endl; -// cerr << s << endl; + cerr << s << endl; do { getline (in, result); -// cerr << result << endl; + cerr << result << endl; } while ( result[3] == '-' ); } } - + close(fd2[1]); close(fd1[0]); t.join(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |