]> Dogcows Code - chaz/yoink/blobdiff - src/Moof/Service.cc
more explicit constructors
[chaz/yoink] / src / Moof / Service.cc
index 400006ba2eb6ee59a4e4dad2391b90dd3a55240a..da135c1fea51513a2f7a4f3af2ebf8c02ab46293 100644 (file)
 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)
 {
 }
 
This page took 0.021255 seconds and 4 git commands to generate.