X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fnet%2Fclientsocket.cpp;h=7987f4b82bce50212ab23cbe1be573a71ef796d6;hb=6057616e00a6792e219fab2ce958306e737faa67;hp=04d07000a7bb1286c105a1697fdc71f0bc880901;hpb=88bbb4039aa274c7f41ebe3a18085b63427e5475;p=libs%2Fnet.git diff --git a/source/net/clientsocket.cpp b/source/net/clientsocket.cpp index 04d0700..7987f4b 100644 --- a/source/net/clientsocket.cpp +++ b/source/net/clientsocket.cpp @@ -1,21 +1,19 @@ #include "platform_api.h" -#include #include "clientsocket.h" +#include #include "socket_private.h" +using namespace std; + namespace Msp { namespace Net { ClientSocket::ClientSocket(Family af, int type, int proto): - Socket(af, type, proto), - connecting(false), - connected(false), - peer_addr(0) + Socket(af, type, proto) { } ClientSocket::ClientSocket(const Private &p, const SockAddr &paddr): Socket(p), - connecting(false), connected(true), peer_addr(paddr.copy()) { } @@ -23,8 +21,6 @@ ClientSocket::ClientSocket(const Private &p, const SockAddr &paddr): ClientSocket::~ClientSocket() { signal_flush_required.emit(); - - delete peer_addr; } void ClientSocket::shutdown(IO::Mode m) @@ -55,12 +51,12 @@ void ClientSocket::shutdown(IO::Mode m) const SockAddr &ClientSocket::get_peer_address() const { - if(peer_addr==0) + if(!peer_addr) throw bad_socket_state("not connected"); 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) @@ -72,7 +68,7 @@ unsigned ClientSocket::do_write(const char *buf, unsigned size) 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) @@ -81,15 +77,18 @@ unsigned ClientSocket::do_read(char *buf, unsigned size) if(size==0) return 0; - unsigned ret = check_sys_error(::recv(priv->handle, buf, size, 0), "recv"); - if(ret==0 && !eof_flag) + make_signed::type ret = ::recv(priv->handle, buf, size, 0); + if(ret==0) { - eof_flag = true; - signal_end_of_file.emit(); - set_socket_events(S_NONE); + if(!eof_flag) + { + set_socket_events(S_NONE); + set_eof(); + } + return 0; } - return ret; + return check_sys_error(ret, "recv"); } } // namespace Net