diff options
author | monster <monster@ydb.tech> | 2022-07-07 14:41:37 +0300 |
---|---|---|
committer | monster <monster@ydb.tech> | 2022-07-07 14:41:37 +0300 |
commit | 06e5c21a835c0e923506c4ff27929f34e00761c2 (patch) | |
tree | 75efcbc6854ef9bd476eb8bf00cc5c900da436a2 /contrib/libs/poco/Net | |
parent | 03f024c4412e3aa613bb543cf1660176320ba8f4 (diff) | |
download | ydb-06e5c21a835c0e923506c4ff27929f34e00761c2.tar.gz |
fix ya.make
Diffstat (limited to 'contrib/libs/poco/Net')
6 files changed, 1 insertions, 850 deletions
diff --git a/contrib/libs/poco/Net/.yandex_meta/licenses.list.txt b/contrib/libs/poco/Net/.yandex_meta/licenses.list.txt deleted file mode 100644 index 66ce1e81df..0000000000 --- a/contrib/libs/poco/Net/.yandex_meta/licenses.list.txt +++ /dev/null @@ -1,118 +0,0 @@ -====================BSL-1.0==================== -// SPDX-License-Identifier: BSL-1.0 - - -====================BSL-1.0==================== -Boost Software License - Version 1.0 - August 17th, 2003 - -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. - ---------------------------------------------------------------------------- -Note: -Individual files contain the following tag instead of the full license text. - - SPDX-License-Identifier: BSL-1.0 - -This enables machine processing of license information based on the SPDX -License Identifiers that are here available: http://spdx.org/licenses/ - -====================COPYRIGHT==================== -// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. - - -====================COPYRIGHT==================== -// Copyright (c) 2005-2007, Applied Informatics Software Engineering GmbH. -// and Contributors. - - -====================COPYRIGHT==================== -// Copyright (c) 2005-2008, Applied Informatics Software Engineering GmbH. -// and Contributors. - - -====================COPYRIGHT==================== -// Copyright (c) 2005-2011, Applied Informatics Software Engineering GmbH. -// and Contributors. - - -====================COPYRIGHT==================== -// Copyright (c) 2005-2012, Applied Informatics Software Engineering GmbH. -// and Contributors. - - -====================COPYRIGHT==================== -// Copyright (c) 2006, Applied Informatics Software Engineering GmbH. -// and Contributors. - - -====================COPYRIGHT==================== -// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. -// and Contributors. - - -====================COPYRIGHT==================== -// Copyright (c) 2007-2011, Applied Informatics Software Engineering GmbH. -// and Contributors. - - -====================COPYRIGHT==================== -// Copyright (c) 2011, Anton V. Yabchinskiy (arn at bestmx dot ru). -// Copyright (c) 2012, Applied Informatics Software Engineering GmbH. -// and Contributors. - - -====================COPYRIGHT==================== -// Copyright (c) 2012, Applied Informatics Software Engineering GmbH. -// and Contributors. - - -====================COPYRIGHT==================== -// Copyright (c) 2014, Applied Informatics Software Engineering GmbH. -// and Contributors. - - -====================COPYRIGHT==================== -// Copyright (c) 2016, Applied Informatics Software Engineering GmbH. -// All rights reserved. - - -====================Custom-Punycode==================== - License on the original code: - - punycode-spec 1.0.3 (2006-Mar-23-Thu) - http://www.nicemice.net/idn/ - Adam M. Costello - http://www.nicemice.net/amc/ - - B. Disclaimer and license - - Regarding this entire document or any portion of it (including - the pseudocode and C code), the author makes no guarantees and - is not responsible for any damage resulting from its use. The - author grants irrevocable permission to anyone to use, modify, - and distribute it in any way that does not diminish the rights - of anyone else to use, modify, and distribute it, provided that - redistributed derivative works do not contain misleading author or - version information. Derivative works need not be licensed under - similar terms. diff --git a/contrib/libs/poco/Net/CMakeLists.txt b/contrib/libs/poco/Net/CMakeLists.txt index e8c98bfd99..c031ddb850 100644 --- a/contrib/libs/poco/Net/CMakeLists.txt +++ b/contrib/libs/poco/Net/CMakeLists.txt @@ -6,6 +6,6 @@ # original buildsystem will not be accepted. -if (UNIX AND NOT APPLE) +if (UNIX) include(CMakeLists.linux.txt) endif() diff --git a/contrib/libs/poco/Net/include/Poco/Net/ParallelSocketAcceptor.h b/contrib/libs/poco/Net/include/Poco/Net/ParallelSocketAcceptor.h deleted file mode 100644 index 514bcfbfa1..0000000000 --- a/contrib/libs/poco/Net/include/Poco/Net/ParallelSocketAcceptor.h +++ /dev/null @@ -1,233 +0,0 @@ -// -// ParallelSocketAcceptor.h -// -// Library: Net -// Package: Reactor -// Module: ParallelSocketAcceptor -// -// Definition of the ParallelSocketAcceptor class. -// -// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// SPDX-License-Identifier: BSL-1.0 -// - - -#ifndef Net_ParallelSocketAcceptor_INCLUDED -#define Net_ParallelSocketAcceptor_INCLUDED - - -#include "Poco/Net/ParallelSocketReactor.h" -#include "Poco/Net/StreamSocket.h" -#include "Poco/Net/ServerSocket.h" -#include "Poco/Environment.h" -#include "Poco/NObserver.h" -#include "Poco/SharedPtr.h" -#include <vector> - - -using Poco::Net::Socket; -using Poco::Net::SocketReactor; -using Poco::Net::ServerSocket; -using Poco::Net::StreamSocket; -using Poco::NObserver; -using Poco::AutoPtr; - - -namespace Poco { -namespace Net { - - -template <class ServiceHandler, class SR> -class ParallelSocketAcceptor - /// This class implements the Acceptor part of the Acceptor-Connector design pattern. - /// Only the difference from single-threaded version is documented here, For full - /// description see Poco::Net::SocketAcceptor documentation. - /// - /// This is a multi-threaded version of SocketAcceptor, it differs from the - /// single-threaded version in number of reactors (defaulting to number of processors) - /// that can be specified at construction time and is rotated in a round-robin fashion - /// by event handler. See ParallelSocketAcceptor::onAccept and - /// ParallelSocketAcceptor::createServiceHandler documentation and implementation for - /// details. -{ -public: - typedef Poco::Net::ParallelSocketReactor<SR> ParallelReactor; - - explicit ParallelSocketAcceptor(ServerSocket& socket, - unsigned threads = Poco::Environment::processorCount()): - _socket(socket), - _pReactor(0), - _threads(threads), - _next(0) - /// Creates a ParallelSocketAcceptor using the given ServerSocket, - /// sets number of threads and populates the reactors vector. - { - init(); - } - - ParallelSocketAcceptor(ServerSocket& socket, - SocketReactor& reactor, - unsigned threads = Poco::Environment::processorCount()): - _socket(socket), - _pReactor(&reactor), - _threads(threads), - _next(0) - /// Creates a ParallelSocketAcceptor using the given ServerSocket, sets the - /// number of threads, populates the reactors vector and registers itself - /// with the given SocketReactor. - { - init(); - _pReactor->addEventHandler(_socket, - Poco::Observer<ParallelSocketAcceptor, - ReadableNotification>(*this, &ParallelSocketAcceptor::onAccept)); - } - - virtual ~ParallelSocketAcceptor() - /// Destroys the ParallelSocketAcceptor. - { - try - { - if (_pReactor) - { - _pReactor->removeEventHandler(_socket, - Poco::Observer<ParallelSocketAcceptor, - ReadableNotification>(*this, &ParallelSocketAcceptor::onAccept)); - } - } - catch (...) - { - poco_unexpected(); - } - } - - void setReactor(SocketReactor& reactor) - /// Sets the reactor for this acceptor. - { - _pReactor = &reactor; - if (!_pReactor->hasEventHandler(_socket, - Poco::Observer<ParallelSocketAcceptor, - ReadableNotification>(*this, &ParallelSocketAcceptor::onAccept))) - { - registerAcceptor(reactor); - } - } - - virtual void registerAcceptor(SocketReactor& reactor) - /// Registers the ParallelSocketAcceptor with a SocketReactor. - /// - /// A subclass can override this function to e.g. - /// register an event handler for timeout event. - /// - /// The overriding method must either call the base class - /// implementation or register the accept handler on its own. - { - if (_pReactor) - throw Poco::InvalidAccessException("Acceptor already registered."); - - _pReactor = &reactor; - _pReactor->addEventHandler(_socket, - Poco::Observer<ParallelSocketAcceptor, - ReadableNotification>(*this, &ParallelSocketAcceptor::onAccept)); - } - - virtual void unregisterAcceptor() - /// Unregisters the ParallelSocketAcceptor. - /// - /// A subclass can override this function to e.g. - /// unregister its event handler for a timeout event. - /// - /// The overriding method must either call the base class - /// implementation or unregister the accept handler on its own. - { - if (_pReactor) - { - _pReactor->removeEventHandler(_socket, - Poco::Observer<ParallelSocketAcceptor, - ReadableNotification>(*this, &ParallelSocketAcceptor::onAccept)); - } - } - - void onAccept(ReadableNotification* pNotification) - /// Accepts connection and creates event handler. - { - pNotification->release(); - StreamSocket sock = _socket.acceptConnection(); - _pReactor->wakeUp(); - createServiceHandler(sock); - } - -protected: - virtual ServiceHandler* createServiceHandler(StreamSocket& socket) - /// Create and initialize a new ServiceHandler instance. - /// - /// Subclasses can override this method. - { - std::size_t next = _next++; - if (_next == _reactors.size()) _next = 0; - _reactors[next]->wakeUp(); - return new ServiceHandler(socket, *_reactors[next]); - } - - SocketReactor* reactor() - /// Returns a pointer to the SocketReactor where - /// this SocketAcceptor is registered. - /// - /// The pointer may be null. - { - return _pReactor; - } - - Socket& socket() - /// Returns a reference to the SocketAcceptor's socket. - { - return _socket; - } - - void init() - /// Populates the reactors vector. - { - poco_assert (_threads > 0); - - for (unsigned i = 0; i < _threads; ++i) - _reactors.push_back(new ParallelReactor); - } - - typedef std::vector<typename ParallelReactor::Ptr> ReactorVec; - - ReactorVec& reactors() - /// Returns reference to vector of reactors. - { - return _reactors; - } - - SocketReactor* reactor(std::size_t idx) - /// Returns reference to the reactor at position idx. - { - return _reactors.at(idx).get(); - } - - std::size_t& next() - /// Returns reference to the next reactor index. - { - return _next; - } - -private: - ParallelSocketAcceptor(); - ParallelSocketAcceptor(const ParallelSocketAcceptor&); - ParallelSocketAcceptor& operator = (const ParallelSocketAcceptor&); - - ServerSocket _socket; - SocketReactor* _pReactor; - unsigned _threads; - ReactorVec _reactors; - std::size_t _next; -}; - - -} } // namespace Poco::Net - - -#endif // Net_ParallelSocketAcceptor_INCLUDED diff --git a/contrib/libs/poco/Net/include/Poco/Net/ParallelSocketReactor.h b/contrib/libs/poco/Net/include/Poco/Net/ParallelSocketReactor.h deleted file mode 100644 index a7631ce1d9..0000000000 --- a/contrib/libs/poco/Net/include/Poco/Net/ParallelSocketReactor.h +++ /dev/null @@ -1,90 +0,0 @@ -// -// ParallelSocketReactor.h -// -// Library: Net -// Package: Reactor -// Module: ParallelSocketReactor -// -// Definition of the ParallelSocketReactor class. -// -// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// SPDX-License-Identifier: BSL-1.0 -// - - -#ifndef Net_ParallelSocketReactor_INCLUDED -#define Net_ParallelSocketReactor_INCLUDED - - -#include "Poco/Net/SocketReactor.h" -#include "Poco/Net/SocketNotification.h" -#include "Poco/Net/StreamSocket.h" -#include "Poco/Net/ServerSocket.h" -#include "Poco/NObserver.h" -#include "Poco/Thread.h" -#include "Poco/SharedPtr.h" - - -using Poco::Net::Socket; -using Poco::Net::SocketReactor; -using Poco::Net::ReadableNotification; -using Poco::Net::ShutdownNotification; -using Poco::Net::ServerSocket; -using Poco::Net::StreamSocket; -using Poco::NObserver; -using Poco::AutoPtr; -using Poco::Thread; - - -namespace Poco { -namespace Net { - - -template <class SR> -class ParallelSocketReactor: public SR -{ -public: - typedef Poco::SharedPtr<ParallelSocketReactor> Ptr; - - ParallelSocketReactor() - { - _thread.start(*this); - } - - ParallelSocketReactor(const Poco::Timespan& timeout): - SR(timeout) - { - _thread.start(*this); - } - - ~ParallelSocketReactor() - { - try - { - this->stop(); - _thread.join(); - } - catch (...) - { - poco_unexpected(); - } - } - -protected: - void onIdle() - { - SR::onIdle(); - Poco::Thread::yield(); - } - -private: - Poco::Thread _thread; -}; - - -} } // namespace Poco::Net - - -#endif // Net_ParallelSocketReactor_INCLUDED diff --git a/contrib/libs/poco/Net/include/Poco/Net/SocketAcceptor.h b/contrib/libs/poco/Net/include/Poco/Net/SocketAcceptor.h deleted file mode 100644 index c9021ecd0b..0000000000 --- a/contrib/libs/poco/Net/include/Poco/Net/SocketAcceptor.h +++ /dev/null @@ -1,196 +0,0 @@ -// -// SocketAcceptor.h -// -// Library: Net -// Package: Reactor -// Module: SocketAcceptor -// -// Definition of the SocketAcceptor class. -// -// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// SPDX-License-Identifier: BSL-1.0 -// - - -#ifndef Net_SocketAcceptor_INCLUDED -#define Net_SocketAcceptor_INCLUDED - - -#include "Poco/Net/Net.h" -#include "Poco/Net/SocketNotification.h" -#include "Poco/Net/SocketReactor.h" -#include "Poco/Net/ServerSocket.h" -#include "Poco/Net/StreamSocket.h" -#include "Poco/Observer.h" - - -namespace Poco { -namespace Net { - - -template <class ServiceHandler> -class SocketAcceptor - /// This class implements the Acceptor part of the - /// Acceptor-Connector design pattern. - /// - /// The Acceptor-Connector pattern has been described in the book - /// "Pattern Languages of Program Design 3", edited by Robert Martin, - /// Frank Buschmann and Dirk Riehle (Addison Wesley, 1997). - /// - /// The Acceptor-Connector design pattern decouples connection - /// establishment and service initialization in a distributed system - /// from the processing performed once a service is initialized. - /// This decoupling is achieved with three components: Acceptors, - /// Connectors and Service Handlers. - /// The SocketAcceptor passively waits for connection requests (usually - /// from a remote Connector) and establishes a connection upon - /// arrival of a connection requests. Also, a Service Handler is - /// initialized to process the data arriving via the connection in - /// an application-specific way. - /// - /// The SocketAcceptor sets up a ServerSocket and registers itself - /// for a ReadableNotification, denoting an incoming connection request. - /// - /// When the ServerSocket becomes readable the SocketAcceptor accepts - /// the connection request and creates a ServiceHandler to - /// service the connection. - /// - /// The ServiceHandler class must provide a constructor that - /// takes a StreamSocket and a SocketReactor as arguments, - /// e.g.: - /// MyServiceHandler(const StreamSocket& socket, ServiceReactor& reactor) - /// - /// When the ServiceHandler is done, it must destroy itself. - /// - /// Subclasses can override the createServiceHandler() factory method - /// if special steps are necessary to create a ServiceHandler object. -{ -public: - explicit SocketAcceptor(ServerSocket& socket): - _socket(socket), - _pReactor(0) - /// Creates a SocketAcceptor, using the given ServerSocket. - { - } - - SocketAcceptor(ServerSocket& socket, SocketReactor& reactor): - _socket(socket), - _pReactor(&reactor) - /// Creates a SocketAcceptor, using the given ServerSocket. - /// The SocketAcceptor registers itself with the given SocketReactor. - { - _pReactor->addEventHandler(_socket, Poco::Observer<SocketAcceptor, - ReadableNotification>(*this, &SocketAcceptor::onAccept)); - } - - virtual ~SocketAcceptor() - /// Destroys the SocketAcceptor. - { - try - { - if (_pReactor) - { - _pReactor->removeEventHandler(_socket, Poco::Observer<SocketAcceptor, - ReadableNotification>(*this, &SocketAcceptor::onAccept)); - } - } - catch (...) - { - poco_unexpected(); - } - } - - void setReactor(SocketReactor& reactor) - /// Sets the reactor for this acceptor. - { - _pReactor = &reactor; - if (!_pReactor->hasEventHandler(_socket, Poco::Observer<SocketAcceptor, - ReadableNotification>(*this, &SocketAcceptor::onAccept))) - { - registerAcceptor(reactor); - } - } - - virtual void registerAcceptor(SocketReactor& reactor) - /// Registers the SocketAcceptor with a SocketReactor. - /// - /// A subclass can override this function to e.g. - /// register an event handler for timeout event. - /// - /// If acceptor was constructed without providing reactor to it, - /// the override of this method must either call the base class - /// implementation or directly register the accept handler with - /// the reactor. - { - if (_pReactor) - throw Poco::InvalidAccessException("Acceptor already registered."); - - _pReactor = &reactor; - _pReactor->addEventHandler(_socket, Poco::Observer<SocketAcceptor, ReadableNotification>(*this, &SocketAcceptor::onAccept)); - } - - virtual void unregisterAcceptor() - /// Unregisters the SocketAcceptor. - /// - /// A subclass can override this function to e.g. - /// unregister its event handler for a timeout event. - /// - /// If the accept handler was registered with the reactor, - /// the overriding method must either call the base class - /// implementation or directly unregister the accept handler. - { - if (_pReactor) - { - _pReactor->removeEventHandler(_socket, Poco::Observer<SocketAcceptor, ReadableNotification>(*this, &SocketAcceptor::onAccept)); - } - } - - void onAccept(ReadableNotification* pNotification) - /// Accepts connection and creates event handler. - { - pNotification->release(); - StreamSocket sock = _socket.acceptConnection(); - _pReactor->wakeUp(); - createServiceHandler(sock); - } - -protected: - virtual ServiceHandler* createServiceHandler(StreamSocket& socket) - /// Create and initialize a new ServiceHandler instance. - /// - /// Subclasses can override this method. - { - return new ServiceHandler(socket, *_pReactor); - } - - SocketReactor* reactor() - /// Returns a pointer to the SocketReactor where - /// this SocketAcceptor is registered. - /// - /// The pointer may be null. - { - return _pReactor; - } - - Socket& socket() - /// Returns a reference to the SocketAcceptor's socket. - { - return _socket; - } - -private: - SocketAcceptor(); - SocketAcceptor(const SocketAcceptor&); - SocketAcceptor& operator = (const SocketAcceptor&); - - ServerSocket _socket; - SocketReactor* _pReactor; -}; - - -} } // namespace Poco::Net - - -#endif // Net_SocketAcceptor_INCLUDED diff --git a/contrib/libs/poco/Net/include/Poco/Net/SocketConnector.h b/contrib/libs/poco/Net/include/Poco/Net/SocketConnector.h deleted file mode 100644 index d3196c9f62..0000000000 --- a/contrib/libs/poco/Net/include/Poco/Net/SocketConnector.h +++ /dev/null @@ -1,212 +0,0 @@ -// -// SocketConnector.h -// -// Library: Net -// Package: Reactor -// Module: SocketConnector -// -// Definition of the SocketConnector class. -// -// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// SPDX-License-Identifier: BSL-1.0 -// - - -#ifndef Net_SocketConnector_INCLUDED -#define Net_SocketConnector_INCLUDED - - -#include "Poco/Net/Net.h" -#include "Poco/Net/SocketNotification.h" -#include "Poco/Net/SocketAddress.h" -#include "Poco/Net/StreamSocket.h" -#include "Poco/Observer.h" - - -namespace Poco { -namespace Net { - - -template <class ServiceHandler> -class SocketConnector - /// This class implements the Connector part of the - /// Acceptor-Connector design pattern. - /// - /// The Acceptor-Connector pattern has been described in the book - /// "Pattern Languages of Program Design 3", edited by Robert Martin, - /// Frank Buschmann and Dirk Riehle (Addison Wesley, 1997). - /// - /// The Acceptor-Connector design pattern decouples connection - /// establishment and service initialization in a distributed system - /// from the processing performed once a service is initialized. - /// This decoupling is achieved with three components: Acceptors, - /// Connectors and Service Handlers. - /// The Connector actively establishes a connection with a remote - /// server socket (usually managed by an Acceptor) and initializes - /// a Service Handler to manage the connection. - /// - /// The SocketConnector sets up a StreamSocket, initiates a non-blocking - /// connect operation and registers itself for ReadableNotification, WritableNotification - /// and ErrorNotification. ReadableNotification or WritableNotification denote the successful - /// establishment of the connection. - /// - /// When the StreamSocket becomes readable or writeable, the SocketConnector - /// creates a ServiceHandler to service the connection and unregisters - /// itself. - /// - /// In case of an error (ErrorNotification), the SocketConnector unregisters itself - /// and calls the onError() method, which can be overridden by subclasses - /// to perform custom error handling. - /// - /// The ServiceHandler class must provide a constructor that - /// takes a StreamSocket and a SocketReactor as arguments, - /// e.g.: - /// MyServiceHandler(const StreamSocket& socket, ServiceReactor& reactor) - /// - /// When the ServiceHandler is done, it must destroy itself. - /// - /// Subclasses can override the createServiceHandler() factory method - /// if special steps are necessary to create a ServiceHandler object. -{ -public: - explicit SocketConnector(SocketAddress& address): - _pReactor(0) - /// Creates a SocketConnector, using the given Socket. - { - _socket.connectNB(address); - } - - SocketConnector(SocketAddress& address, SocketReactor& reactor): - _pReactor(0) - /// Creates an acceptor, using the given ServerSocket. - /// The SocketConnector registers itself with the given SocketReactor. - { - _socket.connectNB(address); - registerConnector(reactor); - } - - virtual ~SocketConnector() - /// Destroys the SocketConnector. - { - try - { - unregisterConnector(); - } - catch (...) - { - poco_unexpected(); - } - } - - virtual void registerConnector(SocketReactor& reactor) - /// Registers the SocketConnector with a SocketReactor. - /// - /// A subclass can override this and, for example, also register - /// an event handler for a timeout event. - /// - /// The overriding method must call the baseclass implementation first. - { - _pReactor = &reactor; - _pReactor->addEventHandler(_socket, Poco::Observer<SocketConnector, ReadableNotification>(*this, &SocketConnector::onReadable)); - _pReactor->addEventHandler(_socket, Poco::Observer<SocketConnector, WritableNotification>(*this, &SocketConnector::onWritable)); - _pReactor->addEventHandler(_socket, Poco::Observer<SocketConnector, ErrorNotification>(*this, &SocketConnector::onError)); - } - - virtual void unregisterConnector() - /// Unregisters the SocketConnector. - /// - /// A subclass can override this and, for example, also unregister - /// its event handler for a timeout event. - /// - /// The overriding method must call the baseclass implementation first. - { - if (_pReactor) - { - _pReactor->removeEventHandler(_socket, Poco::Observer<SocketConnector, ReadableNotification>(*this, &SocketConnector::onReadable)); - _pReactor->removeEventHandler(_socket, Poco::Observer<SocketConnector, WritableNotification>(*this, &SocketConnector::onWritable)); - _pReactor->removeEventHandler(_socket, Poco::Observer<SocketConnector, ErrorNotification>(*this, &SocketConnector::onError)); - } - } - - void onReadable(ReadableNotification* pNotification) - { - pNotification->release(); - int err = _socket.impl()->socketError(); - if (err) - { - onError(err); - unregisterConnector(); - } - else - { - onConnect(); - } - } - - void onWritable(WritableNotification* pNotification) - { - pNotification->release(); - onConnect(); - } - - void onConnect() - { - _socket.setBlocking(true); - createServiceHandler(); - unregisterConnector(); - } - - void onError(ErrorNotification* pNotification) - { - pNotification->release(); - onError(_socket.impl()->socketError()); - unregisterConnector(); - } - -protected: - virtual ServiceHandler* createServiceHandler() - /// Create and initialize a new ServiceHandler instance. - /// - /// Subclasses can override this method. - { - return new ServiceHandler(_socket, *_pReactor); - } - - virtual void onError(int errorCode) - /// Called when the socket cannot be connected. - /// - /// Subclasses can override this method. - { - } - - SocketReactor* reactor() - /// Returns a pointer to the SocketReactor where - /// this SocketConnector is registered. - /// - /// The pointer may be null. - { - return _pReactor; - } - - StreamSocket& socket() - /// Returns a reference to the SocketConnector's socket. - { - return _socket; - } - -private: - SocketConnector(); - SocketConnector(const SocketConnector&); - SocketConnector& operator = (const SocketConnector&); - - StreamSocket _socket; - SocketReactor* _pReactor; -}; - - -} } // namespace Poco::Net - - -#endif // Net_SocketConnector_INCLUDED |