aboutsummaryrefslogtreecommitdiff
path: root/src/arm
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-09-20 16:10:08 +0000
committerChristian Grothoff <christian@grothoff.org>2013-09-20 16:10:08 +0000
commitc2888c6fee538824dc1e176d5336c4bbd86314df (patch)
treee6b974df33279737bd2600a2f00717ee849901c1 /src/arm
parent042171eb0499aae5130095ab213fb9b8c78113ce (diff)
downloadgnunet-c2888c6fee538824dc1e176d5336c4bbd86314df.tar.gz
gnunet-c2888c6fee538824dc1e176d5336c4bbd86314df.zip
-minor code cleanup
Diffstat (limited to 'src/arm')
-rw-r--r--src/arm/gnunet-service-arm.c72
1 files changed, 45 insertions, 27 deletions
diff --git a/src/arm/gnunet-service-arm.c b/src/arm/gnunet-service-arm.c
index f5426e176..906f0adde 100644
--- a/src/arm/gnunet-service-arm.c
+++ b/src/arm/gnunet-service-arm.c
@@ -240,10 +240,10 @@ static struct GNUNET_SERVER_NotificationContext *notifier;
240/** 240/**
241 * Transmit a status result message. 241 * Transmit a status result message.
242 * 242 *
243 * @param cls pointer to "unit16_t*" with message type 243 * @param cls a `unit16_t *` with message type
244 * @param size number of bytes available in buf 244 * @param size number of bytes available in @a buf
245 * @param buf where to copy the message, NULL on error 245 * @param buf where to copy the message, NULL on error
246 * @return number of bytes copied to buf 246 * @return number of bytes copied to @a buf
247 */ 247 */
248static size_t 248static size_t
249write_result (void *cls, size_t size, void *buf) 249write_result (void *cls, size_t size, void *buf)
@@ -259,7 +259,8 @@ write_result (void *cls, size_t size, void *buf)
259 return 0; /* error, not much we can do */ 259 return 0; /* error, not much we can do */
260 } 260 }
261 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 261 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
262 "Sending status response %u to client\n", (unsigned int) msg->result); 262 "Sending status response %u to client\n",
263 (unsigned int) msg->result);
263 msize = msg->arm_msg.header.size; 264 msize = msg->arm_msg.header.size;
264 GNUNET_assert (size >= msize); 265 GNUNET_assert (size >= msize);
265 msg->arm_msg.header.size = htons (msg->arm_msg.header.size); 266 msg->arm_msg.header.size = htons (msg->arm_msg.header.size);
@@ -271,13 +272,14 @@ write_result (void *cls, size_t size, void *buf)
271 return msize; 272 return msize;
272} 273}
273 274
275
274/** 276/**
275 * Transmit the list of running services. 277 * Transmit the list of running services.
276 * 278 *
277 * @param cls pointer to struct GNUNET_ARM_ListResultMessage with the message 279 * @param cls pointer to `struct GNUNET_ARM_ListResultMessage` with the message
278 * @param size number of bytes available in buf 280 * @param size number of bytes available in @a buf
279 * @param buf where to copy the message, NULL on error 281 * @param buf where to copy the message, NULL on error
280 * @return number of bytes copied to buf 282 * @return number of bytes copied to @a buf
281 */ 283 */
282static size_t 284static size_t
283write_list_result (void *cls, size_t size, void *buf) 285write_list_result (void *cls, size_t size, void *buf)
@@ -317,8 +319,10 @@ write_list_result (void *cls, size_t size, void *buf)
317 * @return NULL if it was not found 319 * @return NULL if it was not found
318 */ 320 */
319static void 321static void
320signal_result (struct GNUNET_SERVER_Client *client, const char *name, 322signal_result (struct GNUNET_SERVER_Client *client,
321 uint64_t request_id, enum GNUNET_ARM_Result result) 323 const char *name,
324 uint64_t request_id,
325 enum GNUNET_ARM_Result result)
322{ 326{
323 struct GNUNET_ARM_ResultMessage *msg; 327 struct GNUNET_ARM_ResultMessage *msg;
324 size_t msize; 328 size_t msize;
@@ -331,7 +335,8 @@ signal_result (struct GNUNET_SERVER_Client *client, const char *name,
331 msg->arm_msg.request_id = request_id; 335 msg->arm_msg.request_id = request_id;
332 336
333 GNUNET_SERVER_notify_transmit_ready (client, msize, 337 GNUNET_SERVER_notify_transmit_ready (client, msize,
334 GNUNET_TIME_UNIT_FOREVER_REL, write_result, msg); 338 GNUNET_TIME_UNIT_FOREVER_REL,
339 write_result, msg);
335} 340}
336 341
337 342
@@ -344,8 +349,9 @@ signal_result (struct GNUNET_SERVER_Client *client, const char *name,
344 * otherwise, send to all clients in the notifier 349 * otherwise, send to all clients in the notifier
345 */ 350 */
346static void 351static void
347broadcast_status (const char *name, enum GNUNET_ARM_ServiceStatus status, 352broadcast_status (const char *name,
348 struct GNUNET_SERVER_Client *unicast) 353 enum GNUNET_ARM_ServiceStatus status,
354 struct GNUNET_SERVER_Client *unicast)
349{ 355{
350 struct GNUNET_ARM_StatusMessage *msg; 356 struct GNUNET_ARM_StatusMessage *msg;
351 size_t namelen; 357 size_t namelen;
@@ -544,7 +550,7 @@ find_service (const char *name)
544 * First connection has come to the listening socket associated with the service, 550 * First connection has come to the listening socket associated with the service,
545 * create the service in order to relay the incoming connection to it 551 * create the service in order to relay the incoming connection to it
546 * 552 *
547 * @param cls callback data, struct ServiceListeningInfo describing a listen socket 553 * @param cls callback data, `struct ServiceListeningInfo` describing a listen socket
548 * @param tc context 554 * @param tc context
549 */ 555 */
550static void 556static void
@@ -566,7 +572,7 @@ accept_connection (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
566 * wait for the first incoming connection to it 572 * wait for the first incoming connection to it
567 * 573 *
568 * @param sa address associated with the service 574 * @param sa address associated with the service
569 * @param addr_len length of sa 575 * @param addr_len length of @a sa
570 * @param sl service entry for the service in question 576 * @param sl service entry for the service in question
571 */ 577 */
572static void 578static void
@@ -674,8 +680,8 @@ free_service (struct ServiceList *sl)
674 * @param cls closure (always NULL) 680 * @param cls closure (always NULL)
675 * @param client identification of the client 681 * @param client identification of the client
676 * @param message the actual message 682 * @param message the actual message
677 * @return GNUNET_OK to keep the connection open, 683 * @return #GNUNET_OK to keep the connection open,
678 * GNUNET_SYSERR to close it (signal serious error) 684 * #GNUNET_SYSERR to close it (signal serious error)
679 */ 685 */
680static void 686static void
681handle_start (void *cls, struct GNUNET_SERVER_Client *client, 687handle_start (void *cls, struct GNUNET_SERVER_Client *client,
@@ -743,8 +749,8 @@ trigger_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
743 * @param cls closure (always NULL) 749 * @param cls closure (always NULL)
744 * @param client identification of the client 750 * @param client identification of the client
745 * @param message the actual message 751 * @param message the actual message
746 * @return GNUNET_OK to keep the connection open, 752 * @return #GNUNET_OK to keep the connection open,
747 * GNUNET_SYSERR to close it (signal serious error) 753 * #GNUNET_SYSERR to close it (signal serious error)
748 */ 754 */
749static void 755static void
750handle_stop (void *cls, struct GNUNET_SERVER_Client *client, 756handle_stop (void *cls, struct GNUNET_SERVER_Client *client,
@@ -823,6 +829,7 @@ handle_stop (void *cls, struct GNUNET_SERVER_Client *client,
823 GNUNET_SERVER_receive_done (client, GNUNET_OK); 829 GNUNET_SERVER_receive_done (client, GNUNET_OK);
824} 830}
825 831
832
826/** 833/**
827 * Handle LIST-message. 834 * Handle LIST-message.
828 * 835 *
@@ -885,6 +892,7 @@ handle_list (void *cls, struct GNUNET_SERVER_Client *client,
885 GNUNET_SERVER_receive_done (client, GNUNET_OK); 892 GNUNET_SERVER_receive_done (client, GNUNET_OK);
886} 893}
887 894
895
888/** 896/**
889 * We are done with everything. Stop remaining 897 * We are done with everything. Stop remaining
890 * tasks, signal handler and the server. 898 * tasks, signal handler and the server.
@@ -910,16 +918,21 @@ do_shutdown ()
910 } 918 }
911} 919}
912 920
913unsigned int 921
922static unsigned int
914list_count (struct ServiceList *running_head) 923list_count (struct ServiceList *running_head)
915{ 924{
916 struct ServiceList *i; 925 struct ServiceList *i;
917 unsigned int res = 0; 926 unsigned int res = 0;
927
918 for (res = 0, i = running_head; i; i = i->next, res++) 928 for (res = 0, i = running_head; i; i = i->next, res++)
919 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s\n", i->name); 929 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
930 "%s\n",
931 i->name);
920 return res; 932 return res;
921} 933}
922 934
935
923/** 936/**
924 * Task run for shutdown. 937 * Task run for shutdown.
925 * 938 *
@@ -933,7 +946,8 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
933 struct ServiceList *nxt; 946 struct ServiceList *nxt;
934 struct ServiceListeningInfo *sli; 947 struct ServiceListeningInfo *sli;
935 948
936 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "First shutdown phase\n"); 949 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
950 "First shutdown phase\n");
937 if (GNUNET_SCHEDULER_NO_TASK != child_restart_task) 951 if (GNUNET_SCHEDULER_NO_TASK != child_restart_task)
938 { 952 {
939 GNUNET_SCHEDULER_cancel (child_restart_task); 953 GNUNET_SCHEDULER_cancel (child_restart_task);
@@ -965,7 +979,8 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
965 nxt = pos->next; 979 nxt = pos->next;
966 if (pos->proc != NULL) 980 if (pos->proc != NULL)
967 { 981 {
968 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stopping service `%s'\n", 982 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
983 "Stopping service `%s'\n",
969 pos->name); 984 pos->name);
970 pos->killed_at = GNUNET_TIME_absolute_get (); 985 pos->killed_at = GNUNET_TIME_absolute_get ();
971 if (0 != GNUNET_OS_process_kill (pos->proc, SIGTERM)) 986 if (0 != GNUNET_OS_process_kill (pos->proc, SIGTERM))
@@ -981,7 +996,8 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
981 do_shutdown (); 996 do_shutdown ();
982 else 997 else
983 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 998 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
984 "Delaying shutdown, have %u childs still running\n", list_count (running_head)); 999 "Delaying shutdown, have %u childs still running\n",
1000 list_count (running_head));
985} 1001}
986 1002
987 1003
@@ -1218,7 +1234,7 @@ sighandler_child_death ()
1218 * 1234 *
1219 * @param cls unused 1235 * @param cls unused
1220 * @param section a section in the configuration file 1236 * @param section a section in the configuration file
1221 * @return GNUNET_OK (continue) 1237 * @return #GNUNET_OK (continue)
1222 */ 1238 */
1223static void 1239static void
1224setup_service (void *cls, const char *section) 1240setup_service (void *cls, const char *section)
@@ -1266,7 +1282,7 @@ setup_service (void *cls, const char *section)
1266 config = NULL; 1282 config = NULL;
1267 } 1283 }
1268 } 1284 }
1269 sl = GNUNET_malloc (sizeof (struct ServiceList)); 1285 sl = GNUNET_new (struct ServiceList);
1270 sl->name = GNUNET_strdup (section); 1286 sl->name = GNUNET_strdup (section);
1271 sl->binary = binary; 1287 sl->binary = binary;
1272 sl->config = config; 1288 sl->config = config;
@@ -1309,14 +1325,15 @@ handle_client_connecting (void *cls, struct GNUNET_SERVER_Client *client)
1309 GNUNET_SERVER_client_mark_monitor (client); 1325 GNUNET_SERVER_client_mark_monitor (client);
1310} 1326}
1311 1327
1328
1312/** 1329/**
1313 * Handle MONITOR-message. 1330 * Handle MONITOR-message.
1314 * 1331 *
1315 * @param cls closure (always NULL) 1332 * @param cls closure (always NULL)
1316 * @param client identification of the client 1333 * @param client identification of the client
1317 * @param message the actual message 1334 * @param message the actual message
1318 * @return GNUNET_OK to keep the connection open, 1335 * @return #GNUNET_OK to keep the connection open,
1319 * GNUNET_SYSERR to close it (signal serious error) 1336 * #GNUNET_SYSERR to close it (signal serious error)
1320 */ 1337 */
1321static void 1338static void
1322handle_monitor (void *cls, struct GNUNET_SERVER_Client *client, 1339handle_monitor (void *cls, struct GNUNET_SERVER_Client *client,
@@ -1331,6 +1348,7 @@ handle_monitor (void *cls, struct GNUNET_SERVER_Client *client,
1331 } 1348 }
1332} 1349}
1333 1350
1351
1334/** 1352/**
1335 * Process arm requests. 1353 * Process arm requests.
1336 * 1354 *