X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FService.cc;h=da135c1fea51513a2f7a4f3af2ebf8c02ab46293;hp=400006ba2eb6ee59a4e4dad2391b90dd3a55240a;hb=c85b710e7ead9bc417805bb893571a7139f1081c;hpb=3fd6f206f0e64122b7cb289907a1a780b6ed2dc9 diff --git a/src/Moof/Service.cc b/src/Moof/Service.cc index 400006b..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 << 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) { @@ -55,25 +55,24 @@ int ServiceFinder::handlePacket(SocketMultiplexer& sock, 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) { }