From de6942ee1401fea16a171610de779ef0a8c57e38 Mon Sep 17 00:00:00 2001 From: Charles McGarvey Date: Fri, 21 May 2010 04:15:26 -0600 Subject: [PATCH] constructors should be explicit --- src/Moof/Packet.hh | 2 +- src/Moof/Service.cc | 41 +++++++++++++++++++---------------------- src/Moof/Service.hh | 19 ++++++++++--------- src/Moof/Thread.hh | 10 +++++----- 4 files changed, 35 insertions(+), 37 deletions(-) diff --git a/src/Moof/Packet.hh b/src/Moof/Packet.hh index 8bcefff..db371f4 100644 --- a/src/Moof/Packet.hh +++ b/src/Moof/Packet.hh @@ -51,7 +51,7 @@ public: * 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 diff --git a/src/Moof/Service.cc b/src/Moof/Service.cc index 3432ae6..da135c1 100644 --- a/src/Moof/Service.cc +++ b/src/Moof/Service.cc @@ -20,32 +20,32 @@ namespace Mf { -int Service::handlePacket(SocketMultiplexer& sock, +int Service::handlePacket(SocketMultiplexer& mux, Packet& packet, const SocketAddress& address) { - uint32_t magic = 0; - try { + uint32_t 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; } -int ServiceFinder::handlePacket(SocketMultiplexer& sock, +int ServiceFinder::handlePacket(SocketMultiplexer& mux, Packet& packet, const SocketAddress& address) { @@ -62,16 +62,13 @@ int ServiceFinder::handlePacket(SocketMultiplexer& sock, 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; } } } - catch (...) - { - } - + catch (...) {} return -1; } diff --git a/src/Moof/Service.hh b/src/Moof/Service.hh index b26f4cf..570a230 100644 --- a/src/Moof/Service.hh +++ b/src/Moof/Service.hh @@ -34,25 +34,25 @@ class Service 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 type The type of service. * \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); /** - * 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 type The type of service. * \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); @@ -110,7 +110,7 @@ public: private: - int handlePacket(SocketMultiplexer& sock, + int handlePacket(SocketMultiplexer& mux, Packet& packet, const SocketAddress& address); @@ -130,14 +130,15 @@ public: * 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. */ - ServiceFinder(const std::string& type, int sockType = SOCK_STREAM); + explicit ServiceFinder(const std::string& type, + int sockType = SOCK_STREAM); const std::map& services() const @@ -148,7 +149,7 @@ public: private: - int handlePacket(SocketMultiplexer& sock, + int handlePacket(SocketMultiplexer& mux, Packet& packet, const SocketAddress& address); diff --git a/src/Moof/Thread.hh b/src/Moof/Thread.hh index 4888ab6..2987a59 100644 --- a/src/Moof/Thread.hh +++ b/src/Moof/Thread.hh @@ -252,7 +252,7 @@ public: * Construct a lock. * \param mutex The mutex. */ - Lock(Mutex& mutex) : + explicit Lock(Mutex& mutex) : mMutex(mutex), mIsLocked(false) {} @@ -317,7 +317,7 @@ public: * Construct a lock. * \param mutex The mutex. */ - ScopedLock(Mutex& mutex) : + explicit ScopedLock(Mutex& mutex) : Lock(mutex) { acquire(); @@ -458,7 +458,7 @@ public: * Construct a semaphore. * \param value The initial value of the semaphore. */ - Semaphore(uint32_t value) + explicit Semaphore(uint32_t value) { mSemaphore = SDL_CreateSemaphore(value); } @@ -531,7 +531,7 @@ public: * Construct a lock. * \param semaphore The semaphore. */ - Lock(Semaphore& semaphore) : + explicit Lock(Semaphore& semaphore) : mSemaphore(semaphore), mIsLocked(false) {} @@ -593,7 +593,7 @@ public: * Construct a lock. * \param semaphore The semaphore. */ - ScopedLock(Semaphore& semaphore) : + explicit ScopedLock(Semaphore& semaphore) : Lock(semaphore) { acquire(); -- 2.43.0