From be2a5a80e770d9ae5432306db6e2d8ef5d6b5f19 Mon Sep 17 00:00:00 2001 From: Carlos Daniel Ruvalcaba Valenzuela Date: Sat, 5 Apr 2008 13:53:09 -0700 Subject: [PATCH] Updated POP3 code for new ThreadWorker --- backends/protocol/pop3.cpp | 59 ++++++++++++++++------------------------------ tools/benchsmtp.py | 2 +- 2 files changed, 21 insertions(+), 40 deletions(-) diff --git a/backends/protocol/pop3.cpp b/backends/protocol/pop3.cpp index a7fd611..dca0449 100644 --- a/backends/protocol/pop3.cpp +++ b/backends/protocol/pop3.cpp @@ -74,10 +74,11 @@ int knhash(char v){ return 255; } -class POP3Handler : public ProtocolHandler { +class POP3Handler : public Job { SearchTree cmdtree; + Socket * s; public: - POP3Handler(){ + POP3Handler(Socket *sock) : Job() { /* Insert POP3 commands to search tree, 4 letters only for optimization */ cmdtree.Insert("USER", 1); cmdtree.Insert("PASS", 2); @@ -91,20 +92,24 @@ public: cmdtree.Insert("TOP", 10); cmdtree.Insert("CAPA", 11); printf("SearchTree Memory Usage: %i bytes\n", cmdtree.getTreeSize()); + this->s = sock; } - int Handle(Socket * s){ + ~POP3Handler(){ + delete s; + } + int Run(){ char buffer[255]; //char userbuff[255]; //char outbuff[255]; int r, i, j; int onrun, cmd, state; - IPC * ipc, * ipcmb; - IPCMessage * msg; + //IPC * ipc, * ipcmb; + //IPCMessage * msg; string user, pass; pcrecpp::RE reg("[\\w\\a]*\\s([\\w\\a]*)"); - ipc = IPC::CreateIPC("socket://127.0.0.1:14000"); - ipcmb = IPC::CreateIPC("socket://127.0.0.1:14001"); + //ipc = IPC::CreateIPC("socket://127.0.0.1:14000"); + //ipcmb = IPC::CreateIPC("socket://127.0.0.1:14001"); /* Send greeting to client */ s->Write(welcome, strlen(welcome)); @@ -161,26 +166,7 @@ public: printf("Got Password: %s\n", pass.c_str()); - /* Request IPC Session with authentication server */ - i = 0; - while (i < 10){ - if (ipc->RequestIPC()) - i = 10; - } - - /* Send the auth message */ - msg = new IPCMessage("auth"); - msg->PushParam((char *)user.c_str()); - msg->PushParam((char *)pass.c_str()); - ipc->PushMessage(msg); - - while(ipc->PeekMessage() == 0){ - } - msg = ipc->PopMessage(); - - ipc->CloseIPC(); - - if (!strcmp(msg->GetMessageName(), "authok")){ + if (1){ s->Write( "+OK", 3); s->Write( CRLF, 2); @@ -289,10 +275,8 @@ public: break; } } - printf("Closing Connection\n"); + s->Close(); - delete ipcmb; - delete ipc; return 0; } }; @@ -307,16 +291,14 @@ public: }; int main(){ - //BaseServer *srv; - //SimpleLoad *lh; - POP3Handler * pop3; Socket * s, * client; - ThreadLoad * tlh; + Boss *boss; int ret; /* Create our POP3 Handler and Threaded Load Handler */ - pop3 = new POP3Handler(); - tlh = new ThreadLoad(pop3); + //pop3 = new POP3Handler(); + //tlh = new ThreadLoad(pop3); + boss = new Boss(10); /* Create and bind our socket to POP3 port */ s = Socket::CreateSocket(SOCKET_INET, 0); @@ -332,15 +314,14 @@ int main(){ if (ret & SOCKET_POLL_READ){ /* Accept client and dispatch */ client = s->Accept(); - tlh->Dispatch(client, pop3); + boss->Dispatch(new POP3Handler(client)); } else if(ret & SOCKET_POLL_ERROR){ //error return -1; } else{ //timeout break; } } - delete tlh; - delete pop3; + delete boss; return 0; } diff --git a/tools/benchsmtp.py b/tools/benchsmtp.py index a91de12..8617bed 100755 --- a/tools/benchsmtp.py +++ b/tools/benchsmtp.py @@ -9,7 +9,7 @@ SMTP_PORT = 12000 MSG_SIZE = 256 MSG_COUNT = 100 #Messages to Send per Test CONN_COUNT = 20 #Messages to send on Connection test, beware it could be slow -THREAD_COUNT = [2, 5, 10] +THREAD_COUNT = [2, 5, 10] #, 15, 20, 25, 30, 50, 75, 100] MSG_FROM = 'testmail@mymail.com' MSG_TO = 'testuser@localhost' -- 2.11.4.GIT