00001
00002 #include "ServerOptions.h"
00003 #include <boost/foreach.hpp>
00004 #include <string>
00005 namespace Moses
00006 {
00007
00008
00009
00010
00011
00012
00013 size_t
00014 parse_timespec(std::string const& spec)
00015 {
00016 size_t t = 0, timeout = 0;
00017 BOOST_FOREACH(char const& c, spec)
00018 {
00019 if (c >= '0' && c <= '9')
00020 {
00021 t = t * 10 + c - '0';
00022 }
00023 else
00024 {
00025 if (c == 'd') timeout = t * 24 * 3600;
00026 else if (c == 'h') timeout += t * 3600;
00027 else if (c == 'm') timeout += t * 60;
00028 else if (c == 's') timeout += t;
00029 else UTIL_THROW2("Can't parse specification '" << spec
00030 << " at " << HERE);
00031 t = 0;
00032 }
00033 }
00034 return timeout;
00035 }
00036
00037 ServerOptions::
00038 ServerOptions()
00039 : is_serial(false)
00040 , numThreads(15)
00041 , sessionTimeout(1800)
00042 , sessionCacheSize(25)
00043 , port(8080)
00044 , maxConn(15)
00045 , maxConnBacklog(15)
00046 , keepaliveTimeout(15)
00047 , keepaliveMaxConn(30)
00048 , timeout(15)
00049 { }
00050
00051 ServerOptions::
00052 ServerOptions(Parameter const& P)
00053 {
00054 init(P);
00055 }
00056
00057 bool
00058 ServerOptions::
00059 init(Parameter const& P)
00060 {
00061
00062 P.SetParameter(this->port, "server-port", 8080);
00063 P.SetParameter(this->is_serial, "serial", false);
00064 P.SetParameter(this->logfile, "server-log", std::string("/dev/null"));
00065 P.SetParameter(this->numThreads, "threads", uint32_t(15));
00066
00067
00068
00069 P.SetParameter(this->maxConn,"server-maxconn", 15);
00070 P.SetParameter(this->maxConnBacklog,"server-maxconn-backlog", 15);
00071 P.SetParameter(this->keepaliveTimeout,"server-keepalive-timeout", 15);
00072 P.SetParameter(this->keepaliveMaxConn,"server-keepalive-maxconn", 30);
00073 P.SetParameter(this->timeout,"server-timeout",15);
00074
00075
00076 std::string timeout_spec;
00077 P.SetParameter(timeout_spec, "session-timeout",std::string("30m"));
00078 this->sessionTimeout = parse_timespec(timeout_spec);
00079 P.SetParameter(this->sessionCacheSize, "session-cache_size", size_t(25));
00080
00081 return true;
00082 }
00083 }