]> Dogcows Code - chaz/yoink/blob - src/moof/service.cc
use only triangles; no quads
[chaz/yoink] / src / moof / service.cc
1
2 /*] Copyright (c) 2009-2010, Charles McGarvey [**************************
3 **] All rights reserved.
4 *
5 * vi:ts=4 sw=4 tw=75
6 *
7 * Distributable under the terms and conditions of the 2-clause BSD license;
8 * see the file COPYING for a complete text of the license.
9 *
10 **************************************************************************/
11
12 #include "service.hh"
13 #include "socket.hh"
14
15
16 #define SOLICIT 0x1234ABCD
17 #define RESPONSE 0xABCD1234
18
19
20 namespace moof {
21
22
23 int service::handle_packet(socket_multiplexer& mux,
24 packet& packet,
25 const socket::address& address)
26 {
27 try
28 {
29 uint32_t magic;
30 packet >> magic;
31 if (magic == SOLICIT)
32 {
33 std::string type;
34 packet >> type;
35 if (type == type_)
36 {
37 packet.clear();
38 packet << RESPONSE << type_ << name_ << text_;
39 mux.socket().write(packet);
40 return 0;
41 }
42 }
43 }
44 catch (...) {}
45 return -1;
46 }
47
48 int service_finder::handle_packet(socket_multiplexer& mux,
49 packet& packet,
50 const socket::address& address)
51 {
52 try
53 {
54 uint32_t magic;
55 packet >> magic;
56 if (magic == RESPONSE)
57 {
58 std::string type;
59 packet >> type;
60 if (type == type_)
61 {
62 std::string name;
63 std::string text;
64 packet >> name >> text;
65 service service(address, type, name, text);
66 services_.insert(std::make_pair(name, service));
67 return 0;
68 }
69 }
70 }
71 catch (...) {}
72 return -1;
73 }
74
75 service_finder::service_finder(const std::string& type, int sockType)
76 {
77 }
78
79
80 } // namespace moof
81
This page took 0.034283 seconds and 4 git commands to generate.