1 /* Declarations concerning the buffer data structure. */
3 #if defined (SERVER_SUPPORT) || defined (CLIENT_SUPPORT)
6 * We must read data from a child process and send it across the
7 * network. We do not want to block on writing to the network, so we
8 * store the data from the child process in memory. A BUFFER
9 * structure holds the status of one communication, and uses a linked
10 * list of buffer_data structures to hold data.
16 struct buffer_data *data;
18 /* Last buffer on data chain. */
19 struct buffer_data *last;
21 /* Nonzero if the buffer is in nonblocking mode. */
24 /* Functions must be provided to transfer data in and out of the
25 buffer. Either the input or output field must be set, but not
28 /* Read data into the buffer DATA. There is room for up to SIZE
29 bytes. In blocking mode, wait until some input, at least NEED
30 bytes, is available (NEED may be 0 but that is the same as NEED
31 == 1). In non-blocking mode return immediately no matter how
32 much input is available; NEED is ignored. Return 0 on success,
33 or -1 on end of file, or an errno code. Set the number of
36 If there are a nonzero number of bytes available, less than NEED,
37 followed by end of file, just read those bytes and return 0. */
38 int (*input) (void *closure, char *data, int need, int size,
41 /* Write data. This should write up to HAVE bytes from DATA.
42 This should return 0 on success, or an errno code. It should
43 set the number of bytes written in *WROTE. */
44 int (*output) (void *closure, const char *data, int have,
47 /* Flush any data which may be buffered up after previous calls to
48 OUTPUT. This should return 0 on success, or an errno code. */
49 int (*flush) (void *closure);
51 /* Change the blocking mode of the underlying communication
52 stream. If BLOCK is non-zero, it should be placed into
53 blocking mode. Otherwise, it should be placed into
54 non-blocking mode. This should return 0 on success, or an
56 int (*block) (void *closure, int block);
58 /* Shut down the communication stream. This does not mean that it
59 should be closed. It merely means that no more data will be
60 read or written, and that any final processing that is
61 appropriate should be done at this point. This may be NULL.
62 It should return 0 on success, or an errno code. This entry
63 point exists for the compression code. */
64 int (*shutdown) (struct buffer *);
66 /* This field is passed to the INPUT, OUTPUT, and BLOCK functions. */
69 /* Function to call if we can't allocate memory. */
70 void (*memory_error) (struct buffer *);
73 /* Data is stored in lists of these structures. */
77 /* Next buffer in linked list. */
78 struct buffer_data *next;
81 * A pointer into the data area pointed to by the text field. This
82 * is where to find data that has not yet been written out.
86 /* The number of data bytes found at BUFP. */
90 * Actual buffer. This never changes after the structure is
91 * allocated. The buffer is BUFFER_DATA_SIZE bytes.
96 /* The size we allocate for each buffer_data structure. */
97 #define BUFFER_DATA_SIZE (4096)
99 /* The type of a function passed as a memory error handler. */
100 typedef void (*BUFMEMERRPROC) (struct buffer *);
102 extern struct buffer *buf_initialize (int (*) (void *, char *, int,
104 int (*) (void *, const char *,
107 int (*) (void *, int),
108 int (*) (struct buffer *),
109 void (*) (struct buffer *),
111 extern void buf_free (struct buffer *);
112 extern struct buffer *buf_nonio_initialize (void (*) (struct buffer *));
113 extern struct buffer *stdio_buffer_initialize
114 (FILE *, int, int, void (*) (struct buffer *));
115 extern FILE *stdio_buffer_get_file (struct buffer *);
116 extern struct buffer *compress_buffer_initialize
117 (struct buffer *, int, int, void (*) (struct buffer *));
118 extern struct buffer *packetizing_buffer_initialize
119 (struct buffer *, int (*) (void *, const char *, char *, int),
120 int (*) (void *, const char *, char *, int, int *), void *,
121 void (*) (struct buffer *));
122 extern int buf_empty (struct buffer *);
123 extern int buf_empty_p (struct buffer *);
124 extern void buf_output (struct buffer *, const char *, int);
125 extern void buf_output0 (struct buffer *, const char *);
126 extern void buf_append_char (struct buffer *, int);
127 extern int buf_send_output (struct buffer *);
128 extern int buf_flush (struct buffer *, int);
129 extern int set_nonblock (struct buffer *);
130 extern int set_block (struct buffer *);
131 extern int buf_send_counted (struct buffer *);
132 extern int buf_send_special_count (struct buffer *, int);
133 extern void buf_append_data (struct buffer *,
134 struct buffer_data *,
135 struct buffer_data *);
136 extern void buf_append_buffer (struct buffer *, struct buffer *);
137 extern int buf_read_file (FILE *, long, struct buffer_data **,
138 struct buffer_data **);
139 extern int buf_read_file_to_eof (FILE *, struct buffer_data **,
140 struct buffer_data **);
141 extern int buf_input_data (struct buffer *, int *);
142 extern int buf_read_line (struct buffer *, char **, int *);
143 extern int buf_read_data (struct buffer *, int, char **, int *);
144 extern void buf_copy_lines (struct buffer *, struct buffer *, int);
145 extern int buf_copy_counted (struct buffer *, struct buffer *, int *);
146 extern int buf_chain_length (struct buffer_data *);
147 extern int buf_length (struct buffer *);
148 extern int buf_shutdown (struct buffer *);
150 #ifdef SERVER_FLOWCONTROL
151 extern int buf_count_mem (struct buffer *);
152 #endif /* SERVER_FLOWCONTROL */
154 #endif /* defined (SERVER_SUPPORT) || defined (CLIENT_SUPPORT) */