]> Dogcows Code - chaz/yoink/commitdiff
constructors should be explicit
authorCharles McGarvey <chazmcgarvey@brokenzipper.com>
Fri, 21 May 2010 10:15:26 +0000 (04:15 -0600)
committerCharles McGarvey <chazmcgarvey@brokenzipper.com>
Fri, 21 May 2010 10:15:26 +0000 (04:15 -0600)
src/Moof/Packet.hh
src/Moof/Service.cc
src/Moof/Service.hh
src/Moof/Thread.hh

index 8bcefffc95b0b86f9280b7f908e52f0b7b8448eb..db371f4e58bd22081c12daf721c0bddd73eccc48 100644 (file)
@@ -51,7 +51,7 @@ public:
         * Construct a packet with an initial capacity.
         * \param capacity Initial capacity of the packet.
         */
         * Construct a packet with an initial capacity.
         * \param capacity Initial capacity of the packet.
         */
-       Packet(size_t size = PAGE_SIZE);
+       explicit Packet(size_t size = PAGE_SIZE);
 
        /**
         * Construct a packet with some bytes from a buffer.  The bytes will be
 
        /**
         * Construct a packet with some bytes from a buffer.  The bytes will be
index 3432ae6ac12c763857fe25d558442a18f192f66f..da135c1fea51513a2f7a4f3af2ebf8c02ab46293 100644 (file)
 namespace Mf {
 
 
 namespace Mf {
 
 
-int Service::handlePacket(SocketMultiplexer& sock,
+int Service::handlePacket(SocketMultiplexer& mux,
                                                  Packet& packet,
                                                  const SocketAddress& address)
 {
                                                  Packet& packet,
                                                  const SocketAddress& address)
 {
-       uint32_t magic = 0;
-
        try
        {
        try
        {
+               uint32_t magic;
                packet >> magic;
                packet >> magic;
+               if (magic == SOLICIT)
+               {
+                       std::string type;
+                       packet >> type;
+                       if (type == mType)
+                       {
+                               packet.clear();
+                               packet << RESPONSE << mType << mName << mText;
+                               mux.socket().write(packet);
+                               return 0;
+                       }
+               }
        }
        }
-       catch (...)
-       {
-               return -1;
-       }
-
-       if (magic == SOLICIT)
-       {
-               Packet out;
-               out << RESPONSE << mType << mName << mText;
-               sock.socket().write(out);
-               return 0;
-       }
+       catch (...) {}
        return -1;
 }
 
        return -1;
 }
 
-int ServiceFinder::handlePacket(SocketMultiplexer& sock,
+int ServiceFinder::handlePacket(SocketMultiplexer& mux,
                                                                Packet& packet,
                                                                const SocketAddress& address)
 {
                                                                Packet& packet,
                                                                const SocketAddress& address)
 {
@@ -62,16 +62,13 @@ int ServiceFinder::handlePacket(SocketMultiplexer& sock,
                                std::string name;
                                std::string     text;
                                packet >> name >> text;
                                std::string name;
                                std::string     text;
                                packet >> name >> text;
-                               mServices.insert(std::make_pair(name,
-                                                                                               Service(address, name, text)));
+                               Service service(address, type, name, text);
+                               mServices.insert(std::make_pair(name, service));
                                return 0;
                        }
                }
        }
                                return 0;
                        }
                }
        }
-       catch (...)
-       {
-       }
-
+       catch (...) {}
        return -1;
 }
 
        return -1;
 }
 
index b26f4cfb375a01433eb9f1c3c5c59a371f0f4028..570a2309e270cb235a7abe7e1b8819d12a7264a6 100644 (file)
@@ -34,25 +34,25 @@ class Service
 public:
 
        /**
 public:
 
        /**
-        * Construct a network service.  The type of service will be inferred
-        * from the address.
+        * Construct a network service with an explicit type.
         * \param address The address of the host.
         * \param address The address of the host.
+        * \param type The type of service.
         * \param name The service name.
         * \param text The service information.
         */
        Service(const SocketAddress& address,
         * \param name The service name.
         * \param text The service information.
         */
        Service(const SocketAddress& address,
+                       const std::string& type,
                        const std::string& name,
                        const std::string& text);
 
        /**
                        const std::string& name,
                        const std::string& text);
 
        /**
-        * Construct a network service with an explicit type.
+        * Construct a network service.  The type of service will be inferred
+        * from the address.
         * \param address The address of the host.
         * \param address The address of the host.
-        * \param type The type of service.
         * \param name The service name.
         * \param text The service information.
         */
        Service(const SocketAddress& address,
         * \param name The service name.
         * \param text The service information.
         */
        Service(const SocketAddress& address,
-                       const std::string& type,
                        const std::string& name,
                        const std::string& text);
 
                        const std::string& name,
                        const std::string& text);
 
@@ -110,7 +110,7 @@ public:
 
 private:
 
 
 private:
 
-       int handlePacket(SocketMultiplexer& sock,
+       int handlePacket(SocketMultiplexer& mux,
                                         Packet& packet,
                                         const SocketAddress& address);
 
                                         Packet& packet,
                                         const SocketAddress& address);
 
@@ -130,14 +130,15 @@ public:
         * address.
         * \address The address.
         */
         * address.
         * \address The address.
         */
-       ServiceFinder(const SocketAddress& address);
+       explicit ServiceFinder(const SocketAddress& address);
 
        /**
         * Construct a service finder to find services of a certain type.
         * \param type The type of the service.
         * \param sockType The type of socket.
         */
 
        /**
         * Construct a service finder to find services of a certain type.
         * \param type The type of the service.
         * \param sockType The type of socket.
         */
-       ServiceFinder(const std::string& type, int sockType = SOCK_STREAM);
+       explicit ServiceFinder(const std::string& type,
+                                                  int sockType = SOCK_STREAM);
 
 
        const std::map<std::string,Service>& services() const
 
 
        const std::map<std::string,Service>& services() const
@@ -148,7 +149,7 @@ public:
 
 private:
 
 
 private:
 
-       int handlePacket(SocketMultiplexer& sock,
+       int handlePacket(SocketMultiplexer& mux,
                                         Packet& packet,
                                         const SocketAddress& address);
 
                                         Packet& packet,
                                         const SocketAddress& address);
 
index 4888ab6408be05225dc9fe880730f9bd4fe474ba..2987a59b968716b7649c1eb5d180072f3c308e8a 100644 (file)
@@ -252,7 +252,7 @@ public:
                 * Construct a lock.
                 * \param mutex The mutex.
                 */
                 * Construct a lock.
                 * \param mutex The mutex.
                 */
-        Lock(Mutex& mutex) :
+        explicit Lock(Mutex& mutex) :
                        mMutex(mutex),
                        mIsLocked(false) {}
 
                        mMutex(mutex),
                        mIsLocked(false) {}
 
@@ -317,7 +317,7 @@ public:
                 * Construct a lock.
                 * \param mutex The mutex.
                 */
                 * Construct a lock.
                 * \param mutex The mutex.
                 */
-               ScopedLock(Mutex& mutex) :
+               explicit ScopedLock(Mutex& mutex) :
                        Lock(mutex)
                {
                        acquire();
                        Lock(mutex)
                {
                        acquire();
@@ -458,7 +458,7 @@ public:
         * Construct a semaphore.
         * \param value The initial value of the semaphore.
         */
         * Construct a semaphore.
         * \param value The initial value of the semaphore.
         */
-    Semaphore(uint32_t value)
+    explicit Semaphore(uint32_t value)
        {
                mSemaphore = SDL_CreateSemaphore(value);
        }
        {
                mSemaphore = SDL_CreateSemaphore(value);
        }
@@ -531,7 +531,7 @@ public:
                 * Construct a lock.
                 * \param semaphore The semaphore.
                 */
                 * Construct a lock.
                 * \param semaphore The semaphore.
                 */
-        Lock(Semaphore& semaphore) :
+        explicit Lock(Semaphore& semaphore) :
                        mSemaphore(semaphore),
                        mIsLocked(false) {}
 
                        mSemaphore(semaphore),
                        mIsLocked(false) {}
 
@@ -593,7 +593,7 @@ public:
                 * Construct a lock.
                 * \param semaphore The semaphore.
                 */
                 * Construct a lock.
                 * \param semaphore The semaphore.
                 */
-        ScopedLock(Semaphore& semaphore) :
+        explicit ScopedLock(Semaphore& semaphore) :
                        Lock(semaphore)
                {
                        acquire();
                        Lock(semaphore)
                {
                        acquire();
This page took 0.031101 seconds and 4 git commands to generate.