Merge pull request #400 from karlr42/develop

Support for Priority attribute in Cookies / TCPServer improvments.
This commit is contained in:
Günter Obiltschnig
2014-03-07 17:48:14 +01:00
9 changed files with 90 additions and 3 deletions

View File

@@ -139,10 +139,16 @@ public:
void setPath(const std::string& path);
/// Sets the path for the cookie.
void setPriority(const std::string& priority);
/// Sets the priority for the cookie.
const std::string& getPath() const;
/// Returns the path for the cookie.
const std::string& getPriority() const;
/// Returns the priority for the cookie.
void setSecure(bool secure);
/// Sets the value of the secure flag for
/// the cookie.
@@ -210,6 +216,7 @@ private:
std::string _comment;
std::string _domain;
std::string _path;
std::string _priority;
bool _secure;
int _maxAge;
bool _httpOnly;
@@ -254,6 +261,11 @@ inline const std::string& HTTPCookie::getPath() const
return _path;
}
inline const std::string& HTTPCookie::getPriority() const
{
return _priority;
}
inline bool HTTPCookie::getSecure() const
{

View File

@@ -162,6 +162,9 @@ public:
int currentThreads() const;
/// Returns the number of currently used connection threads.
int maxThreads() const;
/// Returns the maximum number of threads available.
int totalConnections() const;
/// Returns the total number of handled connections.

View File

@@ -85,6 +85,9 @@ public:
int currentThreads() const;
/// Returns the number of currently used threads.
int maxThreads() const;
/// Returns the maximum number of threads available.
int totalConnections() const;
/// Returns the total number of handled connections.

View File

@@ -102,6 +102,10 @@ HTTPCookie::HTTPCookie(const NameValueCollection& nvc):
{
setPath(value);
}
else if (icompare(name, "Priority") == 0)
{
setPriority(value);
}
else if (icompare(name, "max-age") == 0)
{
setMaxAge(NumberParser::parse(value));
@@ -152,6 +156,7 @@ HTTPCookie::HTTPCookie(const HTTPCookie& cookie):
_comment(cookie._comment),
_domain(cookie._domain),
_path(cookie._path),
_priority(cookie._priority),
_secure(cookie._secure),
_maxAge(cookie._maxAge),
_httpOnly(cookie._httpOnly)
@@ -174,6 +179,7 @@ HTTPCookie& HTTPCookie::operator = (const HTTPCookie& cookie)
_comment = cookie._comment;
_domain = cookie._domain;
_path = cookie._path;
_priority = cookie._priority;
_secure = cookie._secure;
_maxAge = cookie._maxAge;
_httpOnly = cookie._httpOnly;
@@ -217,6 +223,11 @@ void HTTPCookie::setPath(const std::string& path)
_path = path;
}
void HTTPCookie::setPriority(const std::string& priority)
{
_priority = priority;
}
void HTTPCookie::setSecure(bool secure)
{
@@ -256,6 +267,11 @@ std::string HTTPCookie::toString() const
result.append("; path=");
result.append(_path);
}
if (!_priority.empty())
{
result.append("; Priority=");
result.append(_priority);
}
if (_maxAge != -1)
{
Timestamp ts;
@@ -296,6 +312,13 @@ std::string HTTPCookie::toString() const
result.append(_path);
result.append("\"");
}
if (!_priority.empty())
{
result.append("; Priority=\"");
result.append(_priority);
result.append("\"");
}
if (_maxAge != -1)
{
result.append("; Max-Age=\"");

View File

@@ -52,19 +52,25 @@ namespace Net {
TCPServer::TCPServer(TCPServerConnectionFactory::Ptr pFactory, Poco::UInt16 portNumber, TCPServerParams::Ptr pParams):
_socket(ServerSocket(portNumber)),
_pDispatcher(new TCPServerDispatcher(pFactory, Poco::ThreadPool::defaultPool(), pParams)),
_thread(threadName(_socket)),
_stopped(true)
{
Poco::ThreadPool& pool = Poco::ThreadPool::defaultPool();
if(pParams) pool.addCapacity(pParams->getMaxThreads() - pool.capacity());
_pDispatcher = new TCPServerDispatcher(pFactory, pool, pParams);
}
TCPServer::TCPServer(TCPServerConnectionFactory::Ptr pFactory, const ServerSocket& socket, TCPServerParams::Ptr pParams):
_socket(socket),
_pDispatcher(new TCPServerDispatcher(pFactory, Poco::ThreadPool::defaultPool(), pParams)),
_thread(threadName(socket)),
_stopped(true)
{
Poco::ThreadPool& pool = Poco::ThreadPool::defaultPool();
if(pParams) pool.addCapacity(pParams->getMaxThreads() - pool.capacity());
_pDispatcher = new TCPServerDispatcher(pFactory, pool, pParams);
}
@@ -146,6 +152,11 @@ int TCPServer::currentThreads() const
return _pDispatcher->currentThreads();
}
int TCPServer::maxThreads() const
{
return _pDispatcher->maxThreads();
}
int TCPServer::totalConnections() const
{

View File

@@ -197,6 +197,13 @@ int TCPServerDispatcher::currentThreads() const
return _currentThreads;
}
int TCPServerDispatcher::maxThreads() const
{
FastMutex::ScopedLock lock(_mutex);
return _threadPool.capacity();
}
int TCPServerDispatcher::totalConnections() const
{

View File

@@ -80,8 +80,15 @@ void HTTPCookieTest::testCookie()
assert (cookie.toString() == "name=value; domain=appinf.com; path=/; secure");
cookie.setHttpOnly(true);
assert (cookie.toString() == "name=value; domain=appinf.com; path=/; secure; HttpOnly");
cookie.setPriority("Low");
assert (cookie.toString() == "name=value; domain=appinf.com; path=/; Priority=Low; secure; HttpOnly");
cookie.setPriority("Medium");
assert (cookie.toString() == "name=value; domain=appinf.com; path=/; Priority=Medium; secure; HttpOnly");
cookie.setPriority("High");
assert (cookie.toString() == "name=value; domain=appinf.com; path=/; Priority=High; secure; HttpOnly");
cookie.setPriority("");
cookie.setHttpOnly(false);
cookie.setVersion(1);
assert (cookie.toString() == "name=\"value\"; Comment=\"comment\"; Domain=\"appinf.com\"; Path=\"/\"; secure; Version=\"1\"");
@@ -91,6 +98,14 @@ void HTTPCookieTest::testCookie()
cookie.setHttpOnly(true);
assert (cookie.toString() == "name=\"value\"; Comment=\"comment\"; Domain=\"appinf.com\"; Path=\"/\"; Max-Age=\"100\"; HttpOnly; Version=\"1\"");
cookie.setPriority("Low");
assert (cookie.toString() == "name=\"value\"; Comment=\"comment\"; Domain=\"appinf.com\"; Path=\"/\"; Priority=\"Low\"; Max-Age=\"100\"; HttpOnly; Version=\"1\"");
cookie.setPriority("Medium");
assert (cookie.toString() == "name=\"value\"; Comment=\"comment\"; Domain=\"appinf.com\"; Path=\"/\"; Priority=\"Medium\"; Max-Age=\"100\"; HttpOnly; Version=\"1\"");
cookie.setPriority("High");
assert (cookie.toString() == "name=\"value\"; Comment=\"comment\"; Domain=\"appinf.com\"; Path=\"/\"; Priority=\"High\"; Max-Age=\"100\"; HttpOnly; Version=\"1\"");
}

View File

@@ -175,6 +175,7 @@ void TCPServerTest::testMultiConnections()
srv.start();
assert (srv.currentConnections() == 0);
assert (srv.currentThreads() == 0);
assert (srv.maxThreads() >= 4);
assert (srv.queuedConnections() == 0);
assert (srv.totalConnections() == 0);
@@ -252,6 +253,16 @@ void TCPServerTest::testMultiConnections()
assert (srv.currentConnections() == 0);
}
void TCPServerTest::testThreadCapacity(){
ServerSocket svs(0);
TCPServerParams* pParams = new TCPServerParams;
pParams->setMaxThreads(64);
TCPServer srv(new TCPServerConnectionFactoryImpl<EchoConnection>(), svs, pParams);
srv.start();
assert (srv.maxThreads() >= 64);
}
void TCPServerTest::setUp()
{
@@ -270,6 +281,7 @@ CppUnit::Test* TCPServerTest::suite()
CppUnit_addTest(pSuite, TCPServerTest, testOneConnection);
CppUnit_addTest(pSuite, TCPServerTest, testTwoConnections);
CppUnit_addTest(pSuite, TCPServerTest, testMultiConnections);
CppUnit_addTest(pSuite, TCPServerTest, testThreadCapacity);
return pSuite;
}

View File

@@ -49,6 +49,7 @@ public:
void testOneConnection();
void testTwoConnections();
void testMultiConnections();
void testThreadCapacity();
void setUp();
void tearDown();