mockup-service.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2007, 2008, 2009 Christian Grothoff (and other contributing authors)
  4. GNUnet is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published
  6. by the Free Software Foundation; either version 3, or (at your
  7. option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNUnet; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  15. Boston, MA 02111-1307, USA.
  16. */
  17. #include <stdlib.h>
  18. #include "platform.h"
  19. #include "gnunet_util_lib.h"
  20. #include "gnunet_protocols.h"
  21. static int special_ret = 0;
  22. /**
  23. * Handler for STOP message.
  24. *
  25. * @param cls closure (refers to service)
  26. * @param client identification of the client
  27. * @param message the actual message
  28. */
  29. static void
  30. handle_stop (void *cls, struct GNUNET_SERVER_Client *client,
  31. const struct GNUNET_MessageHeader *message)
  32. {
  33. GNUNET_log (GNUNET_ERROR_TYPE_INFO,
  34. _("Initiating shutdown as requested by client.\n"));
  35. GNUNET_SERVER_client_persist_ (client);
  36. GNUNET_SCHEDULER_shutdown ();
  37. /* ARM won't exponentially increase restart delay if we
  38. * terminate normally. This changes the return code.
  39. */
  40. special_ret = 1;
  41. }
  42. static void
  43. run (void *cls, struct GNUNET_SERVER_Handle *server,
  44. const struct GNUNET_CONFIGURATION_Handle *cfg)
  45. {
  46. static const struct GNUNET_SERVER_MessageHandler handlers[] = {
  47. {&handle_stop, NULL, GNUNET_MESSAGE_TYPE_ARM_STOP,
  48. sizeof (struct GNUNET_MessageHeader)},
  49. {NULL, NULL, 0, 0}
  50. };
  51. /* process client requests */
  52. GNUNET_SERVER_add_handlers (server, handlers);
  53. }
  54. int
  55. main (int argc, char *const *argv)
  56. {
  57. int ret;
  58. ret =
  59. (GNUNET_OK ==
  60. GNUNET_SERVICE_run (argc, argv, "do-nothing", GNUNET_SERVICE_OPTION_NONE,
  61. &run, NULL)) ? 0 : 1;
  62. if (0 != special_ret)
  63. return special_ret;
  64. return ret;
  65. }