BIPCServer.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /**
  2. * @file BIPCServer.h
  3. * @author Ambroz Bizjak <ambrop7@gmail.com>
  4. *
  5. * @section LICENSE
  6. *
  7. * This file is part of BadVPN.
  8. *
  9. * BadVPN is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2
  11. * as published by the Free Software Foundation.
  12. *
  13. * BadVPN is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. *
  22. * @section DESCRIPTION
  23. *
  24. * Server part of {@link BIPC}, an abstraction of a reliable, sequenced,
  25. * message-oriented two-way IPC.
  26. */
  27. #ifndef BADVPN_IPC_BIPCSERVER_H
  28. #define BADVPN_IPC_BIPCSERVER_H
  29. #include <misc/debug.h>
  30. #include <misc/dead.h>
  31. #include <system/BSocket.h>
  32. #include <system/Listener.h>
  33. #include <system/DebugObject.h>
  34. /**
  35. * Handler function called when a client may be accepted
  36. * (using {@link BIPC_InitAccept}).
  37. *
  38. * @param user as in {@link BIPCServer_Init}
  39. */
  40. typedef void (*BIPCServer_handler) (void *user);
  41. /**
  42. * Server part of {@link BIPC}, an abstraction of a reliable, sequenced,
  43. * message-oriented two-way IPC.
  44. */
  45. typedef struct {
  46. BSocket sock;
  47. Listener listener;
  48. BIPCServer_handler handler;
  49. void *user;
  50. DebugObject d_obj;
  51. } BIPCServer;
  52. /**
  53. * Initializes the object.
  54. *
  55. * @param o the object
  56. * @param path path of the IPC object. On *nix path of the unix socket, on Windows
  57. * path of the named pipe.
  58. * @param handler handler function called when a client may be accepted
  59. * (using {@link BIPC_InitAccept})
  60. * @param user value to pass to handler function
  61. * @param reactor reactor we live in
  62. * @return 1 on success, 0 on failure
  63. */
  64. int BIPCServer_Init (BIPCServer *o, const char *path, BIPCServer_handler handler, void *user, BReactor *reactor) WARN_UNUSED;
  65. /**
  66. * Frees the object.
  67. *
  68. * @param o the object
  69. */
  70. void BIPCServer_Free (BIPCServer *o);
  71. #endif