Skip to content

Commit 3672694

Browse files
committed
enh(Net): some C++ modernisation
1 parent 3507c30 commit 3672694

File tree

14 files changed

+33
-31
lines changed

14 files changed

+33
-31
lines changed

Net/include/Poco/Net/DatagramSocket.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class Net_API DatagramSocket: public Socket
6767
/// Creates the DatagramSocket with the SocketImpl
6868
/// from another socket.
6969

70-
~DatagramSocket();
70+
~DatagramSocket() override;
7171
/// Destroys the DatagramSocket.
7272

7373
DatagramSocket& operator = (const Socket& socket);

Net/include/Poco/Net/MultiSocketPoller.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class MultiSocketPoller
3838
/// state, the reading/error handling actions are delegated to the reader.
3939
{
4040
public:
41-
MultiSocketPoller(typename UDPHandlerImpl<S>::List& handlers, const Poco::Net::SocketAddress& sa, int nSockets = 10, Poco::Timespan timeout = 250000):
41+
MultiSocketPoller(typename UDPHandlerImpl<S>::List& handlers, const Poco::Net::SocketAddress& sa, int nSockets = 10, const Poco::Timespan& timeout = 250000):
4242
_address(sa),
4343
_timeout(timeout),
4444
_reader(handlers)

Net/include/Poco/Net/Socket.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,11 +411,12 @@ class FDCompare
411411
{
412412
public:
413413
FDCompare(int fd): _fd(fd) { }
414+
FDCompare() = delete;
415+
414416
inline bool operator()(const Socket& socket) const
415417
{ return socket.sockfd() == _fd; }
416418

417419
private:
418-
FDCompare();
419420
int _fd;
420421
};
421422
#endif

Net/include/Poco/Net/SocketDefs.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@
144144
#define POCO_NO_DATA NO_DATA
145145
#elif defined(POCO_OS_FAMILY_UNIX)
146146
#include <unistd.h>
147-
#include <errno.h>
147+
#include <cerrno>
148148
#include <sys/types.h>
149149
#include <sys/socket.h>
150150
#include <sys/un.h>
@@ -369,12 +369,12 @@ namespace Net {
369369

370370

371371
#if defined(POCO_OS_FAMILY_WINDOWS)
372-
typedef WSABUF SocketBuf;
372+
using SocketBuf = WSABUF;
373373
#elif defined(POCO_OS_FAMILY_UNIX) // TODO: may need more refinement
374-
typedef iovec SocketBuf;
374+
using SocketBuf = iovec;
375375
#endif
376376

377-
typedef std::vector<SocketBuf> SocketBufVec;
377+
using SocketBufVec = std::vector<SocketBuf>;
378378

379379
inline int SocketBufVecSize(const SocketBufVec& sbv)
380380
/// Returns total length of all SocketBufs in the vector.

Net/include/Poco/Net/SocketImpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ class Net_API SocketImpl: public Poco::RefCountedObject
490490
SocketImpl(poco_socket_t sockfd);
491491
/// Creates a SocketImpl using the given native socket.
492492

493-
virtual ~SocketImpl();
493+
~SocketImpl() override;
494494
/// Destroys the SocketImpl.
495495
/// Closes the socket if it is still open.
496496

Net/include/Poco/Net/StreamSocket.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class Net_API StreamSocket: public Socket
6969
/// Creates the StreamSocket with the SocketImpl
7070
/// from another socket.
7171

72-
virtual ~StreamSocket();
72+
~StreamSocket() override;
7373
/// Destroys the StreamSocket.
7474

7575
StreamSocket& operator = (const Socket& socket);

Net/include/Poco/Net/UDPClient.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ class Net_API UDPClient : public Poco::Runnable
4444
/// If listen is true, a thread is launched where client can receive
4545
/// responses rom the server.
4646

47-
virtual ~UDPClient();
47+
~UDPClient() override;
4848
/// Destroys UDPClient.
4949

50-
void run();
50+
void run() override;
5151
/// Runs listener (typically invoked internally, in separate thread).
5252

5353
SocketAddress address() const;

Net/include/Poco/Net/UDPHandler.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class UDPHandlerImpl: public Runnable, public RefCountedObject
6363
static constexpr MsgSizeT BUF_STATUS_BUSY = -1;
6464
static constexpr MsgSizeT BUF_STATUS_ERROR = -2;
6565

66-
UDPHandlerImpl(std::size_t bufListSize = 1000, std::ostream* pErr = 0):
66+
UDPHandlerImpl(std::size_t bufListSize = 1000, std::ostream* pErr = nullptr):
6767
_thread("UDPHandlerImpl"),
6868
_stop(false),
6969
_done(false),
@@ -76,7 +76,7 @@ class UDPHandlerImpl: public Runnable, public RefCountedObject
7676
{
7777
}
7878

79-
~UDPHandlerImpl()
79+
~UDPHandlerImpl() override
8080
/// Destroys the UDPHandlerImpl.
8181
{
8282
stop();
@@ -94,7 +94,7 @@ class UDPHandlerImpl: public Runnable, public RefCountedObject
9494
/// the pointers to the newly created guard/buffer.
9595
/// If mutex lock times out, returns null pointer.
9696
{
97-
char* ret = 0;
97+
char* ret = nullptr;
9898
if (_mutex.tryLock(10))
9999
{
100100
if (_buffers[sock].size() < _bufListSize) // building buffer list
@@ -145,7 +145,7 @@ class UDPHandlerImpl: public Runnable, public RefCountedObject
145145
_dataReady.set();
146146
}
147147

148-
void run()
148+
void run() override
149149
/// Does the work.
150150
{
151151
while (!_stop)
@@ -336,7 +336,8 @@ class UDPHandlerImpl: public Runnable, public RefCountedObject
336336
using BufMap = std::map<poco_socket_t, BufList>;
337337
using BLIt = typename BufList::iterator;
338338
using BufIt = std::map<poco_socket_t, BLIt>;
339-
using MemPool = Poco::FastMemoryPool<char[S]>;
339+
using BufArray = std::array<char, S>;
340+
using MemPool = Poco::FastMemoryPool<BufArray>;
340341

341342
void setStatusImpl(char*& pBuf, MsgSizeT status)
342343
{

Net/include/Poco/Net/UDPServer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class UDPServerImpl: public Poco::Runnable
5757
_thread.start(*this);
5858
}
5959

60-
~UDPServerImpl()
60+
~UDPServerImpl() override
6161
/// Destroys the UDPServer.
6262
{
6363
_stop = true;
@@ -79,7 +79,7 @@ class UDPServerImpl: public Poco::Runnable
7979
return _poller.address();
8080
}
8181

82-
void run()
82+
void run() override
8383
/// Does the work.
8484
{
8585
while (!_stop) _poller.poll();

Net/include/Poco/Net/UDPSocketReader.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ class UDPSocketReader
101101
/// for replying to sender and data or error backlog threshold is
102102
/// exceeded, sender is notified of the current backlog size.
103103
{
104-
typedef typename UDPHandlerImpl<S>::MsgSizeT RT;
105-
char* p = 0;
106-
struct sockaddr* pSA = 0;
107-
poco_socklen_t* pAL = 0;
104+
using RT = typename UDPHandlerImpl<S>::MsgSizeT;
105+
char* p = nullptr;
106+
struct sockaddr* pSA = nullptr;
107+
poco_socklen_t* pAL = nullptr;
108108
poco_socket_t sockfd = sock.impl()->sockfd();
109109
nextHandler();
110110
try
@@ -179,10 +179,10 @@ class UDPSocketReader
179179
return done;
180180
}
181181

182-
AtomicCounter::ValueType setError(poco_socket_t sock, char* buf = 0, const std::string& err = "")
182+
AtomicCounter::ValueType setError(poco_socket_t sock, char* buf = nullptr, const std::string& err = "")
183183
/// Sets error to the provided buffer buf. If the buffer is null, a new buffer is obtained
184184
/// from handler.
185-
/// If successful, returns the handler's eror backlog size, otherwise returns zero.
185+
/// If successful, returns the handler's error backlog size, otherwise returns zero.
186186
{
187187
if (!buf) buf = handler().next(sock);
188188
if (buf) return handler().setError(buf, err.empty() ? Error::getMessage(Error::last()) : err);

0 commit comments

Comments
 (0)