Pipe.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* vim: set expandtab ts=4 sw=4: */
  2. /*
  3. * You may redistribute this program and/or modify it under the terms of
  4. * the GNU General Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. */
  15. #ifndef Pipe_H
  16. #define Pipe_H
  17. #include "memory/Allocator.h"
  18. #include "exception/Except.h"
  19. #include "interface/Iface.h"
  20. #include "util/events/EventBase.h"
  21. #include "util/Linker.h"
  22. Linker_require("util/events/libuv/Pipe.c");
  23. #include <stdbool.h>
  24. struct Pipe;
  25. typedef void (* Pipe_callback)(struct Pipe* p, int status);
  26. struct Pipe
  27. {
  28. struct Iface iface;
  29. /** the name as provided by the user eg: "foo" */
  30. const char* const name;
  31. /** The name of the file eg: "/tmp/cjdns_pipe_foo" */
  32. const char* const fullName;
  33. /** A pointer to the platform dependent file descriptor or handle. */
  34. void* fd;
  35. void* userData;
  36. struct EventBase* const base;
  37. Pipe_callback onConnection;
  38. Pipe_callback onClose;
  39. struct Log* logger;
  40. };
  41. #define Pipe_PADDING_AMOUNT 512
  42. #define Pipe_BUFFER_CAP 4000
  43. #ifndef Pipe_PATH
  44. #ifdef win32
  45. #define Pipe_PATH "\\\\.\\pipe"
  46. #elif defined(android)
  47. #define Pipe_PATH "/data/local/tmp"
  48. #else
  49. #define Pipe_PATH "/tmp"
  50. #endif
  51. #endif
  52. struct Pipe* Pipe_named(const char* path,
  53. const char* name,
  54. struct EventBase* eb,
  55. struct Except* eh,
  56. struct Allocator* userAlloc);
  57. struct Pipe* Pipe_namedConnect(const char* fullPath,
  58. bool attemptToCreate,
  59. struct EventBase* eb,
  60. struct Except* eh,
  61. struct Allocator* userAlloc);
  62. struct Pipe* Pipe_forFiles(int inFd,
  63. int outFd,
  64. struct EventBase* eb,
  65. struct Except* eh,
  66. struct Allocator* userAlloc);
  67. #endif