BIPCServer.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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_SYSTEM_BIPCSERVER_H
  28. #define BADVPN_SYSTEM_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. dead_t dead;
  47. BSocket sock;
  48. Listener listener;
  49. BIPCServer_handler handler;
  50. void *user;
  51. DebugObject d_obj;
  52. } BIPCServer;
  53. /**
  54. * Initializes the object.
  55. *
  56. * @param o the object
  57. * @param path path of the IPC object. On *nix path of the unix socket, on Windows
  58. * path of the named pipe.
  59. * @param handler handler function called when a client may be accepted
  60. * (using {@link BIPC_InitAccept})
  61. * @param user value to pass to handler function
  62. * @param reactor reactor we live in
  63. * @return 1 on success, 0 on failure
  64. */
  65. int BIPCServer_Init (BIPCServer *o, const char *path, BIPCServer_handler handler, void *user, BReactor *reactor) WARN_UNUSED;
  66. /**
  67. * Frees the object.
  68. *
  69. * @param o the object
  70. */
  71. void BIPCServer_Free (BIPCServer *o);
  72. #endif