Files
poco/Net/include/Poco/Net/SingleSocketPoller.h
Aleksandar Fabijanic c4e676d36d Feature net udp (#2347)
* add PMTU discovery #2329

* add socket gather/scatter capabilities #2330 (win, udp)

* enable WSAPoll

* add FastMemoryPool

* add receiveFrom() with native args

* allow copying of StringTokenizer

* add AtomicFlag and SpinlockMutex

* update .gitignore

* UDPServer and client #2343 (windows)

* fix warnings

* fix warnings

* regenerate Net VS solutions

* regenerate CppUnit projects/solutions

* clang fixes

* gcc fixes

* try to fix travis

* more travis fixes

* more travis fixes

* handle UDPClient exception

* fix makefiles and init order warnings

* add UNIX gather/scatter sendto/recvfrom implementations and tests

* run travis tests as sudo

* try to run tests as sudo, 2nd attempt

* fix warning

* use mutex in reactor

* lock-order-inversion in SocketReactor #2346

* add PMTU discovery #2329 (linux)

* ICMPSocket does not check reply address #1921

* remove some ignored tests

* add PMTU discovery #2329 (reconcile logic with #1921)

* fix native receiveFrome()

* reinstate ignoring of proxy errors

* add testMTU to ignore list

* add include atomic

* NTPClient not checking reply address #2348

* some ICMP/MTU fixes

* UDPSocketReader cleanup

* resolve some socket inheritance warnings

* add NTP time sync to ignored tests

* SocketNotifier not thread-safe #2345

* prevent x64 samples build attempt for win32

* build TestApp and Library

* fix ICMP tests

* regen VS projects

* regen VS projects and add missing 2012 files

* remove debug prints
2018-06-02 14:02:33 -05: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