Skip to content

Commit

Permalink
enh(C++17): Net: Modernisation of socket class declarations.
Browse files Browse the repository at this point in the history
  • Loading branch information
matejk committed Nov 19, 2024
1 parent efb0745 commit 76ea8c7
Show file tree
Hide file tree
Showing 20 changed files with 73 additions and 71 deletions.
2 changes: 1 addition & 1 deletion Net/include/Poco/Net/DatagramSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class Net_API DatagramSocket: public Socket
/// Creates the DatagramSocket with the SocketImpl
/// from another socket.

~DatagramSocket();
~DatagramSocket() override;
/// Destroys the DatagramSocket.

DatagramSocket& operator = (const Socket& socket);
Expand Down
4 changes: 2 additions & 2 deletions Net/include/Poco/Net/DatagramSocketImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ class Net_API DatagramSocketImpl: public SocketImpl
/// Creates a StreamSocketImpl using the given native socket.

protected:
void init(int af);
void init(int af) override;

~DatagramSocketImpl();
~DatagramSocketImpl() override;
};


Expand Down
2 changes: 1 addition & 1 deletion Net/include/Poco/Net/DialogSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class Net_API DialogSocket: public StreamSocket
DialogSocket(const DialogSocket& socket);
/// Creates the DialogSocket as copy of another dialog socket.

~DialogSocket();
~DialogSocket() override;
/// Destroys the DialogSocket.

DialogSocket& operator = (const Socket& socket);
Expand Down
2 changes: 1 addition & 1 deletion Net/include/Poco/Net/MulticastSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class Net_API MulticastSocket: public DatagramSocket
/// a DatagramSocketImpl, otherwise an InvalidArgumentException
/// will be thrown.

~MulticastSocket();
~MulticastSocket() override;
/// Destroys the DatagramSocket.

MulticastSocket& operator = (const Socket& socket);
Expand Down
13 changes: 7 additions & 6 deletions Net/include/Poco/Net/ParallelSocketAcceptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class ParallelSocketAcceptor
const std::string& threadName = ""):
_threadName(threadName),
_socket(socket),
_pReactor(0),
_pReactor(nullptr),
_threads(threads),
_next(0)
/// Creates a ParallelSocketAcceptor using the given ServerSocket,
Expand Down Expand Up @@ -93,6 +93,10 @@ class ParallelSocketAcceptor
}
}

ParallelSocketAcceptor() = delete;
ParallelSocketAcceptor(const ParallelSocketAcceptor&) = delete;
ParallelSocketAcceptor& operator = (const ParallelSocketAcceptor&) = delete;

void setReactor(SocketReactor& reactor)
/// Sets the reactor for this acceptor.
{
Expand Down Expand Up @@ -140,7 +144,7 @@ class ParallelSocketAcceptor
}

protected:
typedef std::vector<typename ParallelReactor::Ptr> ReactorVec;
using ReactorVec = std::vector<typename ParallelReactor::Ptr>;

virtual ServiceHandler* createServiceHandler(StreamSocket& socket)
/// Create and initialize a new ServiceHandler instance.
Expand Down Expand Up @@ -172,7 +176,7 @@ class ParallelSocketAcceptor
{
if ((*it)->has(socket)) return it->get();
}
return 0;
return nullptr;
}

SocketReactor* reactor()
Expand Down Expand Up @@ -218,9 +222,6 @@ class ParallelSocketAcceptor
}

private:
ParallelSocketAcceptor();
ParallelSocketAcceptor(const ParallelSocketAcceptor&);
ParallelSocketAcceptor& operator = (const ParallelSocketAcceptor&);

std::string _threadName;
/// Name prefix of sub SocketReactor threads
Expand Down
2 changes: 1 addition & 1 deletion Net/include/Poco/Net/PollSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class Net_API PollSet
/// Returns the number of sockets monitored.

//@ deprecated
int count() const;
POCO_DEPRECATED("Use size() instead") int count() const;
/// Returns the number of sockets monitored.
/// This method is deprecated. Use size() instead.

