]> git.tdb.fi Git - libs/net.git/blobdiff - source/net/clientsocket.cpp
Move most platform-specific code into overlay directories
[libs/net.git] / source / net / clientsocket.cpp
index cbf18e593bdadc458ed862ab9aba326025df0bd1..04d07000a7bb1286c105a1697fdc71f0bc880901 100644 (file)
@@ -1,9 +1,4 @@
-#ifdef _WIN32
-#include <winsock2.h>
-#else
-#include <cerrno>
-#include <sys/socket.h>
-#endif
+#include "platform_api.h"
 #include <msp/core/systemerror.h>
 #include "clientsocket.h"
 #include "socket_private.h"
@@ -74,16 +69,7 @@ unsigned ClientSocket::do_write(const char *buf, unsigned size)
        if(size==0)
                return 0;
 
-       int ret = ::send(priv->handle, buf, size, 0);
-       if(ret<0)
-       {
-               if(errno==EAGAIN)
-                       return 0;
-               else
-                       throw system_error("send");
-       }
-
-       return ret;
+       return check_sys_error(::send(priv->handle, buf, size, 0), "send");
 }
 
 unsigned ClientSocket::do_read(char *buf, unsigned size)
@@ -95,19 +81,12 @@ unsigned ClientSocket::do_read(char *buf, unsigned size)
        if(size==0)
                return 0;
 
-       int ret = ::recv(priv->handle, buf, size, 0);
-       if(ret<0)
-       {
-               if(errno==EAGAIN)
-                       return 0;
-               else
-                       throw system_error("recv");
-       }
-       else if(ret==0 && !eof_flag)
+       unsigned ret = check_sys_error(::recv(priv->handle, buf, size, 0), "recv");
+       if(ret==0 && !eof_flag)
        {
                eof_flag = true;
                signal_end_of_file.emit();
-               set_events(IO::P_NONE);
+               set_socket_events(S_NONE);
        }
 
        return ret;