BIPC.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /**
  2. * @file BIPC.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. * An abstraction of a reliable, sequenced, message-oriented two-way IPC.
  25. * Uses unix sockets on *nix systems, and named pipes on Windows.
  26. */
  27. #ifndef BADVPN_SYSTEM_BIPC_H
  28. #define BADVPN_SYSTEM_BIPC_H
  29. #include <misc/debug.h>
  30. #include <misc/dead.h>
  31. #include <system/BSocket.h>
  32. #include <system/DebugObject.h>
  33. #include <system/BIPCServer.h>
  34. #include <flow/SeqPacketSocketSink.h>
  35. #include <flow/SeqPacketSocketSource.h>
  36. /**
  37. * Handler function called when an error occurs.
  38. * The object must be freed from within this handler.
  39. *
  40. * @param user as in {@link BIPC_InitConnect}
  41. */
  42. typedef void (*BIPC_handler) (void *user);
  43. /**
  44. * An abstraction of a reliable, sequenced, message-oriented two-way IPC.
  45. */
  46. typedef struct {
  47. dead_t dead;
  48. BSocket sock;
  49. FlowErrorDomain domain;
  50. SeqPacketSocketSink sink;
  51. SeqPacketSocketSource source;
  52. BIPC_handler handler;
  53. void *user;
  54. DebugObject d_obj;
  55. } BIPC;
  56. /**
  57. * Initializes the object by connecting to an IPC server.
  58. *
  59. * @param o the object
  60. * @param path path of the IPC object. On *nix path of the unix socket, on Windows
  61. * path of the named pipe.
  62. * @param send_mtu maximum packet size for sending. Must be >=0.
  63. * @param recv_mtu maximum packet size for receiving. Must be >=0.
  64. * @param handler handler function called when an error occurs
  65. * @param user value to pass to handler function
  66. * @param reactor reactor we live in
  67. * @return 1 on success, 0 on failure
  68. */
  69. int BIPC_InitConnect (BIPC *o, const char *path, int send_mtu, int recv_mtu, BIPC_handler handler, void *user, BReactor *reactor) WARN_UNUSED;
  70. /**
  71. * Initializes the object by acception a connection on an IPC server.
  72. *
  73. * @param o the object
  74. * @param server IPC server to accept a connection on
  75. * @param send_mtu maximum packet size for sending. Must be >=0.
  76. * @param recv_mtu maximum packet size for receiving. Must be >=0.
  77. * @param handler handler function called when an error occurs
  78. * @param user value to pass to handler function
  79. * @return 1 on success, 0 on failure
  80. */
  81. int BIPC_InitAccept (BIPC *o, BIPCServer *server, int send_mtu, int recv_mtu, BIPC_handler handler, void *user) WARN_UNUSED;
  82. /**
  83. * Frees the object.
  84. *
  85. * @param o the object
  86. */
  87. void BIPC_Free (BIPC *o);
  88. /**
  89. * Returns the interface for sending.
  90. * The MTU of the interface will be as send_mtu in {@link BIPC_InitConnect}.
  91. *
  92. * @param o the object
  93. * @return interface for sending
  94. */
  95. PacketPassInterface * BIPC_GetSendInterface (BIPC *o);
  96. /**
  97. * Returns the interface for receiving.
  98. * The MTU of the interface will be as recv_mtu in {@link BIPC_InitConnect}.
  99. *
  100. * @param o the object
  101. * @return interface for receiving
  102. */
  103. PacketRecvInterface * BIPC_GetRecvInterface (BIPC *o);
  104. #endif