]> Dogcows Code - chaz/yoink/blobdiff - src/Moof/Service.cc
exception-aware packets; other misc socket changes
[chaz/yoink] / src / Moof / Service.cc
index a5fae0f33862c05fd0d251e97593baca008ac881..400006ba2eb6ee59a4e4dad2391b90dd3a55240a 100644 (file)
 **************************************************************************/
 
 #include "Service.hh"
+#include "Socket.hh"
+
+
+#define SOLICIT  0x1234ABCD
+#define RESPONSE 0xABCD1234
 
 
 namespace Mf {
 
 
-ServiceFinder::ServiceFinder(const std::string& service, int type)
+int Service::handlePacket(SocketMultiplexer& sock,
+                                                 Packet& packet,
+                                                 const SocketAddress& address)
 {
+       uint32_t magic = 0;
+
+       try
+       {
+               packet >> magic;
+       }
+       catch (...)
+       {
+               return -1;
+       }
+
+       if (magic == SOLICIT)
+       {
+               Packet out;
+               out << RESPONSE << mAddress.service() << mText;
+               sock.socket().write(out);
+               return 0;
+       }
+       return -1;
 }
 
-void ServiceFinder::update(Scalar t, Scalar dt)
+int ServiceFinder::handlePacket(SocketMultiplexer& sock,
+                                                               Packet& packet,
+                                                               const SocketAddress& address)
+{
+       try
+       {
+               uint32_t magic;
+               packet >> magic;
+               if (magic == RESPONSE)
+               {
+                       std::string service;
+                       std::string     text;
+
+                       packet >> service >> text;
+                       if (service == mService)
+                       {
+                               mServices.push_back(Service(address, text));
+                               return 0;
+                       }
+               }
+       }
+       catch (...)
+       {
+       }
+
+       return -1;
+}
+
+ServiceFinder::ServiceFinder(const std::string& service, int type)
 {
 }
 
This page took 0.021397 seconds and 4 git commands to generate.