00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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 }