pipe.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * pipe.h
  3. *
  4. * Copyright (C) 2013 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as
  8. * published by the Free Software Foundation, either version 3 of the
  9. * License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef _PIPE_H_
  20. #define _PIPE_H_
  21. #include <lock.h>
  22. #include <object.h>
  23. #include <sdk/pipe.h>
  24. #include <thread.h>
  25. #define PIPE_BLOCK_SIZE 1024
  26. #define MAX_PIPE_BLOCKS 1024
  27. #define PIPE_MESSAGE (1 << 0)
  28. enum
  29. {
  30. PIPELINE_IDLE,
  31. PIPELINE_ACCEPTING,
  32. PIPELINE_CONNECTING,
  33. PIPELINE_FAILED,
  34. };
  35. typedef struct
  36. {
  37. object_t header;
  38. dword_t flags;
  39. lock_t lock;
  40. dword_t bytes_ready;
  41. list_entry_t fifo;
  42. } pipe_t;
  43. typedef struct
  44. {
  45. list_entry_t link;
  46. dword_t start, end;
  47. bool_t full;
  48. byte_t data[PIPE_BLOCK_SIZE];
  49. } pipe_fifo_entry_t;
  50. typedef struct
  51. {
  52. list_entry_t link;
  53. size_t size;
  54. byte_t data[VARIABLE_SIZE];
  55. } pipe_message_entry_t;
  56. typedef struct
  57. {
  58. object_t header;
  59. dword_t flags;
  60. lock_t lock;
  61. uintptr_t status;
  62. dword_t master_pid;
  63. dword_t slave_pid;
  64. pipe_t *request_pipe;
  65. pipe_t *response_pipe;
  66. dword_t last_error;
  67. } pipeline_t;
  68. static inline void init_pipe(pipe_t *pipe, dword_t flags)
  69. {
  70. pipe->flags = flags;
  71. lock_init(&pipe->lock);
  72. list_init(&pipe->fifo);
  73. }
  74. dword_t read_pipe(pipe_t *pipe, void *buffer, size_t *size, dword_t timeout);
  75. dword_t write_pipe(pipe_t *pipe, const void *buffer, size_t size);
  76. void pipe_cleanup(object_t *obj);
  77. dword_t pipe_pre_wait(object_t *obj, void *parameter, wait_condition_t *condition);
  78. #endif