Expand Down
2 changes: 1 addition & 1 deletion Net/include/Poco/Net/RawSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Net_API RawSocket: public Socket
/// Creates the RawSocket with the SocketImpl
/// from another socket.

~RawSocket();
~RawSocket() override;
/// Destroys the RawSocket.

RawSocket& operator = (const Socket& socket);
Expand Down
4 changes: 2 additions & 2 deletions Net/include/Poco/Net/RawSocketImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ class Net_API RawSocketImpl: public SocketImpl
/// Creates a RawSocketImpl using the given native socket.

protected:
void init(int af);
void init(int af) override;
void init2(int af, int proto);

~RawSocketImpl();
~RawSocketImpl() override;
};


Expand Down
2 changes: 1 addition & 1 deletion Net/include/Poco/Net/ServerSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Net_API ServerSocket: public Socket
// Creates a socket from an existing file descriptor.
// Ownership is taken by poco

virtual ~ServerSocket();
~ServerSocket() override;
/// Destroys the ServerSocket.

ServerSocket& operator = (const Socket& socket);
Expand Down
2 changes: 1 addition & 1 deletion Net/include/Poco/Net/ServerSocketImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Net_API ServerSocketImpl: public SocketImpl
/// Creates the ServerSocketImpl.

protected:
virtual ~ServerSocketImpl();
~ServerSocketImpl() override;
/// Destroys the ServerSocketImpl.
};

Expand Down
3 changes: 2 additions & 1 deletion Net/include/Poco/Net/Socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -411,11 +411,12 @@ class FDCompare
{
public:
FDCompare(int fd): _fd(fd) { }
FDCompare() = delete;

inline bool operator()(const Socket& socket) const
{ return socket.sockfd() == _fd; }

private:
FDCompare();
int _fd;
};
#endif
Expand Down
9 changes: 5 additions & 4 deletions Net/include/Poco/Net/SocketAcceptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class SocketAcceptor

explicit SocketAcceptor(ServerSocket& socket):
_socket(socket),
_pReactor(0)
_pReactor(nullptr)
/// Creates a SocketAcceptor, using the given ServerSocket.
{
}
Expand Down Expand Up @@ -102,6 +102,10 @@ class SocketAcceptor
}
}

SocketAcceptor() = delete;
SocketAcceptor(const SocketAcceptor&) = delete;
SocketAcceptor& operator = (const SocketAcceptor&) = delete;

void setReactor(SocketReactor& reactor)
/// Sets the reactor for this acceptor.
{
Expand Down Expand Up @@ -176,9 +180,6 @@ class SocketAcceptor
}

private:
SocketAcceptor();
SocketAcceptor(const SocketAcceptor&);
SocketAcceptor& operator = (const SocketAcceptor&);

ServerSocket _socket;
SocketReactor* _pReactor;
Expand Down
11 changes: 6 additions & 5 deletions Net/include/Poco/Net/SocketConnector.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ class SocketConnector
{
public:
explicit SocketConnector(const SocketAddress& address):
_pReactor(0)
_pReactor(nullptr)
/// Creates a SocketConnector, using the given Socket.
{
_socket.connectNB(address);
}

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

SocketConnector() = delete;
SocketConnector(const SocketConnector&) = delete;
SocketConnector& operator = (const SocketConnector&) = delete;

virtual void registerConnector(SocketReactor& reactor)
/// Registers the SocketConnector with a SocketReactor.
///
Expand Down Expand Up @@ -193,9 +197,6 @@ class SocketConnector
}

private:
SocketConnector();
SocketConnector(const SocketConnector&);
SocketConnector& operator = (const SocketConnector&);

StreamSocket _socket;
SocketReactor* _pReactor;
Expand Down
14 changes: 7 additions & 7 deletions Net/include/Poco/Net/SocketNotification.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Net_API SocketNotification: public Poco::Notification
explicit SocketNotification(SocketReactor* pReactor);
/// Creates the SocketNotification for the given SocketReactor.

