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)
{
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;
}
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);
private:
- int handlePacket(SocketMultiplexer& sock,
+ int handlePacket(SocketMultiplexer& mux,
Packet& packet,
const SocketAddress& 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.
*/
- 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
private:
- int handlePacket(SocketMultiplexer& sock,
+ int handlePacket(SocketMultiplexer& mux,
Packet& packet,
const SocketAddress& address);
* Construct a lock.
* \param mutex The mutex.
*/
- Lock(Mutex& mutex) :
+ explicit Lock(Mutex& mutex) :
mMutex(mutex),
mIsLocked(false) {}
* Construct a lock.
* \param mutex The mutex.
*/
- ScopedLock(Mutex& mutex) :
+ explicit ScopedLock(Mutex& mutex) :
Lock(mutex)
{
acquire();
* Construct a semaphore.
* \param value The initial value of the semaphore.
*/
- Semaphore(uint32_t value)
+ explicit Semaphore(uint32_t value)
{
mSemaphore = SDL_CreateSemaphore(value);
}
* Construct a lock.
* \param semaphore The semaphore.
*/
- Lock(Semaphore& semaphore) :
+ explicit Lock(Semaphore& semaphore) :
mSemaphore(semaphore),
mIsLocked(false) {}
* Construct a lock.
* \param semaphore The semaphore.
*/
- ScopedLock(Semaphore& semaphore) :
+ explicit ScopedLock(Semaphore& semaphore) :
Lock(semaphore)
{
acquire();