1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-01-19 03:57:14 +01:00
SqMod/vendor/POCO/Net/include/Poco/Net/SingleSocketPoller.h
Sandu Liviu Catalin 4a6bfc086c Major plugin refactor and cleanup.
Switched to POCO library for unified platform/library interface.
Deprecated the external module API. It was creating more problems than solving.
Removed most built-in libraries in favor of system libraries for easier maintenance.
Cleaned and secured code with help from static analyzers.
2021-01-30 08:51:39 +02:00

105 lines
2.3 KiB
C++

//
// SingleSocketPoller.h
//
// Library: Net
// Package: UDP
// Module: SingleSocketPoller
//
// Definition of the SingleSocketPoller class.
//
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef Net_SingleSocketPoller_INCLUDED
#define Net_SingleSocketPoller_INCLUDED
#include "Poco/Net/Net.h"
#include "Poco/Net/DatagramSocket.h"
#include "Poco/Net/UDPHandler.h"
#include "Poco/Net/PollSet.h"
namespace Poco {
namespace Net {
template <std::size_t S = POCO_UDP_BUF_SIZE>
class SingleSocketPoller
/// SinlgeSocketPoller, as its name indicates, repeatedly polls a single
/// socket for readability; if the socket is readable, the reading action
/// is delegated to the reader.
{
public:
SingleSocketPoller(typename UDPHandlerImpl<S>::List& handlers, const Poco::Net::SocketAddress& sa, Poco::Timespan timeout = 250000): _reader(handlers), _timeout(timeout)
/// Creates the SingleSocketPoller and binds it to
/// the given address.
{
_socket.bind(sa, false, false);
_socket.setBlocking(false);
}
SingleSocketPoller(typename UDPHandlerImpl<S>::List& handlers, const UDPServerParams& serverParams): _reader(handlers, serverParams), _timeout(serverParams.timeout())
/// Creates the SingleSocketPoller and binds it to
/// the given address.
{
_socket.bind(serverParams.address(), false, false);
_socket.setBlocking(false);
}
~SingleSocketPoller()
/// Destroys SingleSocketPoller
{
}
Poco::UInt16 port() const
/// Returns the port the socket is
/// listening on.
{
return _socket.address().port();
}
Poco::Net::SocketAddress address() const
/// Returns the address of the server.
{
return _socket.address();
}
void poll()
/// Poll the socket and read if readable.
{
if (_reader.handlerStopped()) return;
if (_socket.poll(_timeout, Socket::SELECT_READ))
{
_reader.read(_socket);
}
}
void stop()
/// Stops the handler.
{
_reader.stopHandler();
}
bool done() const
/// Returns tru if handler is done.
{
return _reader.handlerDone();
}
private:
Poco::Net::DatagramSocket _socket;
UDPSocketReader<S> _reader;
Poco::Timespan _timeout;
};
} } // namespace Poco::Net
#endif // Net_SingleSocketPoller_INCLUDED