]> Dogcows Code - chaz/yoink/blobdiff - src/Moof/Socket.hh
more explicit constructors
[chaz/yoink] / src / Moof / Socket.hh
index da8132acf62657d9cd688d03e09dd0f165ce487d..cc47f32ee41cf46f5c8bd38a8e9363fbc4e1171c 100644 (file)
@@ -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);
        }
@@ -111,7 +111,7 @@ public:
                mType(addr->ai_socktype)
        {
                memcpy(&mAddr.sa, addr->ai_addr, addr->ai_addrlen);
-               getNameAndService(mService, mName);
+               getNameAndService(mName, mService);
        }
 
        /**
@@ -127,7 +127,7 @@ public:
                mType(type)
        {
                memcpy(&mAddr.sa, addr, size);
-               getNameAndService(mService, mName);
+               getNameAndService(mName, mService);
        }
 
 
@@ -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) {}
 
 
This page took 0.020291 seconds and 4 git commands to generate.