BIPCServer.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 <system/BSocket.h>
  31. #include <system/Listener.h>
  32. #include <system/DebugObject.h>
  33. /**
  34. * Handler function called when a client may be accepted
  35. * (using {@link BIPC_InitAccept}).
  36. *
  37. * @param user as in {@link BIPCServer_Init}
  38. */
  39. typedef void (*BIPCServer_handler) (void *user);
  40. /**
  41. * Server part of {@link BIPC}, an abstraction of a reliable, sequenced,
  42. * message-oriented two-way IPC.
  43. */
  44. typedef struct {
  45. BSocket sock;
  46. Listener listener;
  47. BIPCServer_handler handler;
  48. void *user;
  49. DebugObject d_obj;
  50. } BIPCServer;
  51. /**
  52. * Initializes the object.
  53. *
  54. * @param o the object
  55. * @param path path of the IPC object. On *nix path of the unix socket, on Windows
  56. * path of the named pipe.
  57. * @param handler handler function called when a client may be accepted
  58. * (using {@link BIPC_InitAccept})
  59. * @param user value to pass to handler function
  60. * @param reactor reactor we live in
  61. * @return 1 on success, 0 on failure
  62. */
  63. int BIPCServer_Init (BIPCServer *o, const char *path, BIPCServer_handler handler, void *user, BReactor *reactor) WARN_UNUSED;
  64. /**
  65. * Frees the object.
  66. *
  67. * @param o the object
  68. */
  69. void BIPCServer_Free (BIPCServer *o);
  70. #endif