mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-30 05:29:41 +01:00
Merge branch 'poco-1.10.0' into devel
This commit is contained in:
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "Poco/Crypto/Crypto.h"
|
#include "Poco/Crypto/Crypto.h"
|
||||||
|
#include "Poco/Crypto/CryptoTransform.h"
|
||||||
#include "Poco/RefCountedObject.h"
|
#include "Poco/RefCountedObject.h"
|
||||||
#include "Poco/AutoPtr.h"
|
#include "Poco/AutoPtr.h"
|
||||||
#include <istream>
|
#include <istream>
|
||||||
@@ -30,9 +31,6 @@ namespace Poco {
|
|||||||
namespace Crypto {
|
namespace Crypto {
|
||||||
|
|
||||||
|
|
||||||
class CryptoTransform;
|
|
||||||
|
|
||||||
|
|
||||||
class Crypto_API Cipher: public Poco::RefCountedObject
|
class Crypto_API Cipher: public Poco::RefCountedObject
|
||||||
/// Represents the abstract base class from which all implementations of
|
/// Represents the abstract base class from which all implementations of
|
||||||
/// symmetric/asymmetric encryption algorithms must inherit. Use the CipherFactory
|
/// symmetric/asymmetric encryption algorithms must inherit. Use the CipherFactory
|
||||||
@@ -104,10 +102,10 @@ public:
|
|||||||
virtual const std::string& name() const = 0;
|
virtual const std::string& name() const = 0;
|
||||||
/// Returns the name of the Cipher.
|
/// Returns the name of the Cipher.
|
||||||
|
|
||||||
virtual CryptoTransform* createEncryptor() = 0;
|
virtual CryptoTransform::Ptr createEncryptor() = 0;
|
||||||
/// Creates an encryptor object to be used with a CryptoStream.
|
/// Creates an encryptor object to be used with a CryptoStream.
|
||||||
|
|
||||||
virtual CryptoTransform* createDecryptor() = 0;
|
virtual CryptoTransform::Ptr createDecryptor() = 0;
|
||||||
/// Creates a decryptor object to be used with a CryptoStream.
|
/// Creates a decryptor object to be used with a CryptoStream.
|
||||||
|
|
||||||
virtual std::string encryptString(const std::string& str, Encoding encoding = ENC_NONE);
|
virtual std::string encryptString(const std::string& str, Encoding encoding = ENC_NONE);
|
||||||
|
|||||||
@@ -42,10 +42,10 @@ public:
|
|||||||
const std::string& name() const;
|
const std::string& name() const;
|
||||||
/// Returns the name of the cipher.
|
/// Returns the name of the cipher.
|
||||||
|
|
||||||
CryptoTransform* createEncryptor();
|
CryptoTransform::Ptr createEncryptor();
|
||||||
/// Creates an encryptor object.
|
/// Creates an encryptor object.
|
||||||
|
|
||||||
CryptoTransform* createDecryptor();
|
CryptoTransform::Ptr createDecryptor();
|
||||||
/// Creates a decryptor object.
|
/// Creates a decryptor object.
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "Poco/Crypto/Crypto.h"
|
#include "Poco/Crypto/Crypto.h"
|
||||||
|
#include "Poco/Crypto/CryptoTransform.h"
|
||||||
#include "Poco/BufferedStreamBuf.h"
|
#include "Poco/BufferedStreamBuf.h"
|
||||||
#include "Poco/Buffer.h"
|
#include "Poco/Buffer.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@@ -38,8 +39,8 @@ class Crypto_API CryptoStreamBuf: public Poco::BufferedStreamBuf
|
|||||||
/// going through it.
|
/// going through it.
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CryptoStreamBuf(std::istream& istr, CryptoTransform* pTransform, std::streamsize bufferSize = 8192);
|
CryptoStreamBuf(std::istream& istr, CryptoTransform::Ptr pTransform, std::streamsize bufferSize = 8192);
|
||||||
CryptoStreamBuf(std::ostream& ostr, CryptoTransform* pTransform, std::streamsize bufferSize = 8192);
|
CryptoStreamBuf(std::ostream& ostr, CryptoTransform::Ptr pTransform, std::streamsize bufferSize = 8192);
|
||||||
|
|
||||||
virtual ~CryptoStreamBuf();
|
virtual ~CryptoStreamBuf();
|
||||||
|
|
||||||
@@ -51,7 +52,7 @@ protected:
|
|||||||
int writeToDevice(const char* buffer, std::streamsize length);
|
int writeToDevice(const char* buffer, std::streamsize length);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CryptoTransform* _pTransform;
|
CryptoTransform::Ptr _pTransform;
|
||||||
std::istream* _pIstr;
|
std::istream* _pIstr;
|
||||||
std::ostream* _pOstr;
|
std::ostream* _pOstr;
|
||||||
bool _eof;
|
bool _eof;
|
||||||
@@ -70,8 +71,8 @@ class Crypto_API CryptoIOS: public virtual std::ios
|
|||||||
/// stream buffer and base classes.
|
/// stream buffer and base classes.
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CryptoIOS(std::istream& istr, CryptoTransform* pTransform, std::streamsize bufferSize = 8192);
|
CryptoIOS(std::istream& istr, CryptoTransform::Ptr pTransform, std::streamsize bufferSize = 8192);
|
||||||
CryptoIOS(std::ostream& ostr, CryptoTransform* pTransform, std::streamsize bufferSize = 8192);
|
CryptoIOS(std::ostream& ostr, CryptoTransform::Ptr pTransform, std::streamsize bufferSize = 8192);
|
||||||
~CryptoIOS();
|
~CryptoIOS();
|
||||||
CryptoStreamBuf* rdbuf();
|
CryptoStreamBuf* rdbuf();
|
||||||
|
|
||||||
@@ -89,7 +90,7 @@ class Crypto_API CryptoInputStream: public CryptoIOS, public std::istream
|
|||||||
/// respectively.
|
/// respectively.
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CryptoInputStream(std::istream& istr, CryptoTransform* pTransform, std::streamsize bufferSize = 8192);
|
CryptoInputStream(std::istream& istr, CryptoTransform::Ptr pTransform, std::streamsize bufferSize = 8192);
|
||||||
/// Create a new CryptoInputStream object. The CryptoInputStream takes the
|
/// Create a new CryptoInputStream object. The CryptoInputStream takes the
|
||||||
/// ownership of the given CryptoTransform object.
|
/// ownership of the given CryptoTransform object.
|
||||||
|
|
||||||
@@ -113,7 +114,7 @@ class Crypto_API CryptoOutputStream: public CryptoIOS, public std::ostream
|
|||||||
/// to ensure completion of cryptographic transformation.
|
/// to ensure completion of cryptographic transformation.
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CryptoOutputStream(std::ostream& ostr, CryptoTransform* pTransform, std::streamsize bufferSize = 8192);
|
CryptoOutputStream(std::ostream& ostr, CryptoTransform::Ptr pTransform, std::streamsize bufferSize = 8192);
|
||||||
/// Create a new CryptoOutputStream object. The CryptoOutputStream takes the
|
/// Create a new CryptoOutputStream object. The CryptoOutputStream takes the
|
||||||
/// ownership of the given CryptoTransform object.
|
/// ownership of the given CryptoTransform object.
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "Poco/Crypto/Crypto.h"
|
#include "Poco/Crypto/Crypto.h"
|
||||||
|
#include "Poco/SharedPtr.h"
|
||||||
#include <ios>
|
#include <ios>
|
||||||
|
|
||||||
|
|
||||||
@@ -35,6 +36,8 @@ class Crypto_API CryptoTransform
|
|||||||
/// perform encryption or decryption of data.
|
/// perform encryption or decryption of data.
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
using Ptr = Poco::SharedPtr<CryptoTransform>;
|
||||||
|
|
||||||
CryptoTransform();
|
CryptoTransform();
|
||||||
/// Creates a new CryptoTransform object.
|
/// Creates a new CryptoTransform object.
|
||||||
|
|
||||||
|
|||||||
@@ -49,10 +49,10 @@ public:
|
|||||||
const std::string& name() const;
|
const std::string& name() const;
|
||||||
/// Returns the name of the Cipher.
|
/// Returns the name of the Cipher.
|
||||||
|
|
||||||
CryptoTransform* createEncryptor();
|
CryptoTransform::Ptr createEncryptor();
|
||||||
/// Creates an encryptor object.
|
/// Creates an encryptor object.
|
||||||
|
|
||||||
CryptoTransform* createDecryptor();
|
CryptoTransform::Ptr createDecryptor();
|
||||||
/// Creates a decryptor object.
|
/// Creates a decryptor object.
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -255,14 +255,14 @@ CipherImpl::~CipherImpl()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CryptoTransform* CipherImpl::createEncryptor()
|
CryptoTransform::Ptr CipherImpl::createEncryptor()
|
||||||
{
|
{
|
||||||
CipherKeyImpl::Ptr p = _key.impl();
|
CipherKeyImpl::Ptr p = _key.impl();
|
||||||
return new CryptoTransformImpl(p->cipher(), p->getKey(), p->getIV(), CryptoTransformImpl::DIR_ENCRYPT);
|
return new CryptoTransformImpl(p->cipher(), p->getKey(), p->getIV(), CryptoTransformImpl::DIR_ENCRYPT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CryptoTransform* CipherImpl::createDecryptor()
|
CryptoTransform::Ptr CipherImpl::createDecryptor()
|
||||||
{
|
{
|
||||||
CipherKeyImpl::Ptr p = _key.impl();
|
CipherKeyImpl::Ptr p = _key.impl();
|
||||||
return new CryptoTransformImpl(p->cipher(), p->getKey(), p->getIV(), CryptoTransformImpl::DIR_DECRYPT);
|
return new CryptoTransformImpl(p->cipher(), p->getKey(), p->getIV(), CryptoTransformImpl::DIR_DECRYPT);
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ namespace Crypto {
|
|||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
CryptoStreamBuf::CryptoStreamBuf(std::istream& istr, CryptoTransform* pTransform, std::streamsize bufferSize):
|
CryptoStreamBuf::CryptoStreamBuf(std::istream& istr, CryptoTransform::Ptr pTransform, std::streamsize bufferSize):
|
||||||
Poco::BufferedStreamBuf(bufferSize, std::ios::in),
|
Poco::BufferedStreamBuf(bufferSize, std::ios::in),
|
||||||
_pTransform(pTransform),
|
_pTransform(pTransform),
|
||||||
_pIstr(&istr),
|
_pIstr(&istr),
|
||||||
@@ -45,7 +45,7 @@ CryptoStreamBuf::CryptoStreamBuf(std::istream& istr, CryptoTransform* pTransform
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CryptoStreamBuf::CryptoStreamBuf(std::ostream& ostr, CryptoTransform* pTransform, std::streamsize bufferSize):
|
CryptoStreamBuf::CryptoStreamBuf(std::ostream& ostr, CryptoTransform::Ptr pTransform, std::streamsize bufferSize):
|
||||||
Poco::BufferedStreamBuf(bufferSize, std::ios::out),
|
Poco::BufferedStreamBuf(bufferSize, std::ios::out),
|
||||||
_pTransform(pTransform),
|
_pTransform(pTransform),
|
||||||
_pIstr(0),
|
_pIstr(0),
|
||||||
@@ -67,7 +67,6 @@ CryptoStreamBuf::~CryptoStreamBuf()
|
|||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
delete _pTransform;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -193,14 +192,14 @@ int CryptoStreamBuf::writeToDevice(const char* buffer, std::streamsize length)
|
|||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
CryptoIOS::CryptoIOS(std::istream& istr, CryptoTransform* pTransform, std::streamsize bufferSize):
|
CryptoIOS::CryptoIOS(std::istream& istr, CryptoTransform::Ptr pTransform, std::streamsize bufferSize):
|
||||||
_buf(istr, pTransform, bufferSize)
|
_buf(istr, pTransform, bufferSize)
|
||||||
{
|
{
|
||||||
poco_ios_init(&_buf);
|
poco_ios_init(&_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CryptoIOS::CryptoIOS(std::ostream& ostr, CryptoTransform* pTransform, std::streamsize bufferSize):
|
CryptoIOS::CryptoIOS(std::ostream& ostr, CryptoTransform::Ptr pTransform, std::streamsize bufferSize):
|
||||||
_buf(ostr, pTransform, bufferSize)
|
_buf(ostr, pTransform, bufferSize)
|
||||||
{
|
{
|
||||||
poco_ios_init(&_buf);
|
poco_ios_init(&_buf);
|
||||||
@@ -223,7 +222,7 @@ CryptoStreamBuf* CryptoIOS::rdbuf()
|
|||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
CryptoInputStream::CryptoInputStream(std::istream& istr, CryptoTransform* pTransform, std::streamsize bufferSize):
|
CryptoInputStream::CryptoInputStream(std::istream& istr, CryptoTransform::Ptr pTransform, std::streamsize bufferSize):
|
||||||
CryptoIOS(istr, pTransform, bufferSize),
|
CryptoIOS(istr, pTransform, bufferSize),
|
||||||
std::istream(&_buf)
|
std::istream(&_buf)
|
||||||
{
|
{
|
||||||
@@ -247,7 +246,7 @@ CryptoInputStream::~CryptoInputStream()
|
|||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
CryptoOutputStream::CryptoOutputStream(std::ostream& ostr, CryptoTransform* pTransform, std::streamsize bufferSize):
|
CryptoOutputStream::CryptoOutputStream(std::ostream& ostr, CryptoTransform::Ptr pTransform, std::streamsize bufferSize):
|
||||||
CryptoIOS(ostr, pTransform, bufferSize),
|
CryptoIOS(ostr, pTransform, bufferSize),
|
||||||
std::ostream(&_buf)
|
std::ostream(&_buf)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -329,13 +329,13 @@ RSACipherImpl::~RSACipherImpl()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CryptoTransform* RSACipherImpl::createEncryptor()
|
CryptoTransform::Ptr RSACipherImpl::createEncryptor()
|
||||||
{
|
{
|
||||||
return new RSAEncryptImpl(_key.impl()->getRSA(), _paddingMode);
|
return new RSAEncryptImpl(_key.impl()->getRSA(), _paddingMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CryptoTransform* RSACipherImpl::createDecryptor()
|
CryptoTransform::Ptr RSACipherImpl::createDecryptor()
|
||||||
{
|
{
|
||||||
return new RSADecryptImpl(_key.impl()->getRSA(), _paddingMode);
|
return new RSADecryptImpl(_key.impl()->getRSA(), _paddingMode);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -222,7 +222,7 @@ void CryptoTest::testEncryptDecryptGCM()
|
|||||||
for (std::size_t n = 1; n < MAX_DATA_SIZE; n++)
|
for (std::size_t n = 1; n < MAX_DATA_SIZE; n++)
|
||||||
{
|
{
|
||||||
std::stringstream str;
|
std::stringstream str;
|
||||||
CryptoTransform* pEncryptor = pCipher->createEncryptor();
|
CryptoTransform::Ptr pEncryptor = pCipher->createEncryptor();
|
||||||
CryptoOutputStream encryptorStream(str, pEncryptor);
|
CryptoOutputStream encryptorStream(str, pEncryptor);
|
||||||
std::string in(n, 'x');
|
std::string in(n, 'x');
|
||||||
encryptorStream << in;
|
encryptorStream << in;
|
||||||
@@ -231,7 +231,7 @@ void CryptoTest::testEncryptDecryptGCM()
|
|||||||
|
|
||||||
std::string tag = pEncryptor->getTag();
|
std::string tag = pEncryptor->getTag();
|
||||||
|
|
||||||
CryptoTransform* pDecryptor = pCipher->createDecryptor();
|
CryptoTransform::Ptr pDecryptor = pCipher->createDecryptor();
|
||||||
pDecryptor->setTag(tag);
|
pDecryptor->setTag(tag);
|
||||||
CryptoInputStream decryptorStream(str, pDecryptor);
|
CryptoInputStream decryptorStream(str, pDecryptor);
|
||||||
std::string out;
|
std::string out;
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
#include "Poco/StreamCopier.h"
|
#include "Poco/StreamCopier.h"
|
||||||
#include "CppUnit/TestCaller.h"
|
#include "CppUnit/TestCaller.h"
|
||||||
#include "CppUnit/TestSuite.h"
|
#include "CppUnit/TestSuite.h"
|
||||||
|
#include <memory>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@@ -41,12 +42,12 @@ void EVPTest::testRSAEVPPKey()
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
RSAKey* key = new RSAKey(RSAKey::KL_1024, RSAKey::EXP_SMALL);
|
std::unique_ptr<RSAKey> key(new RSAKey(RSAKey::KL_1024, RSAKey::EXP_SMALL));
|
||||||
assertTrue(key->type() == Poco::Crypto::KeyPair::KT_RSA);
|
assertTrue(key->type() == Poco::Crypto::KeyPair::KT_RSA);
|
||||||
// construct EVPPKey from RSAKey*
|
// construct EVPPKey from RSAKey*
|
||||||
EVPPKey* pKey = new EVPPKey(key);
|
EVPPKey* pKey = new EVPPKey(key.get());
|
||||||
// EVPPKey increments reference count, so freeing the original must be ok
|
// EVPPKey increments reference count, so freeing the original must be ok
|
||||||
delete key;
|
key.reset();
|
||||||
|
|
||||||
assertTrue (!pKey->isSupported(0));
|
assertTrue (!pKey->isSupported(0));
|
||||||
assertTrue (!pKey->isSupported(-1));
|
assertTrue (!pKey->isSupported(-1));
|
||||||
@@ -54,11 +55,11 @@ void EVPTest::testRSAEVPPKey()
|
|||||||
assertTrue (pKey->type() == EVP_PKEY_RSA);
|
assertTrue (pKey->type() == EVP_PKEY_RSA);
|
||||||
|
|
||||||
// construct RSAKey from const EVPPKey&
|
// construct RSAKey from const EVPPKey&
|
||||||
key = new RSAKey(*pKey);
|
key.reset(new RSAKey(*pKey));
|
||||||
delete pKey;
|
delete pKey;
|
||||||
assertTrue(key->type() == Poco::Crypto::KeyPair::KT_RSA);
|
assertTrue(key->type() == Poco::Crypto::KeyPair::KT_RSA);
|
||||||
// construct EVPPKey from RSAKey*
|
// construct EVPPKey from RSAKey*
|
||||||
pKey = new EVPPKey(key);
|
pKey = new EVPPKey(key.get());
|
||||||
assertTrue (pKey->type() == EVP_PKEY_RSA);
|
assertTrue (pKey->type() == EVP_PKEY_RSA);
|
||||||
|
|
||||||
BIO* bioPriv1 = BIO_new(BIO_s_mem());
|
BIO* bioPriv1 = BIO_new(BIO_s_mem());
|
||||||
|
|||||||
@@ -163,14 +163,15 @@ void SessionImpl::open(const std::string& connect)
|
|||||||
if (rc == SQLITE_OK) break;
|
if (rc == SQLITE_OK) break;
|
||||||
if (sw.elapsedSeconds() >= tout)
|
if (sw.elapsedSeconds() >= tout)
|
||||||
{
|
{
|
||||||
close();
|
|
||||||
Utility::throwException(_pDB, rc);
|
Utility::throwException(_pDB, rc);
|
||||||
}
|
}
|
||||||
else Thread::sleep(10);
|
Thread::sleep(10);
|
||||||
|
close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (SQLiteException& ex)
|
catch (SQLiteException& ex)
|
||||||
{
|
{
|
||||||
|
close();
|
||||||
throw ConnectionFailedException(ex.displayText());
|
throw ConnectionFailedException(ex.displayText());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3410,7 +3410,7 @@ void SQLiteTest::testIllegalFilePath()
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Session tmp (Poco::Data::SQLite::Connector::KEY, "\\/some\\/illegal\\/path\\/dummy.db", 1);
|
Session tmp(Poco::Data::SQLite::Connector::KEY, "\\/some\\/illegal\\/path\\/dummy.db", 1);
|
||||||
fail("must fail");
|
fail("must fail");
|
||||||
}
|
}
|
||||||
catch (ConnectionFailedException&)
|
catch (ConnectionFailedException&)
|
||||||
|
|||||||
@@ -94,8 +94,8 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Buffer(Buffer&& other) :
|
Buffer(Buffer&& other) noexcept:
|
||||||
/// Copy constructor.
|
/// Move constructor.
|
||||||
_capacity(other._capacity),
|
_capacity(other._capacity),
|
||||||
_used(other._used),
|
_used(other._used),
|
||||||
_ptr(other._ptr),
|
_ptr(other._ptr),
|
||||||
@@ -119,21 +119,20 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Buffer& operator = (Buffer&& other)
|
Buffer& operator = (Buffer&& other) noexcept
|
||||||
/// Assignment operator.
|
/// Move assignment operator.
|
||||||
{
|
{
|
||||||
if (this != &other)
|
if (_ownMem) delete [] _ptr;
|
||||||
{
|
|
||||||
_capacity = other._capacity;
|
|
||||||
_used = other._used;
|
|
||||||
_ptr = other._ptr;
|
|
||||||
_ownMem = other._ownMem;
|
|
||||||
|
|
||||||
other._capacity = 0;
|
_capacity = other._capacity;
|
||||||
other._used = 0;
|
_used = other._used;
|
||||||
other._ownMem = false;
|
_ptr = other._ptr;
|
||||||
other._ptr = nullptr;
|
_ownMem = other._ownMem;
|
||||||
}
|
|
||||||
|
other._capacity = 0;
|
||||||
|
other._used = 0;
|
||||||
|
other._ownMem = false;
|
||||||
|
other._ptr = nullptr;
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,7 +87,8 @@ namespace
|
|||||||
_reactor(reactor),
|
_reactor(reactor),
|
||||||
_or(*this, &ClientServiceHandler::onReadable),
|
_or(*this, &ClientServiceHandler::onReadable),
|
||||||
_ow(*this, &ClientServiceHandler::onWritable),
|
_ow(*this, &ClientServiceHandler::onWritable),
|
||||||
_ot(*this, &ClientServiceHandler::onTimeout)
|
_ot(*this, &ClientServiceHandler::onTimeout),
|
||||||
|
_os(*this, &ClientServiceHandler::onShutdown)
|
||||||
{
|
{
|
||||||
_timeout = false;
|
_timeout = false;
|
||||||
_readableError = false;
|
_readableError = false;
|
||||||
@@ -102,10 +103,15 @@ namespace
|
|||||||
checkTimeoutObserverCount(0);
|
checkTimeoutObserverCount(0);
|
||||||
_reactor.addEventHandler(_socket, _ot);
|
_reactor.addEventHandler(_socket, _ot);
|
||||||
checkTimeoutObserverCount(1);
|
checkTimeoutObserverCount(1);
|
||||||
|
_reactor.addEventHandler(_socket, _os);
|
||||||
}
|
}
|
||||||
|
|
||||||
~ClientServiceHandler()
|
~ClientServiceHandler()
|
||||||
{
|
{
|
||||||
|
_reactor.removeEventHandler(_socket, _or);
|
||||||
|
_reactor.removeEventHandler(_socket, _ow);
|
||||||
|
_reactor.removeEventHandler(_socket, _ot);
|
||||||
|
_reactor.removeEventHandler(_socket, _os);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onReadable(ReadableNotification* pNf)
|
void onReadable(ReadableNotification* pNf)
|
||||||
@@ -154,6 +160,12 @@ namespace
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void onShutdown(ShutdownNotification* pNf)
|
||||||
|
{
|
||||||
|
pNf->release();
|
||||||
|
delete this;
|
||||||
|
}
|
||||||
|
|
||||||
static std::string data()
|
static std::string data()
|
||||||
{
|
{
|
||||||
return _data;
|
return _data;
|
||||||
@@ -232,6 +244,7 @@ namespace
|
|||||||
Observer<ClientServiceHandler, ReadableNotification> _or;
|
Observer<ClientServiceHandler, ReadableNotification> _or;
|
||||||
Observer<ClientServiceHandler, WritableNotification> _ow;
|
Observer<ClientServiceHandler, WritableNotification> _ow;
|
||||||
Observer<ClientServiceHandler, TimeoutNotification> _ot;
|
Observer<ClientServiceHandler, TimeoutNotification> _ot;
|
||||||
|
Observer<ClientServiceHandler, ShutdownNotification> _os;
|
||||||
std::stringstream _str;
|
std::stringstream _str;
|
||||||
static std::string _data;
|
static std::string _data;
|
||||||
static bool _readableError;
|
static bool _readableError;
|
||||||
|
|||||||
Reference in New Issue
Block a user