]> git.tdb.fi Git - libs/net.git/commitdiff
Use SystemError at appropriate places
authorMikko Rasa <tdb@tdb.fi>
Fri, 27 Jun 2008 06:16:42 +0000 (06:16 +0000)
committerMikko Rasa <tdb@tdb.fi>
Fri, 27 Jun 2008 06:16:42 +0000 (06:16 +0000)
source/datagramsocket.cpp
source/socket.cpp
source/streamlistensocket.cpp
source/streamsocket.cpp

index 1394ffa59db669965f94564a777385ac85e91ce6..9779bfeb268acb4722c3f21fb85b251405856c1c 100644 (file)
@@ -25,7 +25,7 @@ int DatagramSocket::connect(const SockAddr &addr)
 
        int err=::connect(handle, &sa, size);
        if(err==-1)
-               throw Exception(format("Unable to connect: %s", strerror(errno)));
+               throw SystemError("Unable to connect", errno);
 
        delete peer_addr;
        peer_addr=addr.copy();
@@ -56,7 +56,7 @@ unsigned DatagramSocket::sendto(const char *buf, unsigned size, const SockAddr &
                if(errno==EAGAIN)
                        return 0;
                else
-                       throw Exception(format("Sendto failed: %s", strerror(errno)));
+                       throw SystemError("Sendto failed", errno);
        }
 
        return ret;
@@ -78,7 +78,7 @@ unsigned DatagramSocket::recvfrom(char *buf, unsigned size, SockAddr *&addr_)
                if(errno==EAGAIN)
                        return 0;
                else
-                       throw Exception(format("Recvfrom failed: %s", strerror(errno)));
+                       throw SystemError("Recvfrom failed", errno);
        }
 
        addr_=SockAddr::create(addr);
index decdbeb9e2fd663c05a7e07819a30bdd0ca6e4bb..fcd686f1f24d810fb1eef4a6bc8faf139c841288 100644 (file)
@@ -77,7 +77,7 @@ void Socket::bind(const SockAddr &addr)
 
        int err=::bind(handle, &sa, size);
        if(err==-1)
-               throw Exception(format("Unable to bind: %s", strerror(errno)));
+               throw SystemError("Unable to bind", errno);
 
        delete local_addr;
        local_addr=addr.copy();
@@ -187,7 +187,7 @@ unsigned Socket::do_write(const char *buf, unsigned size)
                if(errno==EAGAIN)
                        return 0;
                else
-                       throw Exception(format("Writing to socket failed: %s", strerror(errno)));
+                       throw SystemError("Writing to socket failed", errno);
        }
 
        return ret;
@@ -206,7 +206,7 @@ unsigned Socket::do_read(char *buf, unsigned size)
                if(errno==EAGAIN)
                        return 0;
                else
-                       throw Exception(format("Reading from socket failed: %s", strerror(errno)));
+                       throw SystemError("Reading from socket failed", errno);
        }
        else if(ret==0 && !eof_flag)
        {
index df80b001f30e1eef9941d4ca70af353145c657b7..2a8bc3d216e89c85a4a69e1dd17017601c7e4ee7 100644 (file)
@@ -5,7 +5,7 @@ Copyright © 2008  Mikkosoft Productions, Mikko Rasa
 Distributed under the LGPL
 */
 
-#include <errno.h>
+#include <cerrno>
 #include <msp/core/refptr.h>
 #include <msp/strings/formatter.h>
 #include "streamlistensocket.h"
@@ -30,7 +30,7 @@ void StreamListenSocket::listen(const SockAddr &addr, unsigned backlog)
 
        int err=::listen(handle, backlog);
        if(err==-1)
-               throw Exception(format("Unable to listen: %s", strerror(errno)));
+               throw SystemError("Unable to listen", errno);
 
 #ifdef WIN32
        WSAEventSelect(handle, event, FD_ACCEPT);
index cf1a7b535203a1b3b643923d0ca09443e063c5b7..0f69111204af5ee0af783a158217ece68a7ecfa4 100644 (file)
@@ -8,7 +8,7 @@ Distributed under the LGPL
 #ifndef WIN32
 #include <sys/socket.h>
 #endif
-#include <errno.h>
+#include <cerrno>
 #include <msp/io/poll.h>
 #include <msp/strings/formatter.h>
 #include "streamsocket.h"
@@ -41,7 +41,7 @@ int StreamSocket::poll_connect(const Time::TimeDelta &timeout)
 #ifdef WIN32
                throw Exception(format("Connection polling failed: %d", WSAGetLastError()));
 #else
-               throw Exception(format("Connection polling failed: %s", strerror(errno)));
+               throw SystemError("Connection polling failed", errno);
 #endif
        else if(res>0)
        {
@@ -57,7 +57,7 @@ int StreamSocket::poll_connect(const Time::TimeDelta &timeout)
 #ifdef WIN32
                        throw Exception(format("Connection failed: %d", err));
 #else
-                       throw Exception(format("Connection failed: %s", strerror(err)));
+                       throw SystemError("Connection failed", err);
 #endif
                }
 
@@ -116,7 +116,7 @@ int StreamSocket::connect(const SockAddr &addr)
                        set_events(IO::P_OUTPUT);
                }
                else
-                       throw Exception(format("Unable to connect: %s", strerror(errno)));
+                       throw SystemError("Unable to connect", errno);
        }
 #endif