mirror of
https://github.com/pocoproject/poco.git
synced 2025-02-20 14:24:35 +01:00
ported 1.4.4 branch changes (needs build checks and test runs!)
This commit is contained in:
parent
e5e3a57baf
commit
9b952a29c7
19
CHANGELOG
19
CHANGELOG
@ -23,7 +23,24 @@ Release 1.4.4 (2012-04-??)
|
||||
handshake is enabled and the first attempt to complete the handshake fails
|
||||
- Poco::DateTimeParser::tryParse() without format specifier now correctly parses ISO8601
|
||||
date/times with fractional seconds.
|
||||
|
||||
- Poco::Process::launch() now has additional overloads allowing to specify an initial
|
||||
directory and/or environment.
|
||||
- Poco::Net::FTPClientSession: timeout was not applied to data connection, only to
|
||||
control connection.
|
||||
- Fixed potential IPv6 issue with socket constructors if IPv6 SocketAddress is given
|
||||
(contributed by ??????? ????????? <milovidov@yandex-team.ru>).
|
||||
- Added an additional (optional) parameter to Poco::Thread::setOSPriority() allowing to
|
||||
specify a scheduling policy. Currently this is only used on POSIX platforms and allows
|
||||
specifying SCHED_OTHER (default), SCHED_FIFO or SCHED_RR, as well as other
|
||||
platform-specific policy values.
|
||||
- Added Poco::Crypto::DigestEngine class providing a Poco::DigestEngine interface to
|
||||
the digest algorithms provided by OpenSSL.
|
||||
- Fixed some potential compiler warnings in Crypto library
|
||||
- In some cases, when an SSL exception was unexpectedly closed, a generic Poco::IOException
|
||||
was thrown. This was fixed to throw a SSLConnectionUnexpectedlyClosedException instead.
|
||||
- Added Poco::ObjectPool class template.
|
||||
- Poco::Net::HTTPServer has a new stopAll() method allowing stopping/aborting of all
|
||||
currently active client connections.
|
||||
|
||||
Release 1.4.3p1 (2012-01-23)
|
||||
============================
|
||||
|
@ -518,6 +518,19 @@
|
||||
RelativePath=".\src\OpenSSLInitializer.cpp"/>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Digest">
|
||||
<Filter
|
||||
Name="Header Files">
|
||||
<File
|
||||
RelativePath=".\include\Poco\Crypto\DigestEngine.h"/>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Source Files">
|
||||
<File
|
||||
RelativePath=".\src\DigestEngine.cpp"/>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<File
|
||||
RelativePath="..\DLLVersion.rc">
|
||||
<FileConfiguration
|
||||
|
@ -450,6 +450,19 @@
|
||||
RelativePath=".\src\OpenSSLInitializer.cpp"/>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Digest">
|
||||
<Filter
|
||||
Name="Header Files">
|
||||
<File
|
||||
RelativePath=".\include\Poco\Crypto\DigestEngine.h"/>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Source Files">
|
||||
<File
|
||||
RelativePath=".\src\DigestEngine.cpp"/>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<File
|
||||
RelativePath="..\DLLVersion.rc">
|
||||
<FileConfiguration
|
||||
|
@ -471,6 +471,19 @@
|
||||
RelativePath=".\src\OpenSSLInitializer.cpp"/>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Digest">
|
||||
<Filter
|
||||
Name="Header Files">
|
||||
<File
|
||||
RelativePath=".\include\Poco\Crypto\DigestEngine.h"/>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Source Files">
|
||||
<File
|
||||
RelativePath=".\src\DigestEngine.cpp"/>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<File
|
||||
RelativePath="..\DLLVersion.rc">
|
||||
<FileConfiguration
|
||||
|
@ -470,6 +470,19 @@
|
||||
RelativePath=".\src\OpenSSLInitializer.cpp"/>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Digest">
|
||||
<Filter
|
||||
Name="Header Files">
|
||||
<File
|
||||
RelativePath=".\include\Poco\Crypto\DigestEngine.h"/>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Source Files">
|
||||
<File
|
||||
RelativePath=".\src\DigestEngine.cpp"/>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<File
|
||||
RelativePath="..\DLLVersion.rc">
|
||||
<FileConfiguration
|
||||
|
@ -281,6 +281,7 @@
|
||||
<ClInclude Include="include\Poco\Crypto\X509Certificate.h" />
|
||||
<ClInclude Include="include\Poco\Crypto\Crypto.h" />
|
||||
<ClInclude Include="include\Poco\Crypto\OpenSSLInitializer.h" />
|
||||
<ClInclude Include="include\Poco\Crypto\DigestEngine.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\Cipher.cpp" />
|
||||
@ -296,6 +297,7 @@
|
||||
<ClCompile Include="src\RSAKeyImpl.cpp" />
|
||||
<ClCompile Include="src\X509Certificate.cpp" />
|
||||
<ClCompile Include="src\OpenSSLInitializer.cpp" />
|
||||
<ClCompile Include="src\DigestEngine.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="..\DLLVersion.rc">
|
||||
|
@ -2,40 +2,49 @@
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Cipher">
|
||||
<UniqueIdentifier>{47659d2b-1931-4b5c-a24e-1c710c742c4a}</UniqueIdentifier>
|
||||
<UniqueIdentifier>{817dcc42-c43d-448f-b6f4-682c7b9eebce}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Cipher\Header Files">
|
||||
<UniqueIdentifier>{0f1eef3f-f362-4856-abb6-d66fb7dafd00}</UniqueIdentifier>
|
||||
<UniqueIdentifier>{b9acfa88-5b37-438b-b02a-a0305d660abb}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Cipher\Source Files">
|
||||
<UniqueIdentifier>{16c5db31-64d0-415a-840b-bead16c5b4ed}</UniqueIdentifier>
|
||||
<UniqueIdentifier>{9a337c49-202e-44c6-96b5-544b0c568f31}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="RSA">
|
||||
<UniqueIdentifier>{f55ef5a1-fb9a-443a-9efa-ab2e272f8a5e}</UniqueIdentifier>
|
||||
<UniqueIdentifier>{92a5c4bb-ff46-465d-98e9-de53992f84f3}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="RSA\Header Files">
|
||||
<UniqueIdentifier>{6a4da578-c88b-4d4b-9f2c-bd2ee4fa2b7a}</UniqueIdentifier>
|
||||
<UniqueIdentifier>{a1fbc3f1-3626-46ba-afb2-04a076dc20e9}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="RSA\Source Files">
|
||||
<UniqueIdentifier>{16bf940b-4b9d-4443-8941-a0af3f2d8f8f}</UniqueIdentifier>
|
||||
<UniqueIdentifier>{a54fb963-33ef-4bdb-96ef-3008e5922b60}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Certificate">
|
||||
<UniqueIdentifier>{5301224c-5bed-44a9-9314-ca863aaf4fd8}</UniqueIdentifier>
|
||||
<UniqueIdentifier>{9b4b7e92-fcb9-42e6-979b-239432f7f7d5}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Certificate\Header Files">
|
||||
<UniqueIdentifier>{8184d9c6-ad90-4dd5-8091-1358ca4243c4}</UniqueIdentifier>
|
||||
<UniqueIdentifier>{5ffce66b-4bf8-4a66-b499-e28c798bb193}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Certificate\Source Files">
|
||||
<UniqueIdentifier>{25d75536-89a8-4888-b661-92983aa3d989}</UniqueIdentifier>
|
||||
<UniqueIdentifier>{e898392c-d0f3-40b5-88ce-8c39659ce83f}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="CryptoCore">
|
||||
<UniqueIdentifier>{21724220-39cd-4bd3-acbe-faa155cb88e1}</UniqueIdentifier>
|
||||
<UniqueIdentifier>{4cc14755-2ecd-4ebe-9f8d-916b11107ccb}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="CryptoCore\Header Files">
|
||||
<UniqueIdentifier>{891e2105-aa8f-43d8-b00e-f797fc044836}</UniqueIdentifier>
|
||||
<UniqueIdentifier>{d1a13755-0bbe-47bc-9235-7e85250fa75b}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="CryptoCore\Source Files">
|
||||
<UniqueIdentifier>{f1c93b38-00a2-4073-8750-171298a95e18}</UniqueIdentifier>
|
||||
<UniqueIdentifier>{49706855-ad39-4ff3-a3ef-ecc99c59c7d2}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Digest">
|
||||
<UniqueIdentifier>{25c9d0f5-3a6e-454e-a72e-77557cd02ad1}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Digest\Header Files">
|
||||
<UniqueIdentifier>{e939a817-2082-4c93-bd5d-6771b0706aa8}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Digest\Source Files">
|
||||
<UniqueIdentifier>{7dea865f-63e2-4135-b1d4-1113148896b3}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
@ -81,6 +90,9 @@
|
||||
<ClInclude Include="include\Poco\Crypto\OpenSSLInitializer.h">
|
||||
<Filter>CryptoCore\Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\Poco\Crypto\DigestEngine.h">
|
||||
<Filter>Digest\Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\Cipher.cpp">
|
||||
@ -122,6 +134,9 @@
|
||||
<ClCompile Include="src\OpenSSLInitializer.cpp">
|
||||
<Filter>CryptoCore\Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\DigestEngine.cpp">
|
||||
<Filter>Digest\Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="..\DLLVersion.rc" />
|
||||
|
@ -279,6 +279,7 @@
|
||||
<ClInclude Include="include\Poco\Crypto\X509Certificate.h"/>
|
||||
<ClInclude Include="include\Poco\Crypto\Crypto.h"/>
|
||||
<ClInclude Include="include\Poco\Crypto\OpenSSLInitializer.h"/>
|
||||
<ClInclude Include="include\Poco\Crypto\DigestEngine.h"/>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\Cipher.cpp"/>
|
||||
@ -294,6 +295,7 @@
|
||||
<ClCompile Include="src\RSAKeyImpl.cpp"/>
|
||||
<ClCompile Include="src\X509Certificate.cpp"/>
|
||||
<ClCompile Include="src\OpenSSLInitializer.cpp"/>
|
||||
<ClCompile Include="src\DigestEngine.cpp"/>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="..\DLLVersion.rc">
|
||||
|
@ -2,40 +2,49 @@
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Cipher">
|
||||
<UniqueIdentifier>{b173f1fe-9277-4bb7-a29a-784223cbb1bf}</UniqueIdentifier>
|
||||
<UniqueIdentifier>{0547bb78-91a3-42a6-98d7-eee4062fc96d}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Cipher\Header Files">
|
||||
<UniqueIdentifier>{ad6edcfa-4842-4331-86e4-00e16e105548}</UniqueIdentifier>
|
||||
<UniqueIdentifier>{6ee6b22f-ccff-4894-a138-aead4aa517e7}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Cipher\Source Files">
|
||||
<UniqueIdentifier>{05a9d2ec-4e64-45db-bfe0-4b5786e88a11}</UniqueIdentifier>
|
||||
<UniqueIdentifier>{73645c11-6227-4871-94e3-d77dd3f24291}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="RSA">
|
||||
<UniqueIdentifier>{88627b10-aeee-42c1-87c4-0ebfa2e0a79a}</UniqueIdentifier>
|
||||
<UniqueIdentifier>{ac1d2c15-a701-44b8-a5d0-53270a9b49fb}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="RSA\Header Files">
|
||||
<UniqueIdentifier>{ea6b402c-457a-4daf-b077-be45f2acd17f}</UniqueIdentifier>
|
||||
<UniqueIdentifier>{7d984e13-4192-4041-bdb1-728de0684d30}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="RSA\Source Files">
|
||||
<UniqueIdentifier>{fa65ca2d-a23e-4b8e-b922-9f0866057010}</UniqueIdentifier>
|
||||
<UniqueIdentifier>{a9be19c9-3057-48eb-a21f-a9591307ea36}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Certificate">
|
||||
<UniqueIdentifier>{c7a98e6b-b117-4abc-92c0-da57006d8404}</UniqueIdentifier>
|
||||
<UniqueIdentifier>{53333def-b74f-4969-b6eb-cf158a31e5d4}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Certificate\Header Files">
|
||||
<UniqueIdentifier>{2eb81bba-5786-4827-861c-79b9ce5282d1}</UniqueIdentifier>
|
||||
<UniqueIdentifier>{1c36d55a-2e79-4a52-83bb-df0ee7b973d5}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Certificate\Source Files">
|
||||
<UniqueIdentifier>{6809f384-8941-4b8f-837c-688c36e13184}</UniqueIdentifier>
|
||||
<UniqueIdentifier>{fd3b9e34-05c4-4754-b481-185dfe34e547}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="CryptoCore">
|
||||
<UniqueIdentifier>{68b4002c-3b8d-4807-a97e-8e8b886f7705}</UniqueIdentifier>
|
||||
<UniqueIdentifier>{1e012891-c009-45bb-aa3a-76abae9b9235}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="CryptoCore\Header Files">
|
||||
<UniqueIdentifier>{bb20da77-b634-4616-8448-4fcfd1b3b150}</UniqueIdentifier>
|
||||
<UniqueIdentifier>{97b573b3-41fe-489f-b74e-a29f3ca2cd1b}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="CryptoCore\Source Files">
|
||||
<UniqueIdentifier>{5737fdf4-ee47-4378-8cd3-812512176c75}</UniqueIdentifier>
|
||||
<UniqueIdentifier>{e8ea85fa-b22d-4850-a9a2-6c8390f6169d}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Digest">
|
||||
<UniqueIdentifier>{673a5ceb-4d21-4e09-b77f-4070077ac56d}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Digest\Header Files">
|
||||
<UniqueIdentifier>{ef4c04a0-8f67-4a3c-9a63-ceafdd5fa6e1}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Digest\Source Files">
|
||||
<UniqueIdentifier>{ab15490c-a15c-4d2b-b499-e292a6fc4502}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
@ -81,6 +90,9 @@
|
||||
<ClInclude Include="include\Poco\Crypto\OpenSSLInitializer.h">
|
||||
<Filter>CryptoCore\Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\Poco\Crypto\DigestEngine.h">
|
||||
<Filter>Digest\Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\Cipher.cpp">
|
||||
@ -122,6 +134,9 @@
|
||||
<ClCompile Include="src\OpenSSLInitializer.cpp">
|
||||
<Filter>CryptoCore\Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\DigestEngine.cpp">
|
||||
<Filter>Digest\Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="..\DLLVersion.rc" />
|
||||
|
@ -475,6 +475,19 @@
|
||||
RelativePath=".\src\OpenSSLInitializer.cpp"/>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Digest">
|
||||
<Filter
|
||||
Name="Header Files">
|
||||
<File
|
||||
RelativePath=".\include\Poco\Crypto\DigestEngine.h"/>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Source Files">
|
||||
<File
|
||||
RelativePath=".\src\DigestEngine.cpp"/>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<File
|
||||
RelativePath="..\DLLVersion.rc">
|
||||
<FileConfiguration
|
||||
|
@ -1,7 +1,7 @@
|
||||
#
|
||||
# Makefile
|
||||
#
|
||||
# $Id: //poco/1.4/Crypto/Makefile#1 $
|
||||
# $Id: //poco/1.4/Crypto/Makefile#2 $
|
||||
#
|
||||
# Makefile for Poco Crypto
|
||||
#
|
||||
@ -11,7 +11,7 @@ include $(POCO_BASE)/build/rules/global
|
||||
SYSLIBS += -lssl -lcrypto
|
||||
|
||||
objects = Cipher CipherFactory CipherImpl CipherKey CipherKeyImpl CryptoStream CryptoTransform \
|
||||
RSACipherImpl RSAKey RSAKeyImpl RSADigestEngine \
|
||||
RSACipherImpl RSAKey RSAKeyImpl RSADigestEngine DigestEngine \
|
||||
X509Certificate OpenSSLInitializer
|
||||
|
||||
target = PocoCrypto
|
||||
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// CipherKeyImpl.h
|
||||
//
|
||||
// $Id: //poco/1.4/Crypto/include/Poco/Crypto/CipherKeyImpl.h#2 $
|
||||
// $Id: //poco/1.4/Crypto/include/Poco/Crypto/CipherKeyImpl.h#3 $
|
||||
//
|
||||
// Library: Crypto
|
||||
// Package: Cipher
|
||||
@ -162,7 +162,7 @@ inline const CipherKeyImpl::ByteVec& CipherKeyImpl::getKey() const
|
||||
|
||||
inline void CipherKeyImpl::setKey(const ByteVec& key)
|
||||
{
|
||||
poco_assert(key.size() == keySize());
|
||||
poco_assert(key.size() == static_cast<ByteVec::size_type>(keySize()));
|
||||
_key = key;
|
||||
}
|
||||
|
||||
@ -175,7 +175,7 @@ inline const CipherKeyImpl::ByteVec& CipherKeyImpl::getIV() const
|
||||
|
||||
inline void CipherKeyImpl::setIV(const ByteVec& iv)
|
||||
{
|
||||
poco_assert(iv.size() == ivSize());
|
||||
poco_assert(iv.size() == static_cast<ByteVec::size_type>(ivSize()));
|
||||
_iv = iv;
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// CryptoTransform.h
|
||||
//
|
||||
// $Id: //poco/1.4/Crypto/include/Poco/Crypto/CryptoTransform.h#1 $
|
||||
// $Id: //poco/1.4/Crypto/include/Poco/Crypto/CryptoTransform.h#2 $
|
||||
//
|
||||
// Library: Crypto
|
||||
// Package: Cipher
|
||||
@ -66,6 +66,12 @@ public:
|
||||
virtual std::size_t blockSize() const = 0;
|
||||
/// Returns the block size for this CryptoTransform.
|
||||
|
||||
virtual int setPadding(int padding);
|
||||
/// Enables or disables padding. By default encryption operations are padded using standard block
|
||||
/// padding and the padding is checked and removed when decrypting. If the padding parameter is zero then
|
||||
/// no padding is performed, the total amount of data encrypted or decrypted must then be a multiple of
|
||||
/// the block size or an error will occur.
|
||||
|
||||
virtual std::streamsize transform(
|
||||
const unsigned char* input,
|
||||
std::streamsize inputLength,
|
||||
|
97
Crypto/include/Poco/Crypto/DigestEngine.h
Normal file
97
Crypto/include/Poco/Crypto/DigestEngine.h
Normal file
@ -0,0 +1,97 @@
|
||||
//
|
||||
// DigestEngine.h
|
||||
//
|
||||
// $Id: //poco/1.4/Crypto/include/Poco/Crypto/DigestEngine.h#1 $
|
||||
//
|
||||
// Library: Crypto
|
||||
// Package: Digest
|
||||
// Module: DigestEngine
|
||||
//
|
||||
// Definition of the DigestEngine class.
|
||||
//
|
||||
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Crypto_DigestEngine_INCLUDED
|
||||
#define Crypto_DigestEngine_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Crypto/Crypto.h"
|
||||
#include "Poco/DigestEngine.h"
|
||||
#include <openssl/evp.h>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Crypto {
|
||||
|
||||
|
||||
class Crypto_API DigestEngine: public Poco::DigestEngine
|
||||
/// This class implements a Poco::DigestEngine for all
|
||||
/// digest algorithms supported by OpenSSL.
|
||||
{
|
||||
public:
|
||||
DigestEngine(const std::string& name);
|
||||
/// Creates a DigestEngine using the digest with the given name
|
||||
/// (e.g., "MD5", "SHA1", "SHA256", "SHA512", etc.).
|
||||
/// See the OpenSSL documentation for a list of supported digest algorithms.
|
||||
///
|
||||
/// Throws a Poco::NotFoundException if no algorithm with the given name exists.
|
||||
|
||||
~DigestEngine();
|
||||
/// Destroys the DigestEngine.
|
||||
|
||||
const std::string& algorithm() const;
|
||||
/// Returns the name of the digest algorithm.
|
||||
|
||||
// DigestEngine
|
||||
unsigned digestLength() const;
|
||||
void reset();
|
||||
const Poco::DigestEngine::Digest& digest();
|
||||
|
||||
protected:
|
||||
void updateImpl(const void* data, unsigned length);
|
||||
|
||||
private:
|
||||
std::string _name;
|
||||
EVP_MD_CTX* _ctx;
|
||||
Poco::DigestEngine::Digest _digest;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline const std::string& DigestEngine::algorithm() const
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Crypto
|
||||
|
||||
|
||||
#endif // Crypto_DigestEngine_INCLUDED
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// CipherImpl.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Crypto/src/CipherImpl.cpp#2 $
|
||||
// $Id: //poco/1.4/Crypto/src/CipherImpl.cpp#3 $
|
||||
//
|
||||
// Library: Crypto
|
||||
// Package: Cipher
|
||||
@ -83,6 +83,8 @@ namespace
|
||||
|
||||
std::size_t blockSize() const;
|
||||
|
||||
int setPadding(int padding);
|
||||
|
||||
std::streamsize transform(
|
||||
const unsigned char* input,
|
||||
std::streamsize inputLength,
|
||||
@ -130,6 +132,12 @@ namespace
|
||||
return EVP_CIPHER_CTX_block_size(&_ctx);
|
||||
}
|
||||
|
||||
|
||||
int CryptoTransformImpl::setPadding(int padding)
|
||||
{
|
||||
return EVP_CIPHER_CTX_set_padding(&_ctx, padding);
|
||||
}
|
||||
|
||||
|
||||
std::streamsize CryptoTransformImpl::transform(
|
||||
const unsigned char* input,
|
||||
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// CryptoTransform.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Crypto/src/CryptoTransform.cpp#1 $
|
||||
// $Id: //poco/1.4/Crypto/src/CryptoTransform.cpp#2 $
|
||||
//
|
||||
// Library: Crypto
|
||||
// Package: Cipher
|
||||
@ -50,5 +50,11 @@ CryptoTransform::~CryptoTransform()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int CryptoTransform::setPadding(int padding)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Crypto
|
||||
|
93
Crypto/src/DigestEngine.cpp
Normal file
93
Crypto/src/DigestEngine.cpp
Normal file
@ -0,0 +1,93 @@
|
||||
//
|
||||
// DigestEngine.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Crypto/src/DigestEngine.cpp#1 $
|
||||
//
|
||||
// Library: Crypto
|
||||
// Package: Digest
|
||||
// Module: DigestEngine
|
||||
//
|
||||
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Crypto/DigestEngine.h"
|
||||
#include "Poco/Exception.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Crypto {
|
||||
|
||||
|
||||
DigestEngine::DigestEngine(const std::string& name):
|
||||
_name(name)
|
||||
{
|
||||
const EVP_MD* md = EVP_get_digestbyname(_name.c_str());
|
||||
if (!md) throw Poco::NotFoundException(_name);
|
||||
_ctx = EVP_MD_CTX_create();
|
||||
EVP_DigestInit_ex(_ctx, md, NULL);
|
||||
}
|
||||
|
||||
|
||||
DigestEngine::~DigestEngine()
|
||||
{
|
||||
EVP_MD_CTX_destroy(_ctx);
|
||||
}
|
||||
|
||||
|
||||
unsigned DigestEngine::digestLength() const
|
||||
{
|
||||
return EVP_MD_CTX_size(_ctx);
|
||||
}
|
||||
|
||||
|
||||
void DigestEngine::reset()
|
||||
{
|
||||
EVP_MD_CTX_cleanup(_ctx);
|
||||
const EVP_MD* md = EVP_get_digestbyname(_name.c_str());
|
||||
if (!md) throw Poco::NotFoundException(_name);
|
||||
EVP_DigestInit_ex(_ctx, md, NULL);
|
||||
}
|
||||
|
||||
|
||||
const Poco::DigestEngine::Digest& DigestEngine::digest()
|
||||
{
|
||||
_digest.clear();
|
||||
unsigned len = EVP_MD_CTX_size(_ctx);
|
||||
_digest.resize(len);
|
||||
EVP_DigestFinal_ex(_ctx, &_digest[0], &len);
|
||||
reset();
|
||||
return _digest;
|
||||
}
|
||||
|
||||
|
||||
void DigestEngine::updateImpl(const void* data, unsigned length)
|
||||
{
|
||||
EVP_DigestUpdate(_ctx, data, length);
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Crypto
|
@ -462,6 +462,10 @@
|
||||
Name="Header Files">
|
||||
<File
|
||||
RelativePath=".\src\CryptoTest.h"/>
|
||||
<File
|
||||
RelativePath=".\src\DigestEngineTest.cpp"/>
|
||||
<File
|
||||
RelativePath=".\src\DigestEngineTest.h"/>
|
||||
<File
|
||||
RelativePath=".\src\RSATest.h"/>
|
||||
</Filter>
|
||||
|
@ -397,6 +397,10 @@
|
||||
Name="Header Files">
|
||||
<File
|
||||
RelativePath=".\src\CryptoTest.h"/>
|
||||
<File
|
||||
RelativePath=".\src\DigestEngineTest.cpp"/>
|
||||
<File
|
||||
RelativePath=".\src\DigestEngineTest.h"/>
|
||||
<File
|
||||
RelativePath=".\src\RSATest.h"/>
|
||||
</Filter>
|
||||
|
@ -437,6 +437,10 @@
|
||||
Name="Header Files">
|
||||
<File
|
||||
RelativePath=".\src\CryptoTest.h"/>
|
||||
<File
|
||||
RelativePath=".\src\DigestEngineTest.cpp"/>
|
||||
<File
|
||||
RelativePath=".\src\DigestEngineTest.h"/>
|
||||
<File
|
||||
RelativePath=".\src\RSATest.h"/>
|
||||
</Filter>
|
||||
|
@ -437,6 +437,10 @@
|
||||
Name="Header Files">
|
||||
<File
|
||||
RelativePath=".\src\CryptoTest.h"/>
|
||||
<File
|
||||
RelativePath=".\src\DigestEngineTest.cpp"/>
|
||||
<File
|
||||
RelativePath=".\src\DigestEngineTest.h"/>
|
||||
<File
|
||||
RelativePath=".\src\RSATest.h"/>
|
||||
</Filter>
|
||||
|
@ -301,10 +301,12 @@
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\CryptoTest.h" />
|
||||
<ClInclude Include="src\DigestEngineTest.h" />
|
||||
<ClInclude Include="src\RSATest.h" />
|
||||
<ClInclude Include="src\CryptoTestSuite.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\DigestEngineTest.cpp" />
|
||||
<ClCompile Include="src\CryptoTest.cpp" />
|
||||
<ClCompile Include="src\RSATest.cpp" />
|
||||
<ClCompile Include="src\CryptoTestSuite.cpp" />
|
||||
|
@ -2,34 +2,37 @@
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Crypto">
|
||||
<UniqueIdentifier>{f51ea1c6-6658-406b-865b-fe589b2c895d}</UniqueIdentifier>
|
||||
<UniqueIdentifier>{d524e30f-84a5-4915-9547-cf79f659d4ec}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Crypto\Header Files">
|
||||
<UniqueIdentifier>{7359f2ae-daac-4520-a8a1-b351abb9365b}</UniqueIdentifier>
|
||||
<UniqueIdentifier>{334f5ecd-4bbc-4eb9-b71f-3c3676921d7e}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Crypto\Source Files">
|
||||
<UniqueIdentifier>{ea8f7662-085b-475d-8a09-ef1e55af57a3}</UniqueIdentifier>
|
||||
<UniqueIdentifier>{fd73a44d-676d-4ad8-9dc4-c785c8478a68}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="_Suite">
|
||||
<UniqueIdentifier>{8cfbbfdc-308e-42fc-ae9d-64cbc374a417}</UniqueIdentifier>
|
||||
<UniqueIdentifier>{85e42d2e-ad81-427a-8fd4-7018f06729fe}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="_Suite\Header Files">
|
||||
<UniqueIdentifier>{52bafc82-a432-498f-9424-871507cd38e5}</UniqueIdentifier>
|
||||
<UniqueIdentifier>{ee41bf62-06ae-4ba4-8256-fabd22583f6b}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="_Suite\Source Files">
|
||||
<UniqueIdentifier>{22eae798-ed3f-409d-a1a3-8fbb8c18aafb}</UniqueIdentifier>
|
||||
<UniqueIdentifier>{fce9a2bf-14e9-4cdb-a0cb-2f89b341d97a}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="_Driver">
|
||||
<UniqueIdentifier>{d962a46e-db92-47d9-9a10-c0127e4eec28}</UniqueIdentifier>
|
||||
<UniqueIdentifier>{fcef38ad-ddb0-4986-9ad3-e8fe62091325}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="_Driver\Source Files">
|
||||
<UniqueIdentifier>{4511d576-4486-42c7-95f0-8cd2b6e78f36}</UniqueIdentifier>
|
||||
<UniqueIdentifier>{fcf32693-df2a-48eb-906e-70c2abb78dd1}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\CryptoTest.h">
|
||||
<Filter>Crypto\Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\DigestEngineTest.h">
|
||||
<Filter>Crypto\Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\RSATest.h">
|
||||
<Filter>Crypto\Header Files</Filter>
|
||||
</ClInclude>
|
||||
@ -38,6 +41,9 @@
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\DigestEngineTest.cpp">
|
||||
<Filter>Crypto\Header Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\CryptoTest.cpp">
|
||||
<Filter>Crypto\Source Files</Filter>
|
||||
</ClCompile>
|
||||
|
@ -301,10 +301,12 @@
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\CryptoTest.h"/>
|
||||
<ClInclude Include="src\DigestEngineTest.h"/>
|
||||
<ClInclude Include="src\RSATest.h"/>
|
||||
<ClInclude Include="src\CryptoTestSuite.h"/>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\DigestEngineTest.cpp"/>
|
||||
<ClCompile Include="src\CryptoTest.cpp"/>
|
||||
<ClCompile Include="src\RSATest.cpp"/>
|
||||
<ClCompile Include="src\CryptoTestSuite.cpp"/>
|
||||
|
@ -2,34 +2,37 @@
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Crypto">
|
||||
<UniqueIdentifier>{136a6e0f-3cda-4880-ab48-6d5232fd2f54}</UniqueIdentifier>
|
||||
<UniqueIdentifier>{3090bc77-88b3-41aa-914a-b7d83f739584}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Crypto\Header Files">
|
||||
<UniqueIdentifier>{f072cbb0-dda7-4ac9-b96e-19fa83f85e78}</UniqueIdentifier>
|
||||
<UniqueIdentifier>{38fdd9bb-1738-450b-a3c1-6c291459ce85}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Crypto\Source Files">
|
||||
<UniqueIdentifier>{eb17676c-5b20-4428-8484-737bb8629b02}</UniqueIdentifier>
|
||||
<UniqueIdentifier>{bb9cb4d3-376e-4a09-883e-90c7c942f8ed}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="_Suite">
|
||||
<UniqueIdentifier>{556d1112-4d34-4ee0-9b45-8c04b543ada8}</UniqueIdentifier>
|
||||
<UniqueIdentifier>{15631628-2c4a-44a7-82a0-ffecf34a6df3}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="_Suite\Header Files">
|
||||
<UniqueIdentifier>{6ca0118e-d58d-4634-a06c-392c19bc0464}</UniqueIdentifier>
|
||||
<UniqueIdentifier>{e2d6c0e0-5d01-4111-9fe7-b3398a64b0ef}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="_Suite\Source Files">
|
||||
<UniqueIdentifier>{f65bb8aa-48b4-4e8f-abdf-f8852bfa1db7}</UniqueIdentifier>
|
||||
<UniqueIdentifier>{f2ef0ac9-b687-48b0-99a9-10a21910e242}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="_Driver">
|
||||
<UniqueIdentifier>{87d8d807-8d0a-4fab-8296-4036f1673a96}</UniqueIdentifier>
|
||||
<UniqueIdentifier>{a172ca35-6864-41fc-87ad-64c86485949b}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="_Driver\Source Files">
|
||||
<UniqueIdentifier>{a8e1141a-f7a0-495e-aca0-85a3e85c80c1}</UniqueIdentifier>
|
||||
<UniqueIdentifier>{4860aa69-5ea5-49c0-860c-00f7650595a4}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\CryptoTest.h">
|
||||
<Filter>Crypto\Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\DigestEngineTest.h">
|
||||
<Filter>Crypto\Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\RSATest.h">
|
||||
<Filter>Crypto\Header Files</Filter>
|
||||
</ClInclude>
|
||||
@ -38,6 +41,9 @@
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\DigestEngineTest.cpp">
|
||||
<Filter>Crypto\Header Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\CryptoTest.cpp">
|
||||
<Filter>Crypto\Source Files</Filter>
|
||||
</ClCompile>
|
||||
|
@ -437,6 +437,10 @@
|
||||
Name="Header Files">
|
||||
<File
|
||||
RelativePath=".\src\CryptoTest.h"/>
|
||||
<File
|
||||
RelativePath=".\src\DigestEngineTest.cpp"/>
|
||||
<File
|
||||
RelativePath=".\src\DigestEngineTest.h"/>
|
||||
<File
|
||||
RelativePath=".\src\RSATest.h"/>
|
||||
</Filter>
|
||||
|
99
Crypto/testsuite/src/DigestEngineTest.cpp
Normal file
99
Crypto/testsuite/src/DigestEngineTest.cpp
Normal file
@ -0,0 +1,99 @@
|
||||
//
|
||||
// DigestEngineTest.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Crypto/testsuite/src/DigestEngineTest.cpp#1 $
|
||||
//
|
||||
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "DigestEngineTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Crypto/DigestEngine.h"
|
||||
|
||||
|
||||
using Poco::Crypto::DigestEngine;
|
||||
|
||||
|
||||
DigestEngineTest::DigestEngineTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
DigestEngineTest::~DigestEngineTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void DigestEngineTest::testMD5()
|
||||
{
|
||||
DigestEngine engine("MD5");
|
||||
|
||||
// test vectors from RFC 1321
|
||||
|
||||
engine.update("");
|
||||
assert (DigestEngine::digestToHex(engine.digest()) == "d41d8cd98f00b204e9800998ecf8427e");
|
||||
|
||||
engine.update("a");
|
||||
assert (DigestEngine::digestToHex(engine.digest()) == "0cc175b9c0f1b6a831c399e269772661");
|
||||
|
||||
engine.update("abc");
|
||||
assert (DigestEngine::digestToHex(engine.digest()) == "900150983cd24fb0d6963f7d28e17f72");
|
||||
|
||||
engine.update("message digest");
|
||||
assert (DigestEngine::digestToHex(engine.digest()) == "f96b697d7cb7938d525a2f31aaf161d0");
|
||||
|
||||
engine.update("abcdefghijklmnopqrstuvwxyz");
|
||||
assert (DigestEngine::digestToHex(engine.digest()) == "c3fcd3d76192e4007dfb496cca67e13b");
|
||||
|
||||
engine.update("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||
engine.update("abcdefghijklmnopqrstuvwxyz0123456789");
|
||||
assert (DigestEngine::digestToHex(engine.digest()) == "d174ab98d277d9f5a5611c2c9f419d9f");
|
||||
|
||||
engine.update("12345678901234567890123456789012345678901234567890123456789012345678901234567890");
|
||||
assert (DigestEngine::digestToHex(engine.digest()) == "57edf4a22be3c955ac49da2e2107b67a");
|
||||
}
|
||||
|
||||
|
||||
void DigestEngineTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void DigestEngineTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* DigestEngineTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("DigestEngineTest");
|
||||
|
||||
CppUnit_addTest(pSuite, DigestEngineTest, testMD5);
|
||||
|
||||
return pSuite;
|
||||
}
|
60
Crypto/testsuite/src/DigestEngineTest.h
Normal file
60
Crypto/testsuite/src/DigestEngineTest.h
Normal file
@ -0,0 +1,60 @@
|
||||
//
|
||||
// DigestEngineTest.h
|
||||
//
|
||||
// $Id: //poco/1.4/Crypto/testsuite/src/DigestEngineTest.h#1 $
|
||||
//
|
||||
// Definition of the DigestEngineTest class.
|
||||
//
|
||||
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef DigestEngineTest_INCLUDED
|
||||
#define DigestEngineTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Crypto/Crypto.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class DigestEngineTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
DigestEngineTest(const std::string& name);
|
||||
~DigestEngineTest();
|
||||
|
||||
void testMD5();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // DigestEngineTest_INCLUDED
|
330
Foundation/include/Poco/ObjectPool.h
Normal file
330
Foundation/include/Poco/ObjectPool.h
Normal file
@ -0,0 +1,330 @@
|
||||
//
|
||||
// ObjectPool.h
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/include/Poco/ObjectPool.h#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
// Module: ObjectPool
|
||||
//
|
||||
// Definition of the ObjectPool template class and friends.
|
||||
//
|
||||
// Copyright (c) 2010-2012, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_ObjectPool_INCLUDED
|
||||
#define Foundation_ObjectPool_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Poco.h"
|
||||
#include "Poco/Mutex.h"
|
||||
#include "Poco/AutoPtr.h"
|
||||
#include "Poco/SharedPtr.h"
|
||||
#include <vector>
|
||||
#include <cctype>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
template <class C, class P = C*>
|
||||
class PoolableObjectFactory
|
||||
/// A PoolableObjectFactory is responsible for creating and resetting
|
||||
/// objects managed by an ObjectPool.
|
||||
///
|
||||
/// Together with an ObjectPool, a PoolableObjectFactory is used as
|
||||
/// a policy class to change the behavior of the ObjectPool when
|
||||
/// creating new objects, returning used objects back to the pool
|
||||
/// and destroying objects, when the pool itself is destroyed or
|
||||
/// shrinked.
|
||||
{
|
||||
public:
|
||||
P createObject()
|
||||
/// Create and return a new object.
|
||||
{
|
||||
return new C;
|
||||
}
|
||||
|
||||
bool validateObject(P pObject)
|
||||
/// Checks whether the object is still valid
|
||||
/// and can be reused.
|
||||
///
|
||||
/// Returns true if the object is valid,
|
||||
/// false otherwise.
|
||||
///
|
||||
/// To maintain the integrity of the pool, this method
|
||||
/// must not throw an exception.
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void activateObject(P pObject)
|
||||
/// Called before an object is handed out by the pool.
|
||||
/// Also called for newly created objects, before
|
||||
/// they are given out for the first time.
|
||||
{
|
||||
}
|
||||
|
||||
void deactivateObject(P pObject)
|
||||
/// Called after an object has been given back to the
|
||||
/// pool and the object is still valid (a prior call
|
||||
/// to validateObject() returned true).
|
||||
///
|
||||
/// To maintain the integrity of the pool, this method
|
||||
/// must not throw an exception.
|
||||
{
|
||||
}
|
||||
|
||||
void destroyObject(P pObject)
|
||||
/// Destroy an object.
|
||||
///
|
||||
/// To maintain the integrity of the pool, this method
|
||||
/// must not throw an exception.
|
||||
{
|
||||
delete pObject;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <class C>
|
||||
class PoolableObjectFactory <C, Poco::AutoPtr<C> >
|
||||
{
|
||||
public:
|
||||
Poco::AutoPtr<C> createObject()
|
||||
{
|
||||
return new C;
|
||||
}
|
||||
|
||||
bool validateObject(Poco::AutoPtr<C> pObject)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void activateObject(Poco::AutoPtr<C> pObject)
|
||||
{
|
||||
}
|
||||
|
||||
void deactivateObject(Poco::AutoPtr<C> pObject)
|
||||
{
|
||||
}
|
||||
|
||||
void destroyObject(Poco::AutoPtr<C> pObject)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <class C>
|
||||
class PoolableObjectFactory <C, Poco::SharedPtr<C> >
|
||||
{
|
||||
public:
|
||||
Poco::SharedPtr<C> createObject()
|
||||
{
|
||||
return new C;
|
||||
}
|
||||
|
||||
bool validateObject(Poco::SharedPtr<C> pObject)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void activateObject(Poco::SharedPtr<C> pObject)
|
||||
{
|
||||
}
|
||||
|
||||
void deactivateObject(Poco::SharedPtr<C> pObject)
|
||||
{
|
||||
}
|
||||
|
||||
void destroyObject(Poco::SharedPtr<C> pObject)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <class C, class P = C*, class F = PoolableObjectFactory<C, P> >
|
||||
class ObjectPool
|
||||
/// An ObjectPool manages a pool of objects of a certain class.
|
||||
///
|
||||
/// The number of objects managed by the pool can be restricted.
|
||||
///
|
||||
/// When an object is requested from the pool:
|
||||
/// - If an object is available from the pool, an object from the pool is
|
||||
/// removed from the pool, activated (using the factory) and returned.
|
||||
/// - Otherwise, if the peak capacity of the pool has not yet been reached,
|
||||
/// a new object is created and activated, using the object factory, and returned.
|
||||
/// - If the peak capacity has already been reached, null is returned.
|
||||
///
|
||||
/// When an object is returned to the pool:
|
||||
/// - If the object is valid (checked by calling validateObject()
|
||||
/// from the object factory), the object is deactivated. If the
|
||||
/// number of objects in the pool is below the capacity,
|
||||
/// the object is added to the pool. Otherwise it is destroyed.
|
||||
/// - If the object is not valid, it is destroyed immediately.
|
||||
{
|
||||
public:
|
||||
ObjectPool(std::size_t capacity, std::size_t peakCapacity):
|
||||
/// Creates a new ObjectPool with the given capacity
|
||||
/// and peak capcacity.
|
||||
///
|
||||
/// The PoolableObjectFactory must have a public default constructor.
|
||||
_capacity(capacity),
|
||||
_peakCapacity(peakCapacity),
|
||||
_size(0)
|
||||
{
|
||||
poco_assert (capacity <= peakCapacity);
|
||||
}
|
||||
|
||||
ObjectPool(const F& factory, std::size_t capacity, std::size_t peakCapacity):
|
||||
/// Creates a new ObjectPool with the given PoolableObjectFactory,
|
||||
/// capacity and peak capacity. The PoolableObjectFactory must have
|
||||
/// a public copy constructor.
|
||||
_factory(factory),
|
||||
_capacity(capacity),
|
||||
_peakCapacity(peakCapacity),
|
||||
_size(0)
|
||||
{
|
||||
poco_assert (capacity <= peakCapacity);
|
||||
}
|
||||
|
||||
~ObjectPool()
|
||||
/// Destroys the ObjectPool.
|
||||
{
|
||||
for (typename std::vector<P>::iterator it = _pool.begin(); it != _pool.end(); ++it)
|
||||
{
|
||||
_factory.destroyObject(*it);
|
||||
}
|
||||
}
|
||||
|
||||
P borrowObject()
|
||||
/// Obtains an object from the pool, or creates a new object if
|
||||
/// possible.
|
||||
///
|
||||
/// Returns null if no object is available.
|
||||
///
|
||||
/// If activating the object fails, the object is destroyed and
|
||||
/// the exception is passed on to the caller.
|
||||
{
|
||||
Poco::FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
if (!_pool.empty())
|
||||
{
|
||||
P pObject = _pool.back();
|
||||
_pool.pop_back();
|
||||
return activateObject(pObject);
|
||||
}
|
||||
else if (_size < _peakCapacity)
|
||||
{
|
||||
P pObject = _factory.createObject();
|
||||
activateObject(pObject);
|
||||
_size++;
|
||||
return pObject;
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
|
||||
void returnObject(P pObject)
|
||||
/// Returns an object to the pool.
|
||||
{
|
||||
Poco::FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
if (_factory.validateObject(pObject))
|
||||
{
|
||||
_factory.deactivateObject(pObject);
|
||||
if (_pool.size() < _capacity)
|
||||
{
|
||||
_pool.push_back(pObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
_factory.destroyObject(pObject);
|
||||
_size--;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_factory.destroyObject(pObject);
|
||||
}
|
||||
}
|
||||
|
||||
std::size_t capacity() const
|
||||
{
|
||||
return _capacity;
|
||||
}
|
||||
|
||||
std::size_t peakCapacity() const
|
||||
{
|
||||
return _peakCapacity;
|
||||
}
|
||||
|
||||
std::size_t size() const
|
||||
{
|
||||
Poco::FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
return _size;
|
||||
}
|
||||
|
||||
std::size_t available() const
|
||||
{
|
||||
Poco::FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
return _pool.size() + _peakCapacity - _size;
|
||||
}
|
||||
|
||||
protected:
|
||||
P activateObject(P pObject)
|
||||
{
|
||||
try
|
||||
{
|
||||
_factory.activateObject(pObject);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
_factory.destroyObject(pObject);
|
||||
throw;
|
||||
}
|
||||
return pObject;
|
||||
}
|
||||
|
||||
private:
|
||||
ObjectPool();
|
||||
ObjectPool(const ObjectPool&);
|
||||
ObjectPool& operator = (const ObjectPool&);
|
||||
|
||||
F _factory;
|
||||
std::size_t _capacity;
|
||||
std::size_t _peakCapacity;
|
||||
std::size_t _size;
|
||||
std::vector<P> _pool;
|
||||
mutable Poco::FastMutex _mutex;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Foundation_ObjectPool_INCLUDED
|
@ -87,6 +87,11 @@ public:
|
||||
PRIO_HIGH = PRIO_HIGH_IMPL, /// A higher than normal thread priority.
|
||||
PRIO_HIGHEST = PRIO_HIGHEST_IMPL /// The highest thread priority.
|
||||
};
|
||||
|
||||
enum Policy
|
||||
{
|
||||
POLICY_DEFAULT = POLICY_DEFAULT_IMPL
|
||||
};
|
||||
|
||||
Thread();
|
||||
/// Creates a thread. Call start() to start it.
|
||||
@ -121,10 +126,13 @@ public:
|
||||
Priority getPriority() const;
|
||||
/// Returns the thread's priority.
|
||||
|
||||
void setOSPriority(int prio);
|
||||
void setOSPriority(int prio, int policy = POLICY_DEFAULT);
|
||||
/// Sets the thread's priority, using an operating system specific
|
||||
/// priority value. Use getMinOSPriority() and getMaxOSPriority() to
|
||||
/// obtain mininum and maximum priority values.
|
||||
/// obtain mininum and maximum priority values. Additionally,
|
||||
/// a scheduling policy can be specified. The policy is currently
|
||||
/// only used on POSIX platforms where the values SCHED_OTHER (default),
|
||||
/// SCHED_FIFO and SCHED_RR are supported.
|
||||
|
||||
int getOSPriority() const;
|
||||
/// Returns the thread's priority, expressed as an operating system
|
||||
@ -132,13 +140,13 @@ public:
|
||||
///
|
||||
/// May return 0 if the priority has not been explicitly set.
|
||||
|
||||
static int getMinOSPriority();
|
||||
static int getMinOSPriority(int policy = POLICY_DEFAULT);
|
||||
/// Returns the mininum operating system-specific priority value,
|
||||
/// which can be passed to setOSPriority().
|
||||
/// which can be passed to setOSPriority() for the given policy.
|
||||
|
||||
static int getMaxOSPriority();
|
||||
static int getMaxOSPriority(int policy = POLICY_DEFAULT);
|
||||
/// Returns the maximum operating system-specific priority value,
|
||||
/// which can be passed to setOSPriority().
|
||||
/// which can be passed to setOSPriority() for the given policy.
|
||||
|
||||
void setStackSize(int size);
|
||||
/// Sets the thread's stack size in bytes.
|
||||
@ -270,9 +278,9 @@ inline Thread* Thread::current()
|
||||
}
|
||||
|
||||
|
||||
inline void Thread::setOSPriority(int prio)
|
||||
inline void Thread::setOSPriority(int prio, int policy)
|
||||
{
|
||||
setOSPriorityImpl(prio);
|
||||
setOSPriorityImpl(prio, policy);
|
||||
}
|
||||
|
||||
|
||||
@ -282,15 +290,15 @@ inline int Thread::getOSPriority() const
|
||||
}
|
||||
|
||||
|
||||
inline int Thread::getMinOSPriority()
|
||||
inline int Thread::getMinOSPriority(int policy)
|
||||
{
|
||||
return ThreadImpl::getMinOSPriorityImpl();
|
||||
return ThreadImpl::getMinOSPriorityImpl(policy);
|
||||
}
|
||||
|
||||
|
||||
inline int Thread::getMaxOSPriority()
|
||||
inline int Thread::getMaxOSPriority(int policy)
|
||||
{
|
||||
return ThreadImpl::getMaxOSPriorityImpl();
|
||||
return ThreadImpl::getMaxOSPriorityImpl(policy);
|
||||
}
|
||||
|
||||
|
||||
|
@ -75,7 +75,12 @@ public:
|
||||
PRIO_HIGH_IMPL,
|
||||
PRIO_HIGHEST_IMPL
|
||||
};
|
||||
|
||||
|
||||
enum Policy
|
||||
{
|
||||
POLICY_DEFAULT_IMPL = SCHED_OTHER
|
||||
};
|
||||
|
||||
struct CallbackData: public RefCountedObject
|
||||
{
|
||||
CallbackData(): callback(0), pData(0)
|
||||
@ -92,10 +97,10 @@ public:
|
||||
TIDImpl tidImpl() const;
|
||||
void setPriorityImpl(int prio);
|
||||
int getPriorityImpl() const;
|
||||
void setOSPriorityImpl(int prio);
|
||||
void setOSPriorityImpl(int prio, int policy = SCHED_OTHER);
|
||||
int getOSPriorityImpl() const;
|
||||
static int getMinOSPriorityImpl();
|
||||
static int getMaxOSPriorityImpl();
|
||||
static int getMinOSPriorityImpl(int policy);
|
||||
static int getMaxOSPriorityImpl(int policy);
|
||||
void setStackSizeImpl(int size);
|
||||
int getStackSizeImpl() const;
|
||||
void startImpl(Runnable& target);
|
||||
@ -112,8 +117,8 @@ public:
|
||||
protected:
|
||||
static void* runnableEntry(void* pThread);
|
||||
static void* callableEntry(void* pThread);
|
||||
static int mapPrio(int prio);
|
||||
static int reverseMapPrio(int osPrio);
|
||||
static int mapPrio(int prio, int policy = SCHED_OTHER);
|
||||
static int reverseMapPrio(int osPrio, int policy = SCHED_OTHER);
|
||||
|
||||
private:
|
||||
class CurrentThreadHolder
|
||||
@ -148,7 +153,7 @@ private:
|
||||
pCallbackTarget(0),
|
||||
thread(0),
|
||||
prio(PRIO_NORMAL_IMPL),
|
||||
osPrio(0),
|
||||
policy(SCHED_OTHER),
|
||||
done(false),
|
||||
stackSize(POCO_THREAD_STACK_SIZE)
|
||||
{
|
||||
@ -164,6 +169,7 @@ private:
|
||||
pthread_t thread;
|
||||
int prio;
|
||||
int osPrio;
|
||||
int policy;
|
||||
Event done;
|
||||
std::size_t stackSize;
|
||||
};
|
||||
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// Thread_VX.h
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/include/Poco/Thread_VX.h#1 $
|
||||
// $Id: //poco/1.4/Foundation/include/Poco/Thread_VX.h#3 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Threading
|
||||
@ -67,7 +67,12 @@ public:
|
||||
PRIO_HIGH_IMPL,
|
||||
PRIO_HIGHEST_IMPL
|
||||
};
|
||||
|
||||
|
||||
enum Policy
|
||||
{
|
||||
POLICY_DEFAULT_IMPL = 0
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
DEFAULT_THREAD_STACK_SIZE = 65536
|
||||
@ -89,10 +94,10 @@ public:
|
||||
TIDImpl tidImpl() const;
|
||||
void setPriorityImpl(int prio);
|
||||
int getPriorityImpl() const;
|
||||
void setOSPriorityImpl(int prio);
|
||||
void setOSPriorityImpl(int prio, int policy = 0);
|
||||
int getOSPriorityImpl() const;
|
||||
static int getMinOSPriorityImpl();
|
||||
static int getMaxOSPriorityImpl();
|
||||
static int getMinOSPriorityImpl(int policy);
|
||||
static int getMaxOSPriorityImpl(int policy);
|
||||
void setStackSizeImpl(int size);
|
||||
int getStackSizeImpl() const;
|
||||
void startImpl(Runnable& target);
|
||||
|
@ -79,16 +79,21 @@ public:
|
||||
PRIO_HIGHEST_IMPL = THREAD_PRIORITY_HIGHEST
|
||||
};
|
||||
|
||||
enum Policy
|
||||
{
|
||||
POLICY_DEFAULT_IMPL = 0
|
||||
};
|
||||
|
||||
ThreadImpl();
|
||||
~ThreadImpl();
|
||||
|
||||
TIDImpl tidImpl() const;
|
||||
void setPriorityImpl(int prio);
|
||||
int getPriorityImpl() const;
|
||||
void setOSPriorityImpl(int prio);
|
||||
void setOSPriorityImpl(int prio, int policy = 0);
|
||||
int getOSPriorityImpl() const;
|
||||
static int getMinOSPriorityImpl();
|
||||
static int getMaxOSPriorityImpl();
|
||||
static int getMinOSPriorityImpl(int policy);
|
||||
static int getMaxOSPriorityImpl(int policy);
|
||||
void setStackSizeImpl(int size);
|
||||
int getStackSizeImpl() const;
|
||||
void startImpl(Runnable& target);
|
||||
@ -170,13 +175,13 @@ inline int ThreadImpl::getOSPriorityImpl() const
|
||||
}
|
||||
|
||||
|
||||
inline int ThreadImpl::getMinOSPriorityImpl()
|
||||
inline int ThreadImpl::getMinOSPriorityImpl(int /* policy */)
|
||||
{
|
||||
return PRIO_LOWEST_IMPL;
|
||||
}
|
||||
|
||||
|
||||
inline int ThreadImpl::getMaxOSPriorityImpl()
|
||||
inline int ThreadImpl::getMaxOSPriorityImpl(int /* policy */)
|
||||
{
|
||||
return PRIO_HIGHEST_IMPL;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// Thread_WINCE.h
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/include/Poco/Thread_WINCE.h#1 $
|
||||
// $Id: //poco/1.4/Foundation/include/Poco/Thread_WINCE.h#3 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Threading
|
||||
@ -79,16 +79,21 @@ public:
|
||||
PRIO_HIGHEST_IMPL = THREAD_PRIORITY_HIGHEST
|
||||
};
|
||||
|
||||
enum Policy
|
||||
{
|
||||
POLICY_DEFAULT_IMPL = 0
|
||||
};
|
||||
|
||||
ThreadImpl();
|
||||
~ThreadImpl();
|
||||
|
||||
TIDImpl tidImpl() const;
|
||||
void setPriorityImpl(int prio);
|
||||
int getPriorityImpl() const;
|
||||
void setOSPriorityImpl(int prio);
|
||||
void setOSPriorityImpl(int prio, int policy = 0);
|
||||
int getOSPriorityImpl() const;
|
||||
static int getMinOSPriorityImpl();
|
||||
static int getMaxOSPriorityImpl();
|
||||
static int getMinOSPriorityImpl(int policy);
|
||||
static int getMaxOSPriorityImpl(int policy);
|
||||
void setStackSizeImpl(int size);
|
||||
int getStackSizeImpl() const;
|
||||
void startImpl(Runnable& target);
|
||||
@ -161,13 +166,13 @@ inline int ThreadImpl::getOSPriorityImpl() const
|
||||
}
|
||||
|
||||
|
||||
inline int ThreadImpl::getMinOSPriorityImpl()
|
||||
inline int ThreadImpl::getMinOSPriorityImpl(int /* policy */)
|
||||
{
|
||||
return PRIO_LOWEST_IMPL;
|
||||
}
|
||||
|
||||
|
||||
inline int ThreadImpl::getMaxOSPriorityImpl()
|
||||
inline int ThreadImpl::getMaxOSPriorityImpl(int /* policy */)
|
||||
{
|
||||
return PRIO_HIGHEST_IMPL;
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ void ThreadImpl::setPriorityImpl(int prio)
|
||||
if (isRunningImpl())
|
||||
{
|
||||
struct sched_param par;
|
||||
par.sched_priority = mapPrio(_pData->prio);
|
||||
par.sched_priority = mapPrio(_pData->prio, SCHED_OTHER);
|
||||
if (pthread_setschedparam(_pData->thread, SCHED_OTHER, &par))
|
||||
throw SystemException("cannot set thread priority");
|
||||
}
|
||||
@ -111,9 +111,9 @@ void ThreadImpl::setPriorityImpl(int prio)
|
||||
}
|
||||
|
||||
|
||||
void ThreadImpl::setOSPriorityImpl(int prio)
|
||||
void ThreadImpl::setOSPriorityImpl(int prio, int policy )
|
||||
{
|
||||
if (prio != _pData->osPrio)
|
||||
if (prio != _pData->osPrio || policy != _pData->policy)
|
||||
{
|
||||
if (_pData->pRunnableTarget || _pData->pCallbackTarget)
|
||||
{
|
||||
@ -122,32 +122,33 @@ void ThreadImpl::setOSPriorityImpl(int prio)
|
||||
if (pthread_setschedparam(_pData->thread, SCHED_OTHER, &par))
|
||||
throw SystemException("cannot set thread priority");
|
||||
}
|
||||
_pData->prio = reverseMapPrio(prio);
|
||||
_pData->prio = reverseMapPrio(prio, policy);
|
||||
_pData->osPrio = prio;
|
||||
_pData->policy = policy;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int ThreadImpl::getMinOSPriorityImpl()
|
||||
int ThreadImpl::getMinOSPriorityImpl(int policy)
|
||||
{
|
||||
#if defined(POCO_THREAD_PRIORITY_MIN)
|
||||
return POCO_THREAD_PRIORITY_MIN;
|
||||
#elif defined(__VMS) || defined(__digital__)
|
||||
return PRI_OTHER_MIN;
|
||||
#else
|
||||
return sched_get_priority_min(SCHED_OTHER);
|
||||
return sched_get_priority_min(policy);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int ThreadImpl::getMaxOSPriorityImpl()
|
||||
int ThreadImpl::getMaxOSPriorityImpl(int policy)
|
||||
{
|
||||
#if defined(POCO_THREAD_PRIORITY_MAX)
|
||||
return POCO_THREAD_PRIORITY_MAX;
|
||||
#elif defined(__VMS) || defined(__digital__)
|
||||
return PRI_OTHER_MAX;
|
||||
#else
|
||||
return sched_get_priority_max(SCHED_OTHER);
|
||||
return sched_get_priority_max(policy);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -195,11 +196,21 @@ void ThreadImpl::startImpl(Runnable& target)
|
||||
throw SystemException("cannot start thread");
|
||||
}
|
||||
|
||||
if (_pData->prio != PRIO_NORMAL_IMPL)
|
||||
if (_pData->policy == SCHED_OTHER)
|
||||
{
|
||||
if (_pData->prio != PRIO_NORMAL_IMPL)
|
||||
{
|
||||
struct sched_param par;
|
||||
par.sched_priority = mapPrio(_pData->prio, SCHED_OTHER);
|
||||
if (pthread_setschedparam(_pData->thread, SCHED_OTHER, &par))
|
||||
throw SystemException("cannot set thread priority");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
struct sched_param par;
|
||||
par.sched_priority = mapPrio(_pData->prio);
|
||||
if (pthread_setschedparam(_pData->thread, SCHED_OTHER, &par))
|
||||
par.sched_priority = mapPrio(_pData->prio, _pData->policy);
|
||||
if (pthread_setschedparam(_pData->thread, _pData->policy, &par))
|
||||
throw SystemException("cannot set thread priority");
|
||||
}
|
||||
}
|
||||
@ -232,11 +243,21 @@ void ThreadImpl::startImpl(Callable target, void* pData)
|
||||
throw SystemException("cannot start thread");
|
||||
}
|
||||
|
||||
if (_pData->prio != PRIO_NORMAL_IMPL)
|
||||
if (_pData->policy == SCHED_OTHER)
|
||||
{
|
||||
if (_pData->prio != PRIO_NORMAL_IMPL)
|
||||
{
|
||||
struct sched_param par;
|
||||
par.sched_priority = mapPrio(_pData->prio, SCHED_OTHER);
|
||||
if (pthread_setschedparam(_pData->thread, SCHED_OTHER, &par))
|
||||
throw SystemException("cannot set thread priority");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
struct sched_param par;
|
||||
par.sched_priority = mapPrio(_pData->prio);
|
||||
if (pthread_setschedparam(_pData->thread, SCHED_OTHER, &par))
|
||||
par.sched_priority = _pData->osPrio;
|
||||
if (pthread_setschedparam(_pData->thread, _pData->policy, &par))
|
||||
throw SystemException("cannot set thread priority");
|
||||
}
|
||||
}
|
||||
@ -410,10 +431,10 @@ void* ThreadImpl::callableEntry(void* pThread)
|
||||
}
|
||||
|
||||
|
||||
int ThreadImpl::mapPrio(int prio)
|
||||
int ThreadImpl::mapPrio(int prio, int policy)
|
||||
{
|
||||
int pmin = getMinOSPriorityImpl();
|
||||
int pmax = getMaxOSPriorityImpl();
|
||||
int pmin = getMinOSPriorityImpl(policy);
|
||||
int pmax = getMaxOSPriorityImpl(policy);
|
||||
|
||||
switch (prio)
|
||||
{
|
||||
@ -434,21 +455,25 @@ int ThreadImpl::mapPrio(int prio)
|
||||
}
|
||||
|
||||
|
||||
int ThreadImpl::reverseMapPrio(int prio)
|
||||
int ThreadImpl::reverseMapPrio(int prio, int policy)
|
||||
{
|
||||
int pmin = getMinOSPriorityImpl();
|
||||
int pmax = getMaxOSPriorityImpl();
|
||||
int normal = pmin + (pmax - pmin)/2;
|
||||
if (prio == pmax)
|
||||
return PRIO_HIGHEST_IMPL;
|
||||
if (prio > normal)
|
||||
return PRIO_HIGH_IMPL;
|
||||
else if (prio == normal)
|
||||
return PRIO_NORMAL_IMPL;
|
||||
else if (prio > pmin)
|
||||
return PRIO_LOW_IMPL;
|
||||
else
|
||||
return PRIO_LOWEST_IMPL;
|
||||
if (policy == SCHED_OTHER)
|
||||
{
|
||||
int pmin = getMinOSPriorityImpl(policy);
|
||||
int pmax = getMaxOSPriorityImpl(policy);
|
||||
int normal = pmin + (pmax - pmin)/2;
|
||||
if (prio == pmax)
|
||||
return PRIO_HIGHEST_IMPL;
|
||||
if (prio > normal)
|
||||
return PRIO_HIGH_IMPL;
|
||||
else if (prio == normal)
|
||||
return PRIO_NORMAL_IMPL;
|
||||
else if (prio > pmin)
|
||||
return PRIO_LOW_IMPL;
|
||||
else
|
||||
return PRIO_LOWEST_IMPL;
|
||||
}
|
||||
else return PRIO_HIGHEST_IMPL;
|
||||
}
|
||||
|
||||
|
||||
|
@ -74,7 +74,7 @@ void ThreadImpl::setPriorityImpl(int prio)
|
||||
}
|
||||
|
||||
|
||||
void ThreadImpl::setOSPriorityImpl(int prio)
|
||||
void ThreadImpl::setOSPriorityImpl(int prio, int /* policy */)
|
||||
{
|
||||
if (prio != _pData->osPrio)
|
||||
{
|
||||
@ -89,13 +89,13 @@ void ThreadImpl::setOSPriorityImpl(int prio)
|
||||
}
|
||||
|
||||
|
||||
int ThreadImpl::getMinOSPriorityImpl()
|
||||
int ThreadImpl::getMinOSPriorityImpl(int /* policy */)
|
||||
{
|
||||
return 255;
|
||||
}
|
||||
|
||||
|
||||
int ThreadImpl::getMaxOSPriorityImpl()
|
||||
int ThreadImpl::getMaxOSPriorityImpl(int /* policy */)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ void ThreadImpl::setPriorityImpl(int prio)
|
||||
}
|
||||
|
||||
|
||||
void ThreadImpl::setOSPriorityImpl(int prio)
|
||||
void ThreadImpl::setOSPriorityImpl(int prio, int /* policy */)
|
||||
{
|
||||
setPriorityImpl(prio);
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ void ThreadImpl::setPriorityImpl(int prio)
|
||||
}
|
||||
|
||||
|
||||
void ThreadImpl::setOSPriorityImpl(int prio)
|
||||
void ThreadImpl::setOSPriorityImpl(int prio, int /* policy */)
|
||||
{
|
||||
setPriorityImpl(prio);
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#
|
||||
# Makefile
|
||||
#
|
||||
# $Id: //poco/1.4/Foundation/testsuite/Makefile-Driver#2 $
|
||||
# $Id: //poco/1.4/Foundation/testsuite/Makefile-Driver#2 $
|
||||
#
|
||||
# Makefile for Poco Foundation testsuite
|
||||
#
|
||||
@ -39,7 +39,7 @@ objects = ActiveMethodTest ActivityTest ActiveDispatcherTest \
|
||||
HashSetTest HashMapTest SharedMemoryTest \
|
||||
UniqueExpireCacheTest UniqueExpireLRUCacheTest \
|
||||
TuplesTest NamedTuplesTest TypeListTest VarTest DynamicTestSuite FileStreamTest \
|
||||
MemoryStreamTest
|
||||
MemoryStreamTest ObjectPoolTest
|
||||
|
||||
target = testrunner
|
||||
target_version = 1
|
||||
|
@ -646,6 +646,9 @@
|
||||
RelativePath=".\src\NumberParserTest.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ObjectPoolTest.cpp"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\src\RegularExpressionTest.cpp"
|
||||
>
|
||||
@ -734,6 +737,10 @@
|
||||
RelativePath=".\src\NumberParserTest.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ObjectPoolTest.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\RegularExpressionTest.h"
|
||||
>
|
||||
|
@ -315,6 +315,7 @@
|
||||
<ClCompile Include="src\NDCTest.cpp" />
|
||||
<ClCompile Include="src\NumberFormatterTest.cpp" />
|
||||
<ClCompile Include="src\NumberParserTest.cpp" />
|
||||
<ClCompile Include="src\ObjectPoolTest.cpp" />
|
||||
<ClCompile Include="src\RegularExpressionTest.cpp" />
|
||||
<ClCompile Include="src\SharedPtrTest.cpp" />
|
||||
<ClCompile Include="src\StringTest.cpp" />
|
||||
@ -445,6 +446,7 @@
|
||||
<ClInclude Include="src\NDCTest.h" />
|
||||
<ClInclude Include="src\NumberFormatterTest.h" />
|
||||
<ClInclude Include="src\NumberParserTest.h" />
|
||||
<ClInclude Include="src\ObjectPoolTest.h" />
|
||||
<ClInclude Include="src\RegularExpressionTest.h" />
|
||||
<ClInclude Include="src\SharedPtrTest.h" />
|
||||
<ClInclude Include="src\StringTest.h" />
|
||||
|
@ -558,6 +558,9 @@
|
||||
<ClCompile Include="src\SimpleHashTableTest.cpp">
|
||||
<Filter>Hashing\Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\ObjectPoolTest.cpp">
|
||||
<Filter>Core\Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\VarTest.cpp">
|
||||
<Filter>Dynamic\Source Files</Filter>
|
||||
</ClCompile>
|
||||
@ -941,6 +944,9 @@
|
||||
<ClInclude Include="src\SimpleHashTableTest.h">
|
||||
<Filter>Hashing\Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\ObjectPoolTest.h">
|
||||
<Filter>Core\Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\VarTest.h">
|
||||
<Filter>Dynamic\Header Files</Filter>
|
||||
</ClInclude>
|
||||
|
@ -442,6 +442,9 @@
|
||||
<File
|
||||
RelativePath=".\src\NumberParserTest.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ObjectPoolTest.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\RegularExpressionTest.cpp">
|
||||
</File>
|
||||
@ -509,6 +512,9 @@
|
||||
<File
|
||||
RelativePath=".\src\NumberParserTest.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ObjectPoolTest.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\RegularExpressionTest.h">
|
||||
</File>
|
||||
|
@ -615,6 +615,10 @@
|
||||
RelativePath=".\src\NumberParserTest.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ObjectPoolTest.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\RegularExpressionTest.cpp"
|
||||
>
|
||||
@ -703,6 +707,10 @@
|
||||
RelativePath=".\src\NumberParserTest.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ObjectPoolTest.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\RegularExpressionTest.h"
|
||||
>
|
||||
|
@ -597,6 +597,10 @@
|
||||
RelativePath=".\src\NumberParserTest.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ObjectPoolTest.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\RegularExpressionTest.cpp"
|
||||
>
|
||||
@ -685,6 +689,10 @@
|
||||
RelativePath=".\src\NumberParserTest.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ObjectPoolTest.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\RegularExpressionTest.h"
|
||||
>
|
||||
|
@ -315,6 +315,7 @@
|
||||
<ClCompile Include="src\NDCTest.cpp" />
|
||||
<ClCompile Include="src\NumberFormatterTest.cpp" />
|
||||
<ClCompile Include="src\NumberParserTest.cpp" />
|
||||
<ClCompile Include="src\ObjectPoolTest.cpp" />
|
||||
<ClCompile Include="src\RegularExpressionTest.cpp" />
|
||||
<ClCompile Include="src\SharedPtrTest.cpp" />
|
||||
<ClCompile Include="src\StringTest.cpp" />
|
||||
@ -444,6 +445,7 @@
|
||||
<ClInclude Include="src\NDCTest.h" />
|
||||
<ClInclude Include="src\NumberFormatterTest.h" />
|
||||
<ClInclude Include="src\NumberParserTest.h" />
|
||||
<ClInclude Include="src\ObjectPoolTest.h" />
|
||||
<ClInclude Include="src\RegularExpressionTest.h" />
|
||||
<ClInclude Include="src\SharedPtrTest.h" />
|
||||
<ClInclude Include="src\StringTest.h" />
|
||||
|
@ -552,6 +552,9 @@
|
||||
<ClCompile Include="src\SimpleHashTableTest.cpp">
|
||||
<Filter>Hashing\Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\ObjectPoolTest.cpp">
|
||||
<Filter>Core\Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\AnyTest.h">
|
||||
@ -932,5 +935,8 @@
|
||||
<ClInclude Include="src\SimpleHashTableTest.h">
|
||||
<Filter>Hashing\Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\ObjectPoolTest.h">
|
||||
<Filter>Core\Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -591,6 +591,10 @@
|
||||
RelativePath=".\src\NumberParserTest.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ObjectPoolTest.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\RegularExpressionTest.cpp"
|
||||
>
|
||||
@ -679,6 +683,10 @@
|
||||
RelativePath=".\src\NumberParserTest.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ObjectPoolTest.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\RegularExpressionTest.h"
|
||||
>
|
||||
|
@ -56,6 +56,7 @@
|
||||
#include "NamedTuplesTest.h"
|
||||
#endif
|
||||
#include "TypeListTest.h"
|
||||
#include "ObjectPoolTest.h"
|
||||
|
||||
|
||||
CppUnit::Test* CoreTestSuite::suite()
|
||||
@ -87,6 +88,7 @@ CppUnit::Test* CoreTestSuite::suite()
|
||||
pSuite->addTest(NamedTuplesTest::suite());
|
||||
#endif
|
||||
pSuite->addTest(TypeListTest::suite());
|
||||
pSuite->addTest(ObjectPoolTest::suite());
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
130
Foundation/testsuite/src/ObjectPoolTest.cpp
Normal file
130
Foundation/testsuite/src/ObjectPoolTest.cpp
Normal file
@ -0,0 +1,130 @@
|
||||
//
|
||||
// ObjectPoolTest.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/testsuite/src/ObjectPoolTest.cpp#1 $
|
||||
//
|
||||
// Copyright (c) 2010-2012, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "ObjectPoolTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/ObjectPool.h"
|
||||
#include "Poco/Exception.h"
|
||||
|
||||
|
||||
using Poco::ObjectPool;
|
||||
|
||||
|
||||
ObjectPoolTest::ObjectPoolTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ObjectPoolTest::~ObjectPoolTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void ObjectPoolTest::testObjectPool()
|
||||
{
|
||||
ObjectPool<std::string, Poco::SharedPtr<std::string> > pool(3, 4);
|
||||
|
||||
assert (pool.capacity() == 3);
|
||||
assert (pool.peakCapacity() == 4);
|
||||
assert (pool.size() == 0);
|
||||
assert (pool.available() == 4);
|
||||
|
||||
Poco::SharedPtr<std::string> pStr1 = pool.borrowObject();
|
||||
pStr1->assign("first");
|
||||
assert (pool.size() == 1);
|
||||
assert (pool.available() == 3);
|
||||
|
||||
Poco::SharedPtr<std::string> pStr2 = pool.borrowObject();
|
||||
pStr2->assign("second");
|
||||
assert (pool.size() == 2);
|
||||
assert (pool.available() == 2);
|
||||
|
||||
Poco::SharedPtr<std::string> pStr3 = pool.borrowObject();
|
||||
pStr3->assign("third");
|
||||
assert (pool.size() == 3);
|
||||
assert (pool.available() == 1);
|
||||
|
||||
Poco::SharedPtr<std::string> pStr4 = pool.borrowObject();
|
||||
pStr4->assign("fourth");
|
||||
assert (pool.size() == 4);
|
||||
assert (pool.available() == 0);
|
||||
|
||||
Poco::SharedPtr<std::string> pStr5 = pool.borrowObject();
|
||||
assert (pStr5.isNull());
|
||||
|
||||
pool.returnObject(pStr4);
|
||||
assert (pool.size() == 4);
|
||||
assert (pool.available() == 1);
|
||||
|
||||
pool.returnObject(pStr3);
|
||||
assert (pool.size() == 4);
|
||||
assert (pool.available() == 2);
|
||||
|
||||
pStr3 = pool.borrowObject();
|
||||
assert (*pStr3 == "third");
|
||||
assert (pool.available() == 1);
|
||||
|
||||
pool.returnObject(pStr3);
|
||||
pool.returnObject(pStr2);
|
||||
pool.returnObject(pStr1);
|
||||
|
||||
assert (pool.size() == 3);
|
||||
assert (pool.available() == 4);
|
||||
|
||||
pStr1 = pool.borrowObject();
|
||||
assert (*pStr1 == "second");
|
||||
assert (pool.available() == 3);
|
||||
|
||||
pool.returnObject(pStr1);
|
||||
assert (pool.available() == 4);
|
||||
}
|
||||
|
||||
|
||||
void ObjectPoolTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void ObjectPoolTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* ObjectPoolTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ObjectPoolTest");
|
||||
|
||||
CppUnit_addTest(pSuite, ObjectPoolTest, testObjectPool);
|
||||
|
||||
return pSuite;
|
||||
}
|
60
Foundation/testsuite/src/ObjectPoolTest.h
Normal file
60
Foundation/testsuite/src/ObjectPoolTest.h
Normal file
@ -0,0 +1,60 @@
|
||||
//
|
||||
// ObjectPoolTest.h
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/testsuite/src/ObjectPoolTest.h#1 $
|
||||
//
|
||||
// Definition of the ObjectPoolTest class.
|
||||
//
|
||||
// Copyright (c) 2010-2012, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef ObjectPoolTest_INCLUDED
|
||||
#define ObjectPoolTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class ObjectPoolTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
ObjectPoolTest(const std::string& name);
|
||||
~ObjectPoolTest();
|
||||
|
||||
void testObjectPool();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // ObjectPoolTest_INCLUDED
|
@ -30,6 +30,11 @@
|
||||
//
|
||||
|
||||
|
||||
#if defined(_WIN32)
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
|
@ -745,10 +745,10 @@ void JSONTest::testInvalidJanssonFiles()
|
||||
catch(Poco::JSON::JSONException jsone)
|
||||
{
|
||||
std::cout << "Ok! We got an exception " << jsone.message() << std::endl;
|
||||
}
|
||||
catch(Poco::SyntaxException se)
|
||||
{
|
||||
std::cout << "Ok! We got an exception " << se.message() << std::endl;
|
||||
}
|
||||
catch(Poco::SyntaxException se)
|
||||
{
|
||||
std::cout << "Ok! We got an exception " << se.message() << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -42,6 +42,7 @@
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "Poco/SharedPtr.h"
|
||||
#include "Poco/BasicEvent.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
@ -72,9 +73,15 @@ public:
|
||||
///
|
||||
/// Creates a new request handler for the given HTTP request.
|
||||
|
||||
protected:
|
||||
Poco::BasicEvent<const bool> serverStopped;
|
||||
|
||||
private:
|
||||
HTTPRequestHandlerFactory(const HTTPRequestHandlerFactory&);
|
||||
HTTPRequestHandlerFactory& operator = (const HTTPRequestHandlerFactory&);
|
||||
|
||||
friend class HTTPServer;
|
||||
friend class HTTPServerConnection;
|
||||
};
|
||||
|
||||
|
||||
|
@ -85,6 +85,19 @@ public:
|
||||
|
||||
~HTTPServer();
|
||||
/// Destroys the HTTPServer and its HTTPRequestHandlerFactory.
|
||||
|
||||
void stopAll(bool abortCurrent = false);
|
||||
/// Stops the server. In contrast to TCPServer::stop(), which also
|
||||
/// stops the server, but allows all client connections to finish at
|
||||
/// their pace, this allows finer control over client connections.
|
||||
///
|
||||
/// If abortCurrent is false, all current requests are allowed to
|
||||
/// complete. If abortCurrent is false, the underlying sockets of
|
||||
/// all client connections are shut down, causing all requests
|
||||
/// to abort.
|
||||
|
||||
private:
|
||||
HTTPRequestHandlerFactory::Ptr _pFactory;
|
||||
};
|
||||
|
||||
|
||||
|
@ -45,6 +45,7 @@
|
||||
#include "Poco/Net/HTTPResponse.h"
|
||||
#include "Poco/Net/HTTPRequestHandlerFactory.h"
|
||||
#include "Poco/Net/HTTPServerParams.h"
|
||||
#include "Poco/Mutex.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
@ -70,10 +71,13 @@ public:
|
||||
|
||||
protected:
|
||||
void sendErrorResponse(HTTPServerSession& session, HTTPResponse::HTTPStatus status);
|
||||
void onServerStopped(const bool& abortCurrent);
|
||||
|
||||
private:
|
||||
HTTPServerParams::Ptr _pParams;
|
||||
HTTPRequestHandlerFactory::Ptr _pFactory;
|
||||
bool _stopped;
|
||||
Poco::FastMutex _mutex;
|
||||
};
|
||||
|
||||
|
||||
|
@ -56,7 +56,7 @@ DatagramSocket::DatagramSocket(IPAddress::Family family): Socket(new DatagramSoc
|
||||
}
|
||||
|
||||
|
||||
DatagramSocket::DatagramSocket(const SocketAddress& address, bool reuseAddress): Socket(new DatagramSocketImpl)
|
||||
DatagramSocket::DatagramSocket(const SocketAddress& address, bool reuseAddress): Socket(new DatagramSocketImpl(address.family()))
|
||||
{
|
||||
bind(address, reuseAddress);
|
||||
}
|
||||
|
@ -329,10 +329,13 @@ std::string FTPClientSession::extractPath(const std::string& response)
|
||||
|
||||
StreamSocket FTPClientSession::establishDataConnection(const std::string& command, const std::string& arg)
|
||||
{
|
||||
StreamSocket ss;
|
||||
if (_passiveMode)
|
||||
return passiveDataConnection(command, arg);
|
||||
ss = passiveDataConnection(command, arg);
|
||||
else
|
||||
return activeDataConnection(command, arg);
|
||||
ss = activeDataConnection(command, arg);
|
||||
ss.setReceiveTimeout(_timeout);
|
||||
return ss;
|
||||
}
|
||||
|
||||
|
||||
|
@ -43,13 +43,15 @@ namespace Net {
|
||||
|
||||
|
||||
HTTPServer::HTTPServer(HTTPRequestHandlerFactory::Ptr pFactory, const ServerSocket& socket, HTTPServerParams::Ptr pParams):
|
||||
TCPServer(new HTTPServerConnectionFactory(pParams, pFactory), socket, pParams)
|
||||
TCPServer(new HTTPServerConnectionFactory(pParams, pFactory), socket, pParams),
|
||||
_pFactory(pFactory)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
HTTPServer::HTTPServer(HTTPRequestHandlerFactory::Ptr pFactory, Poco::ThreadPool& threadPool, const ServerSocket& socket, HTTPServerParams::Ptr pParams):
|
||||
TCPServer(new HTTPServerConnectionFactory(pParams, pFactory), threadPool, socket, pParams)
|
||||
TCPServer(new HTTPServerConnectionFactory(pParams, pFactory), threadPool, socket, pParams),
|
||||
_pFactory(pFactory)
|
||||
{
|
||||
}
|
||||
|
||||
@ -59,4 +61,11 @@ HTTPServer::~HTTPServer()
|
||||
}
|
||||
|
||||
|
||||
void HTTPServer::stopAll(bool abortCurrent)
|
||||
{
|
||||
_pFactory->serverStopped(this, abortCurrent);
|
||||
stop();
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Net
|
||||
|
@ -43,6 +43,7 @@
|
||||
#include "Poco/Net/NetException.h"
|
||||
#include "Poco/NumberFormatter.h"
|
||||
#include "Poco/Timestamp.h"
|
||||
#include "Poco/Delegate.h"
|
||||
#include <memory>
|
||||
|
||||
|
||||
@ -53,14 +54,18 @@ namespace Net {
|
||||
HTTPServerConnection::HTTPServerConnection(const StreamSocket& socket, HTTPServerParams::Ptr pParams, HTTPRequestHandlerFactory::Ptr pFactory):
|
||||
TCPServerConnection(socket),
|
||||
_pParams(pParams),
|
||||
_pFactory(pFactory)
|
||||
_pFactory(pFactory),
|
||||
_stopped(false)
|
||||
{
|
||||
poco_check_ptr (pFactory);
|
||||
|
||||
_pFactory->serverStopped += Poco::delegate(this, &HTTPServerConnection::onServerStopped);
|
||||
}
|
||||
|
||||
|
||||
HTTPServerConnection::~HTTPServerConnection()
|
||||
{
|
||||
_pFactory->serverStopped -= Poco::delegate(this, &HTTPServerConnection::onServerStopped);
|
||||
}
|
||||
|
||||
|
||||
@ -68,10 +73,12 @@ void HTTPServerConnection::run()
|
||||
{
|
||||
std::string server = _pParams->getSoftwareVersion();
|
||||
HTTPServerSession session(socket(), _pParams);
|
||||
while (session.hasMoreRequests())
|
||||
while (!_stopped && session.hasMoreRequests())
|
||||
{
|
||||
try
|
||||
{
|
||||
Poco::FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
HTTPServerResponseImpl response(session);
|
||||
HTTPServerRequestImpl request(response, session, _pParams);
|
||||
|
||||
@ -124,4 +131,32 @@ void HTTPServerConnection::sendErrorResponse(HTTPServerSession& session, HTTPRes
|
||||
}
|
||||
|
||||
|
||||
void HTTPServerConnection::onServerStopped(const bool& abortCurrent)
|
||||
{
|
||||
_stopped = true;
|
||||
if (abortCurrent)
|
||||
{
|
||||
try
|
||||
{
|
||||
socket().shutdown();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Poco::FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
try
|
||||
{
|
||||
socket().shutdown();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Net
|
||||
|
@ -59,7 +59,7 @@ RawSocket::RawSocket(IPAddress::Family family, int proto):
|
||||
|
||||
|
||||
RawSocket::RawSocket(const SocketAddress& address, bool reuseAddress):
|
||||
Socket(new RawSocketImpl)
|
||||
Socket(new RawSocketImpl(address.family()))
|
||||
{
|
||||
bind(address, reuseAddress);
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ StreamSocket::StreamSocket(): Socket(new StreamSocketImpl)
|
||||
}
|
||||
|
||||
|
||||
StreamSocket::StreamSocket(const SocketAddress& address): Socket(new StreamSocketImpl)
|
||||
StreamSocket::StreamSocket(const SocketAddress& address): Socket(new StreamSocketImpl(address.family()))
|
||||
{
|
||||
connect(address);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user