Skip to content

Commit 76ea8c7

Browse files
committed
enh(C++17): Net: Modernisation of socket class declarations.
1 parent efb0745 commit 76ea8c7

20 files changed

+73
-71
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/DatagramSocketImpl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ class Net_API DatagramSocketImpl: public SocketImpl
4343
/// Creates a StreamSocketImpl using the given native socket.
4444

4545
protected:
46-
void init(int af);
46+
void init(int af) override;
4747

48-
~DatagramSocketImpl();
48+
~DatagramSocketImpl() override;
4949
};
5050

5151

Net/include/Poco/Net/DialogSocket.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class Net_API DialogSocket: public StreamSocket
6767
DialogSocket(const DialogSocket& socket);
6868
/// Creates the DialogSocket as copy of another dialog socket.
6969

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

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

Net/include/Poco/Net/MulticastSocket.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class Net_API MulticastSocket: public DatagramSocket
6767
/// a DatagramSocketImpl, otherwise an InvalidArgumentException
6868
/// will be thrown.
6969

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

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

Net/include/Poco/Net/ParallelSocketAcceptor.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class ParallelSocketAcceptor
5252
const std::string& threadName = ""):
5353
_threadName(threadName),
5454
_socket(socket),
55-
_pReactor(0),
55+
_pReactor(nullptr),
5656
_threads(threads),
5757
_next(0)
5858
/// Creates a ParallelSocketAcceptor using the given ServerSocket,
@@ -93,6 +93,10 @@ class ParallelSocketAcceptor
9393
}
9494
}
9595

96+
ParallelSocketAcceptor() = delete;
97+
ParallelSocketAcceptor(const ParallelSocketAcceptor&) = delete;
98+
ParallelSocketAcceptor& operator = (const ParallelSocketAcceptor&) = delete;
99+
96100
void setReactor(SocketReactor& reactor)
97101
/// Sets the reactor for this acceptor.
98102
{
@@ -140,7 +144,7 @@ class ParallelSocketAcceptor
140144
}
141145

142146
protected:
143-
typedef std::vector<typename ParallelReactor::Ptr> ReactorVec;
147+
using ReactorVec = std::vector<typename ParallelReactor::Ptr>;
144148

145149
virtual ServiceHandler* createServiceHandler(StreamSocket& socket)
146150
/// Create and initialize a new ServiceHandler instance.
@@ -172,7 +176,7 @@ class ParallelSocketAcceptor
172176
{
173177
if ((*it)->has(socket)) return it->get();
174178
}
175-
return 0;
179+
return nullptr;
176180
}
177181

178182
SocketReactor* reactor()
@@ -218,9 +222,6 @@ class ParallelSocketAcceptor
218222
}
219223

220224
private:
221-
ParallelSocketAcceptor();
222-
ParallelSocketAcceptor(const ParallelSocketAcceptor&);
223-
ParallelSocketAcceptor& operator = (const ParallelSocketAcceptor&);
224225

225226
std::string _threadName;
226227
/// Name prefix of sub SocketReactor threads

Net/include/Poco/Net/PollSet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class Net_API PollSet
9797
/// Returns the number of sockets monitored.
9898

9999
//@ deprecated
100-
int count() const;
100+
POCO_DEPRECATED("Use size() instead") int count() const;
101101
/// Returns the number of sockets monitored.
102102
/// This method is deprecated. Use size() instead.
103103

Net/include/Poco/Net/RawSocket.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class Net_API RawSocket: public Socket
5757
/// Creates the RawSocket with the SocketImpl
5858
/// from another socket.
5959

60-
~RawSocket();
60+
~RawSocket() override;
6161
/// Destroys the RawSocket.
6262

6363
RawSocket& operator = (const Socket& socket);

Net/include/Poco/Net/RawSocketImpl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ class Net_API RawSocketImpl: public SocketImpl
4343
/// Creates a RawSocketImpl using the given native socket.
4444

4545
protected:
46-
void init(int af);
46+
void init(int af) override;
4747
void init2(int af, int proto);
4848

49-
~RawSocketImpl();
49+
~RawSocketImpl() override;
5050
};
5151

5252

Net/include/Poco/Net/ServerSocket.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class Net_API ServerSocket: public Socket
6464
// Creates a socket from an existing file descriptor.
6565
// Ownership is taken by poco
6666

67-
virtual ~ServerSocket();
67+
~ServerSocket() override;
6868
/// Destroys the ServerSocket.
6969

7070
ServerSocket& operator = (const Socket& socket);

Net/include/Poco/Net/ServerSocketImpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Net_API ServerSocketImpl: public SocketImpl
3434
/// Creates the ServerSocketImpl.
3535

3636
protected:
37-
virtual ~ServerSocketImpl();
37+
~ServerSocketImpl() override;
3838
/// Destroys the ServerSocketImpl.
3939
};
4040

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/SocketAcceptor.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class SocketAcceptor
7272

