X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fnet%2Fclientsocket.cpp;h=9cabeef9c7714b7f743bf350b37c067d739714a2;hb=363778f74fba9d9b85980df0590f8106dfd0a6b0;hp=cbf18e593bdadc458ed862ab9aba326025df0bd1;hpb=136c9eec2b72bfad4788908de5552fbd62216148;p=libs%2Fnet.git diff --git a/source/net/clientsocket.cpp b/source/net/clientsocket.cpp index cbf18e5..9cabeef 100644 --- a/source/net/clientsocket.cpp +++ b/source/net/clientsocket.cpp @@ -1,9 +1,4 @@ -#ifdef _WIN32 -#include -#else -#include -#include -#endif +#include "platform_api.h" #include #include "clientsocket.h" #include "socket_private.h" @@ -65,7 +60,7 @@ const SockAddr &ClientSocket::get_peer_address() const return *peer_addr; } -unsigned ClientSocket::do_write(const char *buf, unsigned size) +size_t ClientSocket::do_write(const char *buf, size_t size) { check_access(IO::M_WRITE); if(!connected) @@ -74,19 +69,10 @@ 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) +size_t ClientSocket::do_read(char *buf, size_t size) { check_access(IO::M_READ); if(!connected) @@ -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) + size_t ret = check_sys_error(::recv(priv->handle, buf, size, 0), "recv"); + if(ret==0 && !eof_flag) { eof_flag = true; + set_socket_events(S_NONE); signal_end_of_file.emit(); - set_events(IO::P_NONE); } return ret;