Skip to content

Commit

Permalink
fix(UDPServer): using instead typedefs, auto for long types, optimize…
Browse files Browse the repository at this point in the history
… handlers rollover, fix coment typos #4382
  • Loading branch information
aleks-f committed Jan 4, 2024
1 parent 48d7a3e commit b19a8d6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Net/include/Poco/Net/UDPHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ class UDPHandlerImpl: public Runnable, public RefCountedObject
}

static char* error(char* buf)
/// Returns pointer to the erro message payload.
/// Returns pointer to the error message payload.
///
/// Total message size is S.
///
Expand Down
2 changes: 1 addition & 1 deletion Net/include/Poco/Net/UDPServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ template <std::size_t S = POCO_UDP_BUF_SIZE,
class UDPServerImpl: public Poco::Runnable
/// UDP server, runs in its own thread and owns a poller, to which
/// data arrival and discovery is delegated. See SingleSocketPoller and
/// MultipleSocketPoller for more information.
/// MultiSocketPoller for more information.
{
public:
UDPServerImpl(typename UDPHandlerImpl<S>::List& handlers, const Poco::Net::SocketAddress& sa):
Expand Down
23 changes: 11 additions & 12 deletions Net/include/Poco/Net/UDPSocketReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,26 +154,26 @@ class UDPSocketReader
/// Returns true if all handlers are stopped.
{
bool stopped = true;
typename UDPHandlerImpl<S>::List::iterator it = _handlers.begin();
typename UDPHandlerImpl<S>::List::iterator end = _handlers.end();
auto it = _handlers.begin();
auto end = _handlers.end();
for (; it != end; ++it) stopped = stopped && (*it)->stopped();
return stopped;
}

void stopHandler()
/// Stops all handlers.
{
typename UDPHandlerImpl<S>::List::iterator it = _handlers.begin();
typename UDPHandlerImpl<S>::List::iterator end = _handlers.end();
auto it = _handlers.begin();
auto end = _handlers.end();
for (; it != end; ++it) (*it)->stop();
}

bool handlerDone() const
/// Returns true if all handlers are done processing data.
{
bool done = true;
typename UDPHandlerImpl<S>::List::iterator it = _handlers.begin();
typename UDPHandlerImpl<S>::List::iterator end = _handlers.end();
auto it = _handlers.begin();
auto end = _handlers.end();
for (; it != end; ++it) done = done && (*it)->done();
return done;
}
Expand All @@ -193,20 +193,19 @@ class UDPSocketReader
/// Re-points the handler iterator to the next handler in
/// round-robin fashion.
{
poco_assert_dbg (_handler != _handlers.end());
if (++_handler == _handlers.end()) _handler = _handlers.begin();
if ((_handler == _handlers.end()) || (++_handler == _handlers.end()))
_handler = _handlers.begin();
}

UDPHandlerImpl<S>& handler()
/// Returns the reference to the current handler.
{
poco_assert_dbg (_handler != _handlers.end());
return **_handler;
}

typedef typename UDPHandlerImpl<S>::List HandlerList;
typedef typename UDPHandlerImpl<S>::List::iterator HandlerIterator;
typedef std::map<poco_socket_t, Counter> CounterMap;
using HandlerList = typename UDPHandlerImpl<S>::List;
using HandlerIterator = typename UDPHandlerImpl<S>::List::iterator;
using CounterMap = std::map<poco_socket_t, Counter>;

HandlerList& _handlers;
HandlerIterator _handler;
Expand Down

0 comments on commit b19a8d6

Please sign in to comment.