diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-05-11 13:02:29 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-05-11 13:02:29 +0000 |
commit | e6a918a6b4e22ba7bf61ba418923837481864a8c (patch) | |
tree | 844df68386c5492e2c908ec745b6973a548f0de2 /src | |
parent | 647428d5ed0708276983bca2bc91e430bf2b6a6e (diff) | |
download | gnunet-e6a918a6b4e22ba7bf61ba418923837481864a8c.tar.gz gnunet-e6a918a6b4e22ba7bf61ba418923837481864a8c.zip |
fix mockup
Diffstat (limited to 'src')
-rw-r--r-- | src/arm/mockup-service.c | 72 |
1 files changed, 70 insertions, 2 deletions
diff --git a/src/arm/mockup-service.c b/src/arm/mockup-service.c index fbc6b04ba..dd0f5b122 100644 --- a/src/arm/mockup-service.c +++ b/src/arm/mockup-service.c | |||
@@ -28,14 +28,82 @@ | |||
28 | #include "gnunet_strings_lib.h" | 28 | #include "gnunet_strings_lib.h" |
29 | #include "gnunet_time_lib.h" | 29 | #include "gnunet_time_lib.h" |
30 | 30 | ||
31 | static struct GNUNET_SCHEDULER_Handle *sched; | ||
32 | |||
33 | |||
34 | static size_t | ||
35 | transmit_shutdown_ack (void *cls, size_t size, void *buf) | ||
36 | { | ||
37 | struct GNUNET_SERVER_Client *client = cls; | ||
38 | struct GNUNET_MessageHeader *msg; | ||
39 | |||
40 | if (size < sizeof (struct GNUNET_MessageHeader)) | ||
41 | { | ||
42 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
43 | _("Failed to transmit shutdown ACK.\n")); | ||
44 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
45 | return 0; /* client disconnected */ | ||
46 | } | ||
47 | |||
48 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
49 | _("Transmitting shutdown ACK.\n")); | ||
50 | |||
51 | msg = (struct GNUNET_MessageHeader *) buf; | ||
52 | msg->type = htons (GNUNET_MESSAGE_TYPE_SHUTDOWN_ACK); | ||
53 | msg->size = htons (sizeof (struct GNUNET_MessageHeader)); | ||
54 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
55 | GNUNET_SERVER_client_drop(client); | ||
56 | return sizeof (struct GNUNET_MessageHeader); | ||
57 | } | ||
58 | |||
59 | /** | ||
60 | * Handler for SHUTDOWN message. | ||
61 | * | ||
62 | * @param cls closure (refers to service) | ||
63 | * @param client identification of the client | ||
64 | * @param message the actual message | ||
65 | */ | ||
66 | static void | ||
67 | handle_shutdown (void *cls, | ||
68 | struct GNUNET_SERVER_Client *client, | ||
69 | const struct GNUNET_MessageHeader *message) | ||
70 | { | ||
71 | GNUNET_SERVER_client_keep(client); | ||
72 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
73 | _("Initiating shutdown as requested by client.\n")); | ||
74 | |||
75 | GNUNET_SERVER_notify_transmit_ready (client, | ||
76 | sizeof(struct GNUNET_MessageHeader), | ||
77 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
78 | &transmit_shutdown_ack, client); | ||
79 | GNUNET_SERVER_client_persist_ (client); | ||
80 | GNUNET_SCHEDULER_shutdown (sched); | ||
81 | } | ||
82 | |||
83 | |||
84 | /** | ||
85 | * Default handlers for all services. Will be copied and the | ||
86 | * "callback_cls" fields will be replaced with the specific service | ||
87 | * struct. | ||
88 | */ | ||
89 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { | ||
90 | {&handle_shutdown, NULL, GNUNET_MESSAGE_TYPE_SHUTDOWN, | ||
91 | sizeof (struct GNUNET_MessageHeader)}, | ||
92 | {NULL, NULL, 0, 0} | ||
93 | }; | ||
94 | |||
95 | |||
31 | 96 | ||
32 | static void | 97 | static void |
33 | run (void *cls, | 98 | run (void *cls, |
34 | struct GNUNET_SCHEDULER_Handle *sched, | 99 | struct GNUNET_SCHEDULER_Handle *s, |
35 | struct GNUNET_SERVER_Handle *server, | 100 | struct GNUNET_SERVER_Handle *server, |
36 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 101 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
37 | { | 102 | { |
38 | /* Does nothing */ | 103 | sched = s; |
104 | /* process client requests */ | ||
105 | GNUNET_SERVER_ignore_shutdown (server, GNUNET_YES); | ||
106 | GNUNET_SERVER_add_handlers (server, handlers); | ||
39 | } | 107 | } |
40 | 108 | ||
41 | 109 | ||