7373
explicit SocketAcceptor(ServerSocket& socket):
7474
_socket(socket),
75-
_pReactor(0)
75+
_pReactor(nullptr)
7676
/// Creates a SocketAcceptor, using the given ServerSocket.
7777
{
7878
}
@@ -102,6 +102,10 @@ class SocketAcceptor
102102
}
103103
}
104104

105+
SocketAcceptor() = delete;
106+
SocketAcceptor(const SocketAcceptor&) = delete;
107+
SocketAcceptor& operator = (const SocketAcceptor&) = delete;
108+
105109
void setReactor(SocketReactor& reactor)
106110
/// Sets the reactor for this acceptor.
107111
{
@@ -176,9 +180,6 @@ class SocketAcceptor
176180
}
177181

178182
private:
179-
SocketAcceptor();
180-
SocketAcceptor(const SocketAcceptor&);
181-
SocketAcceptor& operator = (const SocketAcceptor&);
182183

183184
ServerSocket _socket;
184185
SocketReactor* _pReactor;

Net/include/Poco/Net/SocketConnector.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,14 @@ class SocketConnector
7474
{
7575
public:
7676
explicit SocketConnector(const SocketAddress& address):
77-
_pReactor(0)
77+
_pReactor(nullptr)
7878
/// Creates a SocketConnector, using the given Socket.
7979
{
8080
_socket.connectNB(address);
8181
}
8282

8383
SocketConnector(const SocketAddress& address, SocketReactor& reactor, bool doRegister = true) :
84-
_pReactor(0)
84+
_pReactor(nullptr)
8585
/// Creates an connector, using the given ServerSocket.
8686
/// The SocketConnector registers itself with the given SocketReactor.
8787
{
@@ -102,6 +102,10 @@ class SocketConnector
102102
}
103103
}
104104

105+
SocketConnector() = delete;
106+
SocketConnector(const SocketConnector&) = delete;
107+
SocketConnector& operator = (const SocketConnector&) = delete;
108+
105109
virtual void registerConnector(SocketReactor& reactor)
106110
/// Registers the SocketConnector with a SocketReactor.
107111
///
@@ -193,9 +197,6 @@ class SocketConnector
193197
}
194198

195199
private:
196-
SocketConnector();
197-
SocketConnector(const SocketConnector&);
198-
SocketConnector& operator = (const SocketConnector&);
199200

200201
StreamSocket _socket;
201202
SocketReactor* _pReactor;

Net/include/Poco/Net/SocketNotification.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class Net_API SocketNotification: public Poco::Notification
3838
explicit SocketNotification(SocketReactor* pReactor);
3939
/// Creates the SocketNotification for the given SocketReactor.
4040

41-
virtual ~SocketNotification();
41+
~SocketNotification() override;
4242
/// Destroys the SocketNotification.
4343

4444
SocketReactor& source() const;
@@ -65,7 +65,7 @@ class Net_API ReadableNotification: public SocketNotification
6565
ReadableNotification(SocketReactor* pReactor);
6666
/// Creates the ReadableNotification for the given SocketReactor.
6767

68-
~ReadableNotification();
68+
~ReadableNotification() override;
6969
/// Destroys the ReadableNotification.
7070
};
7171

@@ -77,7 +77,7 @@ class Net_API WritableNotification: public SocketNotification
7777
WritableNotification(SocketReactor* pReactor);
7878
/// Creates the WritableNotification for the given SocketReactor.
7979

80-
~WritableNotification();
80+
~WritableNotification() override;
8181
/// Destroys the WritableNotification.
8282
};
8383

@@ -93,7 +93,7 @@ class Net_API ErrorNotification: public SocketNotification
9393
int code = 0, const std::string& description = "");
9494
/// Creates the ErrorNotification for the given SocketReactor.
9595

96-
~ErrorNotification();
96+
~ErrorNotification() override;
9797
/// Destroys the ErrorNotification.
9898

9999
int code() const;
@@ -128,7 +128,7 @@ class Net_API TimeoutNotification: public SocketNotification
128128
TimeoutNotification(SocketReactor* pReactor);
129129
/// Creates the TimeoutNotification for the given SocketReactor.
130130

131-
~TimeoutNotification();
131+
~TimeoutNotification() override;
132132
/// Destroys the TimeoutNotification.
133133
};
134134

@@ -141,7 +141,7 @@ class Net_API IdleNotification: public SocketNotification
141141
IdleNotification(SocketReactor* pReactor);
142142
/// Creates the IdleNotification for the given SocketReactor.
143143

144-
~IdleNotification();
144+
~IdleNotification() override;
145145
/// Destroys the IdleNotification.
146146
};
147147

@@ -154,7 +154,7 @@ class Net_API ShutdownNotification: public SocketNotification
154154
ShutdownNotification(SocketReactor* pReactor);
155155
/// Creates the ShutdownNotification for the given SocketReactor.
156156

157-
~ShutdownNotification();
157+
~ShutdownNotification() override;
158158
/// Destroys the ShutdownNotification.
159159
};
160160

