X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FSocket.hh;h=cc47f32ee41cf46f5c8bd38a8e9363fbc4e1171c;hp=a4cb310b3403b4183562354dedbc54d56ab24738;hb=c85b710e7ead9bc417805bb893571a7139f1081c;hpb=125f447cdb6cf668004e072510674ced91764ffb diff --git a/src/Moof/Socket.hh b/src/Moof/Socket.hh index a4cb310..cc47f32 100644 --- a/src/Moof/Socket.hh +++ b/src/Moof/Socket.hh @@ -95,9 +95,9 @@ public: * \param type The type of socket; either SOCK_STREAM or SOCK_DGRAM. * \param family The family; can be AF_INET or AF_INET6. */ - SocketAddress(const std::string& service, - int type = SOCK_STREAM, - int family = AF_UNSPEC) + explicit SocketAddress(const std::string& service, + int type = SOCK_STREAM, + int family = AF_UNSPEC) { init(service, type, family); } @@ -527,10 +527,10 @@ public: * \param family The family; can be AF_INET or AF_INET6. * \param flags The socket options. */ - Socket(const std::string& service, - int type = SOCK_STREAM, - int family = AF_UNSPEC, - int flags = 0) : + explicit Socket(const std::string& service, + int type = SOCK_STREAM, + int family = AF_UNSPEC, + int flags = 0) : mImpl(SocketAddress(service, type, family), flags) {} @@ -729,11 +729,13 @@ public: * \param flags The send options. * \return The number of bytes written. */ - ssize_t write(const void* bytes, size_t size, - const SocketAddress& address, int flags = 0) + ssize_t write(const void* bytes, + size_t size, + const SocketAddress& address, + int flags = 0) { return sendto(mImpl.fd, bytes, size, flags, - address.address(), address.size()); + address.address(), address.size()); } /** @@ -755,8 +757,9 @@ public: * \param flags The send options. * \return The number of bytes written. */ - ssize_t write(const Packet& packet, const SocketAddress& address, - int flags = 0) + ssize_t write(const Packet& packet, + const SocketAddress& address, + int flags = 0) { return write(packet.bytes(), packet.size(), address, flags); } @@ -771,7 +774,9 @@ public: */ ssize_t read(void* bytes, size_t size, int flags = 0) { - return recv(mImpl.fd, bytes, size, flags); + ssize_t result = recv(mImpl.fd, bytes, size, flags); + if (result == 0) mImpl.isConnected = false; + return result; } /** @@ -783,8 +788,10 @@ public: * \param flags The recv options. * \return The number of bytes read. */ - ssize_t read(void* bytes, size_t size, SocketAddress& address, - int flags = 0) + ssize_t read(void* bytes, + size_t size, + SocketAddress& address, + int flags = 0) { union { @@ -799,6 +806,10 @@ public: { address = SocketAddress(&addr.sa, length, mImpl.address.type()); } + else if (result == 0) + { + mImpl.isConnected = false; + } return result; } @@ -910,7 +921,7 @@ public: Packet&, const SocketAddress&)> Function; - SocketMultiplexer(Socket sock) : + explicit SocketMultiplexer(Socket sock) : mSocket(sock) {}