SMTPServer.cc

Go to the documentation of this file.
00001 /*
00002  *    Copyright 2005-2006 Intel Corporation
00003  * 
00004  *    Licensed under the Apache License, Version 2.0 (the "License");
00005  *    you may not use this file except in compliance with the License.
00006  *    You may obtain a copy of the License at
00007  * 
00008  *        http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  *    Unless required by applicable law or agreed to in writing, software
00011  *    distributed under the License is distributed on an "AS IS" BASIS,
00012  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  *    See the License for the specific language governing permissions and
00014  *    limitations under the License.
00015  */
00016 
00017 
00018 #include "SMTPServer.h"
00019 
00020 namespace oasys {
00021 
00022 //----------------------------------------------------------------------------
00023 SMTPServer::SMTPServer(const SMTP::Config& config,
00024                        SMTPHandlerFactory* handler_factory,
00025                        Notifier*           session_done,
00026                        int                 accept_timeout)
00027     : TCPServerThread("SMTPServer", "/smtp/server", 0, accept_timeout),
00028       config_(config),
00029       handler_factory_(handler_factory),
00030       session_done_(session_done)
00031 {
00032     logpathf("/smtp/server/%s:%d", intoa(config.addr_), config.port_);
00033     bind_listen_start(config.addr_, config.port_);
00034 }
00035 
00036 //----------------------------------------------------------------------------
00037 void
00038 SMTPServer::accepted(int fd, in_addr_t addr, u_int16_t port)
00039 {
00040     (void)addr;
00041     (void)port;
00042     SMTPHandler* handler = handler_factory_->new_handler();
00043     SMTPHandlerThread* thread =
00044         new SMTPHandlerThread(handler, fd, fd, config_, session_done_);
00045     thread->start();
00046 }
00047 
00048 //----------------------------------------------------------------------------
00049 SMTPHandlerThread::SMTPHandlerThread(SMTPHandler* handler,
00050                                      int fd_in, int fd_out,
00051                                      const SMTP::Config& config,
00052                                      Notifier* session_done)
00053     : Thread("/smtp/server", DELETE_ON_EXIT),
00054       handler_(handler),
00055       fdio_in_(fd_in), fdio_out_(fd_out),
00056       in_(&fdio_in_), out_(&fdio_out_),
00057       smtp_(&in_, &out_, config, "/smtp/server"),
00058       session_done_(session_done)
00059 {
00060 }
00061 
00062 //----------------------------------------------------------------------------
00063 SMTPHandlerThread::~SMTPHandlerThread()
00064 {
00065     delete handler_;
00066     handler_ = 0;
00067 }
00068 
00069 //----------------------------------------------------------------------------
00070 void
00071 SMTPHandlerThread::run()
00072 {
00073     smtp_.server_session(handler_);
00074     if (session_done_) {
00075         session_done_->notify();
00076     }
00077 }
00078 
00079 } // namespace oasys

Generated on Sat Sep 8 08:36:18 2007 for DTN Reference Implementation by  doxygen 1.5.3