| |
| #include "ServerOptions.h" |
| #include <boost/foreach.hpp> |
| #include <string> |
| namespace Moses |
| { |
|
|
| |
| |
| |
| |
| |
| size_t |
| parse_timespec(std::string const& spec) |
| { |
| size_t t = 0, timeout = 0; |
| BOOST_FOREACH(char const& c, spec) |
| { |
| if (c >= '0' && c <= '9') |
| { |
| t = t * 10 + c - '0'; |
| } |
| else |
| { |
| if (c == 'd') timeout = t * 24 * 3600; |
| else if (c == 'h') timeout += t * 3600; |
| else if (c == 'm') timeout += t * 60; |
| else if (c == 's') timeout += t; |
| else UTIL_THROW2("Can't parse specification '" << spec |
| << " at " << HERE); |
| t = 0; |
| } |
| } |
| return timeout; |
| } |
|
|
| ServerOptions:: |
| ServerOptions() |
| : is_serial(false) |
| , numThreads(15) |
| , sessionTimeout(1800) |
| , sessionCacheSize(25) |
| , port(8080) |
| , maxConn(15) |
| , maxConnBacklog(15) |
| , keepaliveTimeout(15) |
| , keepaliveMaxConn(30) |
| , timeout(15) |
| { } |
|
|
| ServerOptions:: |
| ServerOptions(Parameter const& P) |
| { |
| init(P); |
| } |
|
|
| bool |
| ServerOptions:: |
| init(Parameter const& P) |
| { |
| |
| P.SetParameter(this->port, "server-port", 8080); |
| P.SetParameter(this->is_serial, "serial", false); |
| P.SetParameter(this->logfile, "server-log", std::string("/dev/null")); |
| P.SetParameter(this->numThreads, "threads", uint32_t(15)); |
|
|
| |
| |
| P.SetParameter(this->maxConn,"server-maxconn", 15); |
| P.SetParameter(this->maxConnBacklog,"server-maxconn-backlog", 15); |
| P.SetParameter(this->keepaliveTimeout,"server-keepalive-timeout", 15); |
| P.SetParameter(this->keepaliveMaxConn,"server-keepalive-maxconn", 30); |
| P.SetParameter(this->timeout,"server-timeout",15); |
|
|
| |
| std::string timeout_spec; |
| P.SetParameter(timeout_spec, "session-timeout",std::string("30m")); |
| this->sessionTimeout = parse_timespec(timeout_spec); |
| P.SetParameter(this->sessionCacheSize, "session-cache_size", size_t(25)); |
|
|
| return true; |
| } |
| } |
|
|