]> git.tdb.fi Git - libs/net.git/blobdiff - source/datagramsocket.cpp
Exception changes
[libs/net.git] / source / datagramsocket.cpp
index aa097f13707a6efe71fc191f21fc17b9a7511145..e15a1d143c0281cc9686abd9b4e36a1da97a168c 100644 (file)
@@ -1,4 +1,5 @@
 #include <cerrno>
+#include <msp/core/systemerror.h>
 #include <msp/strings/format.h>
 #include "datagramsocket.h"
 
@@ -23,7 +24,13 @@ int DatagramSocket::connect(const SockAddr &addr)
 
        int err = ::connect(handle, reinterpret_cast<sockaddr *>(&sa), size);
        if(err==-1)
-               throw SystemError("Unable to connect", errno);
+       {
+#ifdef WIN32
+               throw system_error("connect", WSAGetLastError());
+#else
+               throw system_error("connect");
+#endif
+       }
 
        delete peer_addr;
        peer_addr = addr.copy();
@@ -54,7 +61,13 @@ unsigned DatagramSocket::sendto(const char *buf, unsigned size, const SockAddr &
                if(errno==EAGAIN)
                        return 0;
                else
-                       throw SystemError("Sendto failed", errno);
+               {
+#ifdef WIN32
+                       throw system_error("sendto", WSAGetLastError());
+#else
+                       throw system_error("sendto");
+#endif
+               }
        }
 
        return ret;
@@ -76,7 +89,13 @@ unsigned DatagramSocket::recvfrom(char *buf, unsigned size, SockAddr *&addr_)
                if(errno==EAGAIN)
                        return 0;
                else
-                       throw SystemError("Recvfrom failed", errno);
+               {
+#ifdef WIN32
+                       throw system_error("recvfrom", WSAGetLastError());
+#else
+                       throw system_error("recvfrom");
+#endif
+               }
        }
 
        addr_ = SockAddr::create(addr);