]> git.tdb.fi Git - libs/net.git/blobdiff - source/streamlistensocket.cpp
Hide platform details of Socket behind pimpl
[libs/net.git] / source / streamlistensocket.cpp
index 68580d7627672e7041e79f1a415d5c63d8c156eb..3b375bcafcadb54d0581b1cf6500b82a87ca1448 100644 (file)
@@ -1,9 +1,14 @@
 #include <cerrno>
 #include <msp/core/refptr.h>
-#include <msp/strings/formatter.h>
+#include <msp/core/systemerror.h>
+#include <msp/io/handle_private.h>
+#include <msp/strings/format.h>
+#include "socket_private.h"
 #include "streamlistensocket.h"
 #include "streamsocket.h"
 
+using namespace std;
+
 namespace Msp {
 namespace Net {
 
@@ -14,19 +19,20 @@ StreamListenSocket::StreamListenSocket(Family af, int proto):
 
 int StreamListenSocket::connect(const SockAddr &)
 {
-       throw Exception("Can't connect a listen socket");
+       // XXX This function needs to go away
+       throw logic_error("Can't connect a listen socket");
 }
 
 void StreamListenSocket::listen(const SockAddr &addr, unsigned backlog)
 {
        bind(addr);
 
-       int err = ::listen(handle, backlog);
+       int err = ::listen(priv->handle, backlog);
        if(err==-1)
-               throw SystemError("Unable to listen", errno);
+               throw system_error("listen");
 
 #ifdef WIN32
-       WSAEventSelect(handle, event, FD_ACCEPT);
+       WSAEventSelect(priv->handle, *priv->event, FD_ACCEPT);
 #endif
        set_events(IO::P_INPUT);
 
@@ -36,14 +42,15 @@ void StreamListenSocket::listen(const SockAddr &addr, unsigned backlog)
 StreamSocket *StreamListenSocket::accept()
 {
        if(!listening)
-               throw InvalidState("Socket is not listening");
+               throw bad_socket_state("not listening");
 
        sockaddr_storage sa;
        socklen_t size = sizeof(sockaddr_storage);
-       SocketHandle new_h = ::accept(handle, reinterpret_cast<sockaddr *>(&sa), &size);
+       Private new_p;
+       new_p.handle = ::accept(priv->handle, reinterpret_cast<sockaddr *>(&sa), &size);
 
        RefPtr<SockAddr> paddr = SockAddr::create(sa);
-       return new StreamSocket(new_h, *paddr);
+       return new StreamSocket(new_p, *paddr);
 }
 
 } // namespace Net