Thread: [complement-svn] SF.net SVN: complement: [1847] trunk/complement/explore/app/SMTP-tools
Status: Pre-Alpha
Brought to you by:
complement
From: <oke...@us...> - 2008-04-22 11:42:59
|
Revision: 1847 http://complement.svn.sourceforge.net/complement/?rev=1847&view=rev Author: okechina Date: 2008-04-22 04:42:53 -0700 (Tue, 22 Apr 2008) Log Message: ----------- Added Paths: ----------- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/Makefile trunk/complement/explore/app/SMTP-tools/smtp_server_ut/Makefile.inc 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 trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.h trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test_suite.cc trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test_suite.h trunk/complement/explore/app/SMTP-tools/smtp_server_ut/unit_test.cc Added: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/Makefile =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/Makefile (rev 0) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/Makefile 2008-04-22 11:42:53 UTC (rev 1847) @@ -0,0 +1,74 @@ +# -*- Makefile -*- Time-stamp: <07/08/03 22:38:12 ptr> + +SRCROOT := ../../.. + +include Makefile.inc +include ${SRCROOT}/Makefiles/gmake/top.mak + + +INCLUDES += -I$(SRCROOT)/include +ifdef BOOST_DIR +INCLUDES += -I$(BOOST_INCLUDE_DIR) +endif +DEFS += -D__FIT_EXAM + +# temporary, before dums fix strings: +# DEFS += -D_STLP_DONT_USE_TEMPLATE_EXPRESSION + +# RPATH := $(realpath ${CoMT_LIB_DIR}) +# ifndef WITHOUT_STLPORT +# RPATH := ${RPATH}:$(realpath ${STLPORT_LIB_DIR}):$(realpath /usr/lib) +# endif + +LIBMT_DIR = ${CoMT_DIR}/lib/mt +# LIBUTF_DIR = ${CoMT_DIR}/../extern/custom/boost/libs/test/unit_test_framework +LIBEXAM_DIR = ${CoMT_DIR}/lib/exam +LIBFS_DIR = ${CoMT_DIR}/../extern/custom/boost/libs/filesystem + +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} + +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} + +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} +endif + +endif + +ifeq ($(OSNAME),openbsd) + +release-shared: LDSEARCH += -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} + +ifndef WITHOUT_STLPORT +stldbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_STLDBG} -Wl,-R${LIBMT_DIR}/${OUTPUT_DIR_STLDBG}:${STLPORT_LIB_DIR} +endif + +endif + +release-shared : LDLIBS = -lxmt -lexam +dbg-shared : LDLIBS = -lxmtg -lexamg +ifndef WITHOUT_STLPORT +stldbg-shared : LDLIBS = -lxmtstlg -lexamstlg +endif + +ifeq ($(OSNAME),freebsd) +release-shared : LDLIBS += -lthr +dbg-shared : LDLIBS += -lthr +ifndef WITHOUT_STLPORT +stldbg-shared : LDLIBS += -lthr +endif +endif + +ifeq ($(OSNAME),sunos) +release-shared : LDLIBS += -lrt +dbg-shared : LDLIBS += -lrt +ifndef WITHOUT_STLPORT +stldbg-shared : LDLIBS += -lrt +endif +endif + + Added: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/Makefile.inc =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/Makefile.inc (rev 0) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/Makefile.inc 2008-04-22 11:42:53 UTC (rev 1847) @@ -0,0 +1,7 @@ +# -*- makefile -*- Time-stamp: <08/03/26 10:12:36 ptr> + +PRGNAME = my_ut +SRC_CC = unit_test.cc \ + my_test.cc \ + my_test_suite.cc \ + SMTP_Server.cc Added: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.cc =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.cc (rev 0) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.cc 2008-04-22 11:42:53 UTC (rev 1847) @@ -0,0 +1,151 @@ +#include <iostream> +#include <string> +#include "SMTP_Server.h" + +using namespace std; + +command setCom(const string& str) { + string Str(str); + for(int i = 0; Str[i] != '\0'; i++) + Str[i] = tolower(Str[i]); + if (Str == "helo") return helo; + else if (Str == "ehlo") return ehlo; + else if (Str == "mail") return mail; + else if (Str == "rcpt") return rcpt; + else if (Str == "data") return data; + else if (Str == "rset") return rset; + else if (Str == "vrfy") return vrfy; + else if (Str == "expn") return expn; + else if (Str == "help") return help; + else if (Str == "noop") return noop; + else if (Str == "quit") return quit; + else return none; +} + +void change(state& st, command& com, string& param, string& stout) { + switch (com) { + case helo: + if (st == connect) { + stout = "250 localhost Hello localhost, pleased to meet you\n"; + st = hello; + return; + } + else { + stout = "503 localhost Duplicate HELO/EHLO\n"; + return; + } + case ehlo: + if (st == connect) { + stout = "250-localhost Hello localhost, pleased to meet you\n"; + stout += "250-8BITMIME\n"; + stout += "250-SIZE 8000000\n"; + stout += "250 HELP\n"; + st = hello; + return; + } + else { + stout = "503 localhost Duplicate HELO/EHLO\n"; + return; + } + case mail: + switch (st) { + case connect: + stout = "503 Polite people say HELO first\n"; + return; + case hello: + stout = "250 " + param + "... Sender ok\n"; + st = sender; + return; + case sender: + stout = "503 Sender already specified\n"; + return; + case recipient: + stout = "503 Sender already specified\n"; + return; + } + case rcpt: + switch (st) { + case connect: + stout = "503 Need MAIL before RCPT\n"; + return; + case hello: + stout = "503 Need MAIL before RCPT\n"; + return; + case sender: + stout = "250 " + param + "... Recipient ok\n"; + st = recipient; + return; + case recipient: + stout = "250 " + param + "... Recipient ok\n"; + return; + } + case data: + switch (st) { + case connect: + stout = "503 Need MAIL command\n"; + return; + case hello: + stout = "503 Need MAIL command\n"; + return; + case sender: + stout = "503 Need RCPT (recipient)\n"; + return; + case recipient: + stout = "354 Enter mail, end with '.' on a line by itself\n"; + st = letter; + return; + } + case rset: + stout = "250 Reset state\n"; + if (st!=connect) st = hello; + return; + case vrfy: + stout = "502 Command not implemented\n"; + return; + case expn: + stout = "502 Command not implemented\n"; + return; + case help: + stout = "214-This is SMTP_Server\n"; + stout += "214 End of HELP info\n"; + return; + case noop: + stout = "250 OK\n"; + return; + case quit: + stout = "221 localhost closing connection\n"; + stout += "Connection closed by foreign host.\n"; + st = disconnect; + return; + case none: + stout = "500 Command unrecognized\n"; + return; + } +} + + +int ServerWork() { + 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; + } + else { + getline(cin, param); + if (param != ".") message = message + param + "\n"; + else { + st = hello; + cout << message; + message = ""; + } + }; + }; + return 0; +} Added: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.h =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.h (rev 0) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/SMTP_Server.h 2008-04-22 11:42:53 UTC (rev 1847) @@ -0,0 +1,32 @@ +using namespace std; + +enum state { + disconnect, + connect, + hello, + sender, + recipient, + letter + }; +enum command { + helo, + ehlo, + mail, + rcpt, + data, + rset, + vrfy, + expn, + help, + noop, + quit, + none + }; + + +int ServerWork(); + +command setCom(const string& str); + +void change(state& st, command& com, string& param, string& stout); + Added: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc (rev 0) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc 2008-04-22 11:42:53 UTC (rev 1847) @@ -0,0 +1,97 @@ +// -*- C++ -*- Time-stamp: <08/03/26 01:53:46 ptr> + +#include "my_test.h" +#include "SMTP_Server.h" + +#include <mt/thread> +#include <mt/mutex> +#include <mt/condition_variable> +#include <misc/type_traits.h> +#include <typeinfo> + +#include <iostream> +#include <semaphore.h> + +#include <sys/wait.h> +#include <sys/ipc.h> +#include <sys/shm.h> + +#include <unistd.h> + +using namespace std; + +static int fd1[2], fd2[2]; + +const int buf_size = 1024; +const int com_length = 4; + +void server_thread() +{ + char buffer[buf_size]; + state st = connect; + command com; + string param, message, stout; + + while (st != disconnect) { + if (st != letter) { + + if (read (fd2[0], buffer, sizeof(buffer)) < 1) fprintf(stderr,"Reading error\n"); + else fprintf (stderr,"%s\n",buffer); + + string str(buffer); + param.assign (str, com_length, str.size()); + str.erase (com_length, str.size() - com_length + 1); + com = setCom (str); + change (st, com, param, stout); + + strcpy (buffer, stout.c_str()); + write (fd1[1], buffer, sizeof(buffer)); + } + else { + read (fd2[0], buffer, sizeof(buffer)); + param.assign (buffer, 0, sizeof(buffer)); + if (param != ".") message = message + param + "\n"; + else { + st = hello; +// cout << message; + message = ""; + } + }; + }; + cerr << "Server's loop may be here" << endl; +} + +int EXAM_IMPL(my_test::thread_call) +{ + char r_buffer[buf_size], w_buffer[buf_size]; + pipe (fd1); + pipe (fd2); + std::tr2::basic_thread<0,0> t( server_thread ); + + strcpy (w_buffer, "ehlo"); + write (fd2[1], w_buffer, sizeof(w_buffer)); + read (fd1[0], r_buffer, sizeof(r_buffer)); + cerr << r_buffer; + + strcpy (w_buffer, "help"); + write (fd2[1], w_buffer, sizeof(w_buffer)); + read (fd1[0], r_buffer, sizeof(r_buffer)); + cerr << r_buffer; + + strcpy (w_buffer, "quit"); + write (fd2[1], w_buffer, sizeof(w_buffer)); + read (fd1[0], r_buffer, sizeof(r_buffer)); + cerr << r_buffer; + + cerr << "Client's text may be here" << endl; + t.join(); + + // EXAM_CHECK( val == 1 ); + // std::tr2::basic_thread<0,0> t2( thread_func_int, 2 ); + // t2.join(); + // EXAM_CHECK( val == 2 ); + // val = 0; + + return EXAM_RESULT; +} + Added: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.h =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.h (rev 0) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.h 2008-04-22 11:42:53 UTC (rev 1847) @@ -0,0 +1,18 @@ +// -*- C++ -*- Time-stamp: <08/02/25 12:12:20 ptr> + + +#ifndef __MY_TEST_H +#define __MY_TEST_H + +#define FIT_EXAM + +#include <exam/suite.h> +// #include <mt/shm.h> + +class my_test +{ + public: + int EXAM_DECL(thread_call); +}; + +#endif // __MY_TEST_H Added: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test_suite.cc =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test_suite.cc (rev 0) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test_suite.cc 2008-04-22 11:42:53 UTC (rev 1847) @@ -0,0 +1,16 @@ +// -*- C++ -*- Time-stamp: <08/03/26 10:12:21 ptr> + +#include "my_test_suite.h" +#include "my_test.h" + +#include <config/feature.h> + +int EXAM_IMPL(my_test_suite) +{ + exam::test_suite t( "my test" ); + my_test test; + + t.add( &my_test::thread_call, test, "my_test::thread_call" ); + + return t.girdle(); +}; Added: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test_suite.h =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test_suite.h (rev 0) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test_suite.h 2008-04-22 11:42:53 UTC (rev 1847) @@ -0,0 +1,10 @@ +// -*- C++ -*- Time-stamp: <07/07/16 22:08:39 ptr> + +#ifndef __MY_TEST_SUITE_H +#define __MY_TEST_SUITE_H + +#include <exam/suite.h> + +int EXAM_DECL(my_test_suite); + +#endif // __MY_TEST_SUITE_H Added: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/unit_test.cc =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/unit_test.cc (rev 0) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/unit_test.cc 2008-04-22 11:42:53 UTC (rev 1847) @@ -0,0 +1,11 @@ +// -*- C++ -*- Time-stamp: <07/07/16 22:12:10 ptr> + +#include <exam/suite.h> +#include <config/feature.h> + +#include "my_test_suite.h" + +int main( int, char ** ) +{ + return my_test_suite(0); +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <com...@us...> - 2008-04-23 09:22:17
|
Revision: 1853 http://complement.svn.sourceforge.net/complement/?rev=1853&view=rev Author: complement Date: 2008-04-23 02:22:13 -0700 (Wed, 23 Apr 2008) Log Message: ----------- compiled with modern xmt/date_time Modified Paths: -------------- trunk/complement/explore/app/SMTP-tools/DoSclient/Makefile trunk/complement/explore/app/SMTP-tools/smtp-ut/smtp-batch/Makefile trunk/complement/explore/app/SMTP-tools/smtp-ut/smtp-batch/smtp-batch.cc Property Changed: ---------------- trunk/complement/explore/app/SMTP-tools/smtp-ut/smtp-batch/ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/ Modified: trunk/complement/explore/app/SMTP-tools/DoSclient/Makefile =================================================================== --- trunk/complement/explore/app/SMTP-tools/DoSclient/Makefile 2008-04-23 09:20:23 UTC (rev 1852) +++ trunk/complement/explore/app/SMTP-tools/DoSclient/Makefile 2008-04-23 09:22:13 UTC (rev 1853) @@ -1,4 +1,4 @@ -# -*- Makefile -*- Time-stamp: <08/04/23 09:38:04 ptr> +# -*- Makefile -*- Time-stamp: <08/04/23 09:48:37 ptr> SRCROOT := ../../.. @@ -13,7 +13,7 @@ # LIBFS_DIR = ${CoMT_DIR}/../extern/custom/boost/libs/filesystem DEFS += -D_NO_TEST -INCLUDES += -I$(SRCROOT)/include -I$(STLPORT_INCLUDE_DIR) -I$(BOOST_INCLUDE_DIR) +INCLUDES += -I$(SRCROOT)/include -I$(BOOST_INCLUDE_DIR) release-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR} -L${LIBSOCKIOS_DIR}/${OUTPUT_DIR} -L${LIBMISC_DIR}/${OUTPUT_DIR} dbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_DBG} -L${LIBSOCKIOS_DIR}/${OUTPUT_DIR_DBG} -L${LIBMISC_DIR}/${OUTPUT_DIR_DBG} Property changes on: trunk/complement/explore/app/SMTP-tools/smtp-ut/smtp-batch ___________________________________________________________________ Name: svn:ignore + obj Modified: trunk/complement/explore/app/SMTP-tools/smtp-ut/smtp-batch/Makefile =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp-ut/smtp-batch/Makefile 2008-04-23 09:20:23 UTC (rev 1852) +++ trunk/complement/explore/app/SMTP-tools/smtp-ut/smtp-batch/Makefile 2008-04-23 09:22:13 UTC (rev 1853) @@ -1,28 +1,26 @@ # -*- Makefile -*- Time-stamp: <04/05/06 14:30:08 ptr> -# $Id: Makefile,v 1.1 2004/06/16 14:24:07 ptr Exp $ -#SRCROOT := ../../../../extern/complement -SRCROOT := ../../../../../../island/workshop/explore -COMPILER_NAME := gcc +SRCROOT := ../../../.. include Makefile.inc -include ${SRCROOT}/Makefiles/top.mak +include ${SRCROOT}/Makefiles/gmake/top.mak +LIBMT_DIR = ${CoMT_DIR}/lib/mt +LIBSOCKIOS_DIR = ${CoMT_DIR}/lib/sockios +LIBMISC_DIR = ${CoMT_DIR}/lib/misc +LIBBOOSTRE_DIR = ${CoMT_DIR}/../extern/custom/boost/lib/regex DEFS += -D_NO_TEST -INCLUDES += -I$(SRCROOT)/include -I$(STLPORT_INCLUDE_DIR) -I$(BOOST_INCLUDE_DIR) +INCLUDES += -I$(SRCROOT)/include -I$(BOOST_INCLUDE_DIR) -release-shared: LDSEARCH = -L${STLPORT_LIB_DIR} -L${CoMT_LIB_DIR} -Wl,-rpath=${STLPORT_LIB_DIR} -stldbg-shared: LDSEARCH = -L${STLPORT_LIB_DIR} -L${CoMT_LIB_DIR_STLDBG} -Wl,-rpath=${STLPORT_LIB_DIR} -dbg-shared: LDSEARCH = -L${STLPORT_LIB_DIR} -L${CoMT_LIB_DIR_DBG} -Wl,-rpath=${STLPORT_LIB_DIR} - -ifeq ($(OSNAME),sunos) -release-shared : LDLIBS = -lstlport_gcc -lrt -stldbg-shared : LDLIBS = -lstlport_gcc_stldebug -lrt -dbg-shared : LDLIBS = -lstlport_gcc_debug -lrt -else -release-shared : LDLIBS = -lstlport_gcc -lxmt_gcc -lsockios_gcc -lmisc_gcc -lboost_regex_gcc -stldbg-shared : LDLIBS = -lstlport_gcc_stldebug -lxmt_gcc_stl-g -lsockios_gcc_stl-g -lmisc_gcc_stl-g -lboost_regex_gcc_stl-g -dbg-shared : LDLIBS = -lstlport_gcc_debug -lxmt_gcc-g -lsockios_gcc-g -lmisc_gcc-g -lboost_regex_gcc-g +release-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR} -L${LIBSOCKIOS_DIR}/${OUTPUT_DIR} -L${LIBMISC_DIR}/${OUTPUT_DIR} -L$(LIBBOOSTRE_DIR)/${OUTPUT_DIR} +dbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_DBG} -L${LIBSOCKIOS_DIR}/${OUTPUT_DIR_DBG} -L${LIBMISC_DIR}/${OUTPUT_DIR_DBG} -L$(LIBBOOSTRE_DIR)/${OUTPUT_DIR_DBG} +ifndef WITHOUT_STLPORT +stldbg-shared: LDSEARCH += -L${LIBMT_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBSOCKIOS_DIR}/${OUTPUT_DIR_STLDBG} -L${LIBMISC_DIR}/${OUTPUT_DIR_STLDBG} -L$(LIBBOOSTRE_DIR)/${OUTPUT_DIR_STLDBG} endif +release-shared : LDLIBS += -lxmt -lsockios -lmisc -lboost_regex +dbg-shared : LDLIBS += -lxmtg -lsockiosg -lmiscg -lboost_regexg +ifndef WITHOUT_STLPORT +stldbg-shared: LDLIBS += -lxmtstlg -lsockiosstl -lmiscstlg -lboost_regexstlg +endif Modified: trunk/complement/explore/app/SMTP-tools/smtp-ut/smtp-batch/smtp-batch.cc =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp-ut/smtp-batch/smtp-batch.cc 2008-04-23 09:20:23 UTC (rev 1852) +++ trunk/complement/explore/app/SMTP-tools/smtp-ut/smtp-batch/smtp-batch.cc 2008-04-23 09:22:13 UTC (rev 1853) @@ -1,16 +1,11 @@ // -*- C++ -*- Time-stamp: <04/06/16 12:51:35 ptr> -#ifdef __unix -# ifdef __HP_aCC -#pragma VERSIONID "@(#)$Id: smtp-batch.cc,v 1.1 2004/06/16 14:24:07 ptr Exp $" -# else -#ident "@(#)$Id: smtp-batch.cc,v 1.1 2004/06/16 14:24:07 ptr Exp $" -# endif -#endif +#include <mt/thread> +#include <mt/mutex> +#include <mt/condition_variable> +#include <mt/date_time> -#include <mt/xmt.h> -#include <mt/time.h> #include <sockios/sockstream> #include <misc/args.h> @@ -23,6 +18,7 @@ using namespace std; using namespace boost; +using namespace std::tr2; struct conn { @@ -68,7 +64,8 @@ map<command_type,string> CMD; sockstream tecol; -__impl::Condition tecol_ready; +mutex tecol_ready_lk; +condition_variable tecol_ready; void init_map() { @@ -405,14 +402,14 @@ send_flag = true; { stringstream ss; - timespec t; - __impl::Thread::gettime( &t ); - ss << t.tv_sec << "." + system_time t = get_system_time(); + ss << t.seconds_since_epoch() << "." << setiosflags(ios_base::right) << setfill('0') << setw(9) - << t.tv_nsec << "-" << my_host_name; + << (t.nanoseconds_since_epoch() - seconds(t.seconds_since_epoch()) ).count() << "-" << my_host_name; if ( !tecol.is_open() ) { + lock_guard<mutex> lk( tecol_ready_lk ); tecol.open( host.c_str(), port ); - tecol_ready.set( true ); + tecol_ready.notify_one(); }// else if ( host changed or port changed ) { // } tecol << "id=" << ss.str() << " " << "action=out" << endl; @@ -461,19 +458,17 @@ getline( ss, rest ); if ( !nodelay ) { istringstream str( rest ); - timespec t; - str >> t.tv_sec; + int tsec; + str >> tsec; + seconds sec( tsec ); + nanoseconds t( sec ); if ( !str.fail() ) { - if ( t.tv_sec > 0 ) { - t.tv_nsec = lrand48() % 2000000000; - if ( t.tv_nsec > 1000000000 ) { - --t.tv_sec; - t.tv_nsec -= 1000000000; - } + if ( sec.count() > 0 ) { + t += nanoseconds( (lrand48() % 2000000000) - 1000000000 ); } else { - t.tv_nsec = lrand48() % 1000000000; + t += nanoseconds( lrand48() % 1000000000 ); } - __impl::Thread::delay( &t ); + this_thread::sleep( t ); } } break; @@ -501,9 +496,10 @@ } } -int read_tecol( void * ) +void read_tecol() { - tecol_ready.try_wait(); + unique_lock<mutex> lk( tecol_ready_lk ); + tecol_ready.wait( lk ); string s; @@ -513,8 +509,6 @@ cout << s << endl; } } - - return 0; } int main( int argc, char * const *argv ) @@ -524,7 +518,7 @@ try { Argv arg; - arg.copyright( "Copyright (C) K sky Lab, 2003, 2004" ); + arg.copyright( "Copyright (C) Petr Ovtchenkov 2003, 2004, 2008" ); arg.brief( "Mail script interpreter" ); arg.option( "-h", false, "print this help message" ); arg.option( "-f", string( "" ), "script file, default stdin" ); @@ -547,10 +541,8 @@ string fname; arg.assign( "-f", fname ); - tecol_ready.set( false ); + basic_thread<thread_base::detached,0> t( read_tecol ); - __impl::Thread t( read_tecol, 0, 0, __impl::Thread::detached ); - if ( fname.length() != 0 ) { ifstream script( fname.c_str() ); interpret( script, arg ); Property changes on: trunk/complement/explore/app/SMTP-tools/smtp_server_ut ___________________________________________________________________ Name: svn:ignore + obj This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |