]> git.tdb.fi Git - libs/net.git/commitdiff
Don't allow duplicate listen calls
authorMikko Rasa <tdb@tdb.fi>
Fri, 9 Dec 2022 18:32:46 +0000 (20:32 +0200)
committerMikko Rasa <tdb@tdb.fi>
Fri, 9 Dec 2022 18:32:46 +0000 (20:32 +0200)
Also add a function to check if the socket is already listening

source/net/streamserversocket.cpp
source/net/streamserversocket.h

index 817145bcff15c024469e64f10cdcfe8516e4e551..9b583a141da552d420908826357528eb5b5b7cce 100644 (file)
@@ -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);
index aa4868c121601899a340b01d9e85de70fa19a7a9..315226566e35277055fadece93c48904b6359132 100644 (file)
@@ -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();
 };