diff options
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/client.c | 23 | ||||
-rw-r--r-- | src/util/test_service.c | 1 |
2 files changed, 19 insertions, 5 deletions
diff --git a/src/util/client.c b/src/util/client.c index 8c429995c..3c6f0c405 100644 --- a/src/util/client.c +++ b/src/util/client.c | |||
@@ -468,13 +468,28 @@ GNUNET_CLIENT_receive (struct GNUNET_CLIENT_Connection *sock, | |||
468 | } | 468 | } |
469 | 469 | ||
470 | 470 | ||
471 | /** | ||
472 | * If possible, write a shutdown message to the target | ||
473 | * buffer and destroy the client connection. | ||
474 | * | ||
475 | * @param cls the "struct GNUNET_CLIENT_Connection" to destroy | ||
476 | * @param size number of bytes available in buf | ||
477 | * @param buf NULL on error, otherwise target buffer | ||
478 | * @return number of bytes written to buf | ||
479 | */ | ||
471 | static size_t | 480 | static size_t |
472 | write_shutdown (void *cls, size_t size, void *buf) | 481 | write_shutdown (void *cls, size_t size, void *buf) |
473 | { | 482 | { |
474 | struct GNUNET_MessageHeader *msg; | 483 | struct GNUNET_MessageHeader *msg; |
484 | struct GNUNET_CLIENT_Connection *sock = cls; | ||
475 | 485 | ||
486 | GNUNET_CLIENT_disconnect (sock); | ||
476 | if (size < sizeof (struct GNUNET_MessageHeader)) | 487 | if (size < sizeof (struct GNUNET_MessageHeader)) |
477 | return 0; /* client disconnected */ | 488 | { |
489 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
490 | _("Failed to transmit shutdown request to client.\n")); | ||
491 | return 0; /* client disconnected */ | ||
492 | } | ||
478 | msg = (struct GNUNET_MessageHeader *) buf; | 493 | msg = (struct GNUNET_MessageHeader *) buf; |
479 | msg->type = htons (GNUNET_MESSAGE_TYPE_SHUTDOWN); | 494 | msg->type = htons (GNUNET_MESSAGE_TYPE_SHUTDOWN); |
480 | msg->size = htons (sizeof (struct GNUNET_MessageHeader)); | 495 | msg->size = htons (sizeof (struct GNUNET_MessageHeader)); |
@@ -492,9 +507,9 @@ void | |||
492 | GNUNET_CLIENT_service_shutdown (struct GNUNET_CLIENT_Connection *sock) | 507 | GNUNET_CLIENT_service_shutdown (struct GNUNET_CLIENT_Connection *sock) |
493 | { | 508 | { |
494 | GNUNET_CONNECTION_notify_transmit_ready (sock->sock, | 509 | GNUNET_CONNECTION_notify_transmit_ready (sock->sock, |
495 | sizeof (struct GNUNET_MessageHeader), | 510 | sizeof (struct GNUNET_MessageHeader), |
496 | GNUNET_TIME_UNIT_FOREVER_REL, | 511 | GNUNET_TIME_UNIT_FOREVER_REL, |
497 | &write_shutdown, NULL); | 512 | &write_shutdown, sock); |
498 | } | 513 | } |
499 | 514 | ||
500 | 515 | ||
diff --git a/src/util/test_service.c b/src/util/test_service.c index f615e7eb4..037f6edf7 100644 --- a/src/util/test_service.c +++ b/src/util/test_service.c | |||
@@ -47,7 +47,6 @@ end_it (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
47 | 47 | ||
48 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down service\n"); | 48 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down service\n"); |
49 | GNUNET_CLIENT_service_shutdown (client); | 49 | GNUNET_CLIENT_service_shutdown (client); |
50 | GNUNET_CLIENT_disconnect (client); | ||
51 | if (sctx != NULL) | 50 | if (sctx != NULL) |
52 | GNUNET_SERVICE_stop (sctx); | 51 | GNUNET_SERVICE_stop (sctx); |
53 | } | 52 | } |