Net/include/Poco/Net/SocketNotifier.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ class Net_API SocketNotifier: public Poco::RefCountedObject
6565
/// Returns the number of subscribers;
6666

6767
protected:
68-
~SocketNotifier();
68+
~SocketNotifier() override;
6969
/// Destroys the SocketNotifier.
7070

7171
private:
72-
typedef std::multiset<SocketNotification*> EventSet;
73-
typedef Poco::FastMutex MutexType;
74-
typedef MutexType::ScopedLock ScopedLock;
72+
using EventSet = std::multiset<SocketNotification *>;
73+
using MutexType = Poco::FastMutex;
74+
using ScopedLock = MutexType::ScopedLock;
7575

7676
EventSet _events;
7777
Poco::NotificationCenter _nc;

Net/include/Poco/Net/SocketProactor.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class Net_API SocketProactor final: public Poco::Runnable
7979
SocketProactor& operator=(const SocketProactor&) = delete;
8080
SocketProactor& operator=(SocketProactor&&) = delete;
8181

82-
~SocketProactor();
82+
~SocketProactor() override;
8383
/// Destroys the SocketProactor.
8484

8585
void addWork(const Work& ch, Timestamp::TimeDiff ms = PERMANENT_COMPLETION_HANDLER);
@@ -113,7 +113,7 @@ class Net_API SocketProactor final: public Poco::Runnable
113113
/// from the front of the schedule queue.
114114
/// Default is removal of all functions.
115115

116-
int poll(int* pHandled = 0);
116+
int poll(int* pHandled = nullptr);
117117
/// Polls all registered sockets and calls their respective handlers.
118118
/// If pHandled is not null, after the call it contains the total number
119119
/// of read/write/error socket handlers called.
@@ -126,7 +126,7 @@ class Net_API SocketProactor final: public Poco::Runnable
126126
/// Returns 1 on successful handler invocation, 0 on
127127
/// exception.
128128

129-
void run();
129+
void run() override;
130130
/// Runs the SocketProactor. The reactor will run
131131
/// until stop() is called (in a separate thread).
132132

@@ -157,13 +157,13 @@ class Net_API SocketProactor final: public Poco::Runnable
157157
Poco::Timespan getTimeout() const;
158158
/// Returns the timeout.
159159

160-
void addSocket(Socket sock, int mode);
160+
void addSocket(const Socket& sock, int mode);
161161
/// Adds the socket to the poll set.
162162

163-
void updateSocket(Socket sock, int mode);
163+
void updateSocket(const Socket& sock, int mode);
164164
/// Updates the socket mode in the poll set.
165165

166-
void removeSocket(Socket sock);
166+
void removeSocket(const Socket& sock);
167167
/// Removes the socket from the poll set.
168168

169169
void addReceiveFrom(Socket sock, Buffer& buf, SocketAddress& addr, Callback&& onCompletion);
@@ -212,8 +212,8 @@ class Net_API SocketProactor final: public Poco::Runnable
212212
/// If expiredOnly is true, only expired temporary functions
213213
/// are called.
214214

215-
typedef Poco::Mutex MutexType;
216-
typedef MutexType::ScopedLock ScopedLock;
215+
using MutexType = Poco::Mutex;
216+
using ScopedLock = MutexType::ScopedLock;
217217

218218
static const long DEFAULT_MAX_TIMEOUT_MS = 250;
219219

@@ -245,7 +245,7 @@ class Net_API SocketProactor final: public Poco::Runnable
245245
{
246246
}
247247

248-
~IONotification() = default;
248+
~IONotification() override = default;
249249

250250
void call()
251251
/// Calls the completion handler.
@@ -319,7 +319,7 @@ class Net_API SocketProactor final: public Poco::Runnable
319319
bool runOne()
320320
/// Runs the next I/O completion handler in the queue.
321321
{
322-
IONotification* pNf = dynamic_cast<IONotification*>(_nq.waitDequeueNotification());
322+
auto* pNf = dynamic_cast<IONotification*>(_nq.waitDequeueNotification());
323323
if (_activity.isStopped()) return false;
324324
if (pNf)
325325
{
@@ -462,19 +462,19 @@ class Net_API SocketProactor final: public Poco::Runnable
462462
// inlines
463463
//
464464

465-
inline void SocketProactor::addSocket(Socket sock, int mode)
465+
inline void SocketProactor::addSocket(const Socket& sock, int mode)
466466
{
467467
_pollSet.add(sock, mode | PollSet::POLL_ERROR);
468468
}
469469

470470

471-
inline void SocketProactor::updateSocket(Socket sock, int mode)
471+
inline void SocketProactor::updateSocket(const Socket& sock, int mode)
472472
{
473473
_pollSet.update(sock, mode);
474474
}
475475

476476

477-
inline void SocketProactor::removeSocket(Socket sock)
477+
inline void SocketProactor::removeSocket(const Socket& sock)
478478
{
479479
_pollSet.remove(sock);
480480
}

0 commit comments

Comments
 (0)