/contrib/cvs/src/buffer.h

https://bitbucket.org/freebsd/freebsd-head/ · C++ Header · 168 lines · 76 code · 24 blank · 68 comment · 1 complexity · 89303de6b1b9aa7d61e5b809a19a3210 MD5 · raw file

  1. /*
  2. * Copyright (C) 1996-2005 The Free Software Foundation, Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2, or (at your option)
  7. * any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. */
  14. /* Declarations concerning the buffer data structure. */
  15. #if defined (SERVER_SUPPORT) || defined (CLIENT_SUPPORT)
  16. /*
  17. * We must read data from a child process and send it across the
  18. * network. We do not want to block on writing to the network, so we
  19. * store the data from the child process in memory. A BUFFER
  20. * structure holds the status of one communication, and uses a linked
  21. * list of buffer_data structures to hold data.
  22. */
  23. struct buffer
  24. {
  25. /* Data. */
  26. struct buffer_data *data;
  27. /* Last buffer on data chain. */
  28. struct buffer_data *last;
  29. /* Nonzero if the buffer is in nonblocking mode. */
  30. int nonblocking;
  31. /* Functions must be provided to transfer data in and out of the
  32. buffer. Either the input or output field must be set, but not
  33. both. */
  34. /* Read data into the buffer DATA. There is room for up to SIZE
  35. bytes. In blocking mode, wait until some input, at least NEED
  36. bytes, is available (NEED may be 0 but that is the same as NEED
  37. == 1). In non-blocking mode return immediately no matter how
  38. much input is available; NEED is ignored. Return 0 on success,
  39. or -1 on end of file, or an errno code. Set the number of
  40. bytes read in *GOT.
  41. If there are a nonzero number of bytes available, less than NEED,
  42. followed by end of file, just read those bytes and return 0. */
  43. int (*input) PROTO((void *closure, char *data, int need, int size,
  44. int *got));
  45. /* Write data. This should write up to HAVE bytes from DATA.
  46. This should return 0 on success, or an errno code. It should
  47. set the number of bytes written in *WROTE. */
  48. int (*output) PROTO((void *closure, const char *data, int have,
  49. int *wrote));
  50. /* Flush any data which may be buffered up after previous calls to
  51. OUTPUT. This should return 0 on success, or an errno code. */
  52. int (*flush) PROTO((void *closure));
  53. /* Change the blocking mode of the underlying communication
  54. stream. If BLOCK is non-zero, it should be placed into
  55. blocking mode. Otherwise, it should be placed into
  56. non-blocking mode. This should return 0 on success, or an
  57. errno code. */
  58. int (*block) PROTO ((void *closure, int block));
  59. /* Shut down the communication stream. This does not mean that it
  60. should be closed. It merely means that no more data will be
  61. read or written, and that any final processing that is
  62. appropriate should be done at this point. This may be NULL.
  63. It should return 0 on success, or an errno code. This entry
  64. point exists for the compression code. */
  65. int (*shutdown) PROTO((struct buffer *));
  66. /* This field is passed to the INPUT, OUTPUT, and BLOCK functions. */
  67. void *closure;
  68. /* Function to call if we can't allocate memory. */
  69. void (*memory_error) PROTO((struct buffer *));
  70. };
  71. /* Data is stored in lists of these structures. */
  72. struct buffer_data
  73. {
  74. /* Next buffer in linked list. */
  75. struct buffer_data *next;
  76. /*
  77. * A pointer into the data area pointed to by the text field. This
  78. * is where to find data that has not yet been written out.
  79. */
  80. char *bufp;
  81. /* The number of data bytes found at BUFP. */
  82. int size;
  83. /*
  84. * Actual buffer. This never changes after the structure is
  85. * allocated. The buffer is BUFFER_DATA_SIZE bytes.
  86. */
  87. char *text;
  88. };
  89. /* The size we allocate for each buffer_data structure. */
  90. #define BUFFER_DATA_SIZE (4096)
  91. /* The type of a function passed as a memory error handler. */
  92. typedef void (*BUFMEMERRPROC) PROTO ((struct buffer *));
  93. extern struct buffer *buf_initialize PROTO((int (*) (void *, char *, int,
  94. int, int *),
  95. int (*) (void *, const char *,
  96. int, int *),
  97. int (*) (void *),
  98. int (*) (void *, int),
  99. int (*) (struct buffer *),
  100. void (*) (struct buffer *),
  101. void *));
  102. extern void buf_free PROTO((struct buffer *));
  103. extern struct buffer *buf_nonio_initialize PROTO((void (*) (struct buffer *)));
  104. extern struct buffer *stdio_buffer_initialize
  105. PROTO((FILE *, int, int, void (*) (struct buffer *)));
  106. extern FILE *stdio_buffer_get_file PROTO((struct buffer *));
  107. extern struct buffer *compress_buffer_initialize
  108. PROTO((struct buffer *, int, int, void (*) (struct buffer *)));
  109. extern struct buffer *packetizing_buffer_initialize
  110. PROTO((struct buffer *, int (*) (void *, const char *, char *, int),
  111. int (*) (void *, const char *, char *, int, int *), void *,
  112. void (*) (struct buffer *)));
  113. extern int buf_empty PROTO((struct buffer *));
  114. extern int buf_empty_p PROTO((struct buffer *));
  115. extern void buf_output PROTO((struct buffer *, const char *, int));
  116. extern void buf_output0 PROTO((struct buffer *, const char *));
  117. extern void buf_append_char PROTO((struct buffer *, int));
  118. extern int buf_send_output PROTO((struct buffer *));
  119. extern int buf_flush PROTO((struct buffer *, int));
  120. extern int set_nonblock PROTO((struct buffer *));
  121. extern int set_block PROTO((struct buffer *));
  122. extern int buf_send_counted PROTO((struct buffer *));
  123. extern int buf_send_special_count PROTO((struct buffer *, int));
  124. extern void buf_append_data PROTO((struct buffer *,
  125. struct buffer_data *,
  126. struct buffer_data *));
  127. extern void buf_append_buffer PROTO((struct buffer *, struct buffer *));
  128. extern int buf_read_file PROTO((FILE *, long, struct buffer_data **,
  129. struct buffer_data **));
  130. extern int buf_read_file_to_eof PROTO((FILE *, struct buffer_data **,
  131. struct buffer_data **));
  132. extern int buf_input_data PROTO((struct buffer *, int *));
  133. extern int buf_read_line PROTO((struct buffer *, char **, int *));
  134. extern int buf_read_data PROTO((struct buffer *, int, char **, int *));
  135. extern void buf_copy_lines PROTO((struct buffer *, struct buffer *, int));
  136. extern int buf_copy_counted PROTO((struct buffer *, struct buffer *, int *));
  137. extern int buf_chain_length PROTO((struct buffer_data *));
  138. extern int buf_length PROTO((struct buffer *));
  139. extern int buf_shutdown PROTO((struct buffer *));
  140. #ifdef SERVER_FLOWCONTROL
  141. extern int buf_count_mem PROTO((struct buffer *));
  142. #endif /* SERVER_FLOWCONTROL */
  143. #endif /* defined (SERVER_SUPPORT) || defined (CLIENT_SUPPORT) */