virtual ~SocketNotification();
~SocketNotification() override;
/// Destroys the SocketNotification.

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

~ReadableNotification();
~ReadableNotification() override;
/// Destroys the ReadableNotification.
};

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

~WritableNotification();
~WritableNotification() override;
/// Destroys the WritableNotification.
};

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

~ErrorNotification();
~ErrorNotification() override;
/// Destroys the ErrorNotification.

int code() const;
Expand Down Expand Up @@ -128,7 +128,7 @@ class Net_API TimeoutNotification: public SocketNotification
TimeoutNotification(SocketReactor* pReactor);
/// Creates the TimeoutNotification for the given SocketReactor.

~TimeoutNotification();
~TimeoutNotification() override;
/// Destroys the TimeoutNotification.
};

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

~IdleNotification();
~IdleNotification() override;
/// Destroys the IdleNotification.
};

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

~ShutdownNotification();
~ShutdownNotification() override;
/// Destroys the ShutdownNotification.
};

Expand Down
8 changes: 4 additions & 4 deletions Net/include/Poco/Net/SocketNotifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ class Net_API SocketNotifier: public Poco::RefCountedObject
/// Returns the number of subscribers;

protected:
~SocketNotifier();
~SocketNotifier() override;
/// Destroys the SocketNotifier.

private:
typedef std::multiset<SocketNotification*> EventSet;
typedef Poco::FastMutex MutexType;
typedef MutexType::ScopedLock ScopedLock;
using EventSet = std::multiset<SocketNotification *>;
using MutexType = Poco::FastMutex;
using ScopedLock = MutexType::ScopedLock;

EventSet _events;
Poco::NotificationCenter _nc;
Expand Down
26 changes: 13 additions & 13 deletions Net/include/Poco/Net/SocketProactor.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class Net_API SocketProactor final: public Poco::Runnable
SocketProactor& operator=(const SocketProactor&) = delete;
SocketProactor& operator=(SocketProactor&&) = delete;

~SocketProactor();
~SocketProactor() override;
/// Destroys the SocketProactor.

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

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

void run();
void run() override;
/// Runs the SocketProactor. The reactor will run
/// until stop() is called (in a separate thread).

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

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

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

void removeSocket(Socket sock);
void removeSocket(const Socket& sock);
/// Removes the socket from the poll set.

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

typedef Poco::Mutex MutexType;
typedef MutexType::ScopedLock ScopedLock;
using MutexType = Poco::Mutex;
using ScopedLock = MutexType::ScopedLock;

static const long DEFAULT_MAX_TIMEOUT_MS = 250;

Expand Down Expand Up @@ -245,7 +245,7 @@ class Net_API SocketProactor final: public Poco::Runnable
{
}

~IONotification() = default;
~IONotification() override = default;

void call()
/// Calls the completion handler.
Expand Down Expand Up @@ -319,7 +319,7 @@ class Net_API SocketProactor final: public Poco::Runnable
bool runOne()
/// Runs the next I/O completion handler in the queue.
{
IONotification* pNf = dynamic_cast<IONotification*>(_nq.waitDequeueNotification());
auto* pNf = dynamic_cast<IONotification*>(_nq.waitDequeueNotification());
if (_activity.isStopped()) return false;
if (pNf)
{
Expand Down Expand Up @@ -462,19 +462,19 @@ class Net_API SocketProactor final: public Poco::Runnable
// inlines
//

inline void SocketProactor::addSocket(Socket sock, int mode)
inline void SocketProactor::addSocket(const Socket& sock, int mode)
{
_pollSet.add(sock, mode | PollSet::POLL_ERROR);
}


inline void SocketProactor::updateSocket(Socket sock, int mode)
inline void SocketProactor::updateSocket(const Socket& sock, int mode)
{
_pollSet.update(sock, mode);
}


inline void SocketProactor::removeSocket(Socket sock)
inline void SocketProactor::removeSocket(const Socket& sock)
{
_pollSet.remove(sock);
}
Expand Down
Loading

0 comments on commit 76ea8c7

Please sign in to comment.