buffer.h revision 107484
1/* Declarations concerning the buffer data structure. */ 2 3#if defined (SERVER_SUPPORT) || defined (CLIENT_SUPPORT) 4 5/* 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. 11 */ 12 13struct buffer 14{ 15 /* Data. */ 16 struct buffer_data *data; 17 18 /* Last buffer on data chain. */ 19 struct buffer_data *last; 20 21 /* Nonzero if the buffer is in nonblocking mode. */ 22 int nonblocking; 23 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 26 both. */ 27 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 34 bytes read in *GOT. 35 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) PROTO((void *closure, char *data, int need, int size, 39 int *got)); 40 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) PROTO((void *closure, const char *data, int have, 45 int *wrote)); 46 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) PROTO((void *closure)); 50 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 55 errno code. */ 56 int (*block) PROTO ((void *closure, int block)); 57 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) PROTO((struct buffer *)); 65 66 /* This field is passed to the INPUT, OUTPUT, and BLOCK functions. */ 67 void *closure; 68 69 /* Function to call if we can't allocate memory. */ 70 void (*memory_error) PROTO((struct buffer *)); 71}; 72 73/* Data is stored in lists of these structures. */ 74 75struct buffer_data 76{ 77 /* Next buffer in linked list. */ 78 struct buffer_data *next; 79 80 /* 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. 83 */ 84 char *bufp; 85 86 /* The number of data bytes found at BUFP. */ 87 int size; 88 89 /* 90 * Actual buffer. This never changes after the structure is 91 * allocated. The buffer is BUFFER_DATA_SIZE bytes. 92 */ 93 char *text; 94}; 95 96/* The size we allocate for each buffer_data structure. */ 97#define BUFFER_DATA_SIZE (4096) 98 99/* The type of a function passed as a memory error handler. */ 100typedef void (*BUFMEMERRPROC) PROTO ((struct buffer *)); 101 102extern struct buffer *buf_initialize PROTO((int (*) (void *, char *, int, 103 int, int *), 104 int (*) (void *, const char *, 105 int, int *), 106 int (*) (void *), 107 int (*) (void *, int), 108 int (*) (struct buffer *), 109 void (*) (struct buffer *), 110 void *)); 111extern void buf_free PROTO((struct buffer *)); 112extern struct buffer *buf_nonio_initialize PROTO((void (*) (struct buffer *))); 113extern struct buffer *stdio_buffer_initialize 114 PROTO((FILE *, int, int, void (*) (struct buffer *))); 115extern FILE *stdio_buffer_get_file PROTO((struct buffer *)); 116extern struct buffer *compress_buffer_initialize 117 PROTO((struct buffer *, int, int, void (*) (struct buffer *))); 118extern struct buffer *packetizing_buffer_initialize 119 PROTO((struct buffer *, int (*) (void *, const char *, char *, int), 120 int (*) (void *, const char *, char *, int, int *), void *, 121 void (*) (struct buffer *))); 122extern int buf_empty_p PROTO((struct buffer *)); 123extern void buf_output PROTO((struct buffer *, const char *, int)); 124extern void buf_output0 PROTO((struct buffer *, const char *)); 125extern void buf_append_char PROTO((struct buffer *, int)); 126extern int buf_send_output PROTO((struct buffer *)); 127extern int buf_flush PROTO((struct buffer *, int)); 128extern int set_nonblock PROTO((struct buffer *)); 129extern int set_block PROTO((struct buffer *)); 130extern int buf_send_counted PROTO((struct buffer *)); 131extern int buf_send_special_count PROTO((struct buffer *, int)); 132extern void buf_append_data PROTO((struct buffer *, 133 struct buffer_data *, 134 struct buffer_data *)); 135extern void buf_append_buffer PROTO((struct buffer *, struct buffer *)); 136extern int buf_read_file PROTO((FILE *, long, struct buffer_data **, 137 struct buffer_data **)); 138extern int buf_read_file_to_eof PROTO((FILE *, struct buffer_data **, 139 struct buffer_data **)); 140extern int buf_input_data PROTO((struct buffer *, int *)); 141extern int buf_read_line PROTO((struct buffer *, char **, int *)); 142extern int buf_read_data PROTO((struct buffer *, int, char **, int *)); 143extern void buf_copy_lines PROTO((struct buffer *, struct buffer *, int)); 144extern int buf_copy_counted PROTO((struct buffer *, struct buffer *, int *)); 145extern int buf_chain_length PROTO((struct buffer_data *)); 146extern int buf_length PROTO((struct buffer *)); 147extern int buf_shutdown PROTO((struct buffer *)); 148 149#ifdef SERVER_FLOWCONTROL 150extern int buf_count_mem PROTO((struct buffer *)); 151#endif /* SERVER_FLOWCONTROL */ 152 153#endif /* defined (SERVER_SUPPORT) || defined (CLIENT_SUPPORT) */ 154