From: Mikko Rasa Date: Fri, 9 Dec 2022 18:32:46 +0000 (+0200) Subject: Don't allow duplicate listen calls X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=32713c673d335f0d4667005a9e6f658e8a616e8f;p=libs%2Fnet.git Don't allow duplicate listen calls Also add a function to check if the socket is already listening --- diff --git a/source/net/streamserversocket.cpp b/source/net/streamserversocket.cpp index 817145b..9b583a1 100644 --- a/source/net/streamserversocket.cpp +++ b/source/net/streamserversocket.cpp @@ -20,6 +20,9 @@ StreamServerSocket::StreamServerSocket(Family af, int proto): void StreamServerSocket::listen(const SockAddr &addr, unsigned backlog) { + if(listening) + throw bad_socket_state("already listening"); + bind(addr); int err = ::listen(priv->handle, backlog); diff --git a/source/net/streamserversocket.h b/source/net/streamserversocket.h index aa4868c..3152265 100644 --- a/source/net/streamserversocket.h +++ b/source/net/streamserversocket.h @@ -16,6 +16,7 @@ public: StreamServerSocket(Family, int = 0); virtual void listen(const SockAddr &, unsigned = 4); + bool is_listening() const { return listening; } virtual StreamSocket *accept(); };