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 << mAddress.service() << 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)
{
packet >> magic;
if (magic == RESPONSE)
{
- std::string service;
- std::string text;
-
- packet >> service >> text;
- if (service == mService)
+ std::string type;
+ packet >> type;
+ if (type == mType)
{
- mServices.push_back(Service(address, text));
+ std::string name;
+ std::string text;
+ packet >> name >> text;
+ Service service(address, type, name, text);
+ mServices.insert(std::make_pair(name, service));
return 0;
}
}
}
- catch (...)
- {
- }
-
+ catch (...) {}
return -1;
}
-ServiceFinder::ServiceFinder(const std::string& service, int type)
+ServiceFinder::ServiceFinder(const std::string& type, int sockType)
{
}