]> git.tdb.fi Git - libs/net.git/blobdiff - source/streamsocket.cpp
Exception changes
[libs/net.git] / source / streamsocket.cpp
index 2576009452bddcb9df8ee22898c42ce612fcc171..cd810d5253e14e2990d204c4af12096f5be7278b 100644 (file)
@@ -2,6 +2,7 @@
 #include <sys/socket.h>
 #endif
 #include <cerrno>
+#include <msp/core/systemerror.h>
 #include <msp/io/poll.h>
 #include <msp/strings/format.h>
 #include "streamsocket.h"
@@ -28,14 +29,14 @@ int StreamSocket::poll_connect(const Time::TimeDelta &timeout)
 {
        check_state(false);
        if(!connecting)
-               throw InvalidState("No connection attempt going on");
+               throw bad_socket_state("not connecting");
 
        int res = poll(*this, IO::P_OUTPUT, timeout);
        if(res==-1)
 #ifdef WIN32
-               throw Exception(format("Connection polling failed: %d", WSAGetLastError()));
+               throw system_error("poll", WSAGetLastError());
 #else
-               throw SystemError("Connection polling failed", errno);
+               throw system_error("poll");
 #endif
        else if(res>0)
        {
@@ -49,9 +50,9 @@ int StreamSocket::poll_connect(const Time::TimeDelta &timeout)
                {
                        set_events(IO::P_NONE);
 #ifdef WIN32
-                       throw Exception(format("Connection failed: %d", err));
+                       throw system_error("connect", WSAGetLastError());
 #else
-                       throw SystemError("Connection failed", err);
+                       throw system_error("connect");
 #endif
                }
 
@@ -73,7 +74,7 @@ int StreamSocket::connect(const SockAddr &addr)
        check_state(false);
 
        if(connected)
-               throw InvalidState("Socket is already connected");
+               throw bad_socket_state("already connected");
 
        sockaddr_storage sa;
        socklen_t size = addr.fill_sockaddr(sa);
@@ -90,7 +91,7 @@ int StreamSocket::connect(const SockAddr &addr)
                        set_events(IO::P_OUTPUT);
                }
                else
-                       throw Exception(format("Unable to connect: %d", err_code));
+                       throw system_error("connect", err_code);
        }
 #else
        int err = ::connect(handle, reinterpret_cast<sockaddr *>(&sa), size);
@@ -102,7 +103,7 @@ int StreamSocket::connect(const SockAddr &addr)
                        set_events(IO::P_OUTPUT);
                }
                else
-                       throw SystemError("Unable to connect", errno);
+                       throw system_error("connect");
        }
 #endif