150bf276cStholo /* Declarations concerning the buffer data structure. */ 250bf276cStholo 350bf276cStholo #if defined (SERVER_SUPPORT) || defined (CLIENT_SUPPORT) 450bf276cStholo 550bf276cStholo /* 650bf276cStholo * We must read data from a child process and send it across the 750bf276cStholo * network. We do not want to block on writing to the network, so we 850bf276cStholo * store the data from the child process in memory. A BUFFER 950bf276cStholo * structure holds the status of one communication, and uses a linked 1050bf276cStholo * list of buffer_data structures to hold data. 1150bf276cStholo */ 1250bf276cStholo 1350bf276cStholo struct buffer 1450bf276cStholo { 1550bf276cStholo /* Data. */ 1650bf276cStholo struct buffer_data *data; 1750bf276cStholo 1850bf276cStholo /* Last buffer on data chain. */ 1950bf276cStholo struct buffer_data *last; 2050bf276cStholo 2150bf276cStholo /* Nonzero if the buffer is in nonblocking mode. */ 2250bf276cStholo int nonblocking; 2350bf276cStholo 2450bf276cStholo /* Functions must be provided to transfer data in and out of the 2550bf276cStholo buffer. Either the input or output field must be set, but not 2650bf276cStholo both. */ 2750bf276cStholo 2850bf276cStholo /* Read data into the buffer DATA. There is room for up to SIZE 29461cc63eStholo bytes. In blocking mode, wait until some input, at least NEED 30461cc63eStholo bytes, is available (NEED may be 0 but that is the same as NEED 31461cc63eStholo == 1). In non-blocking mode return immediately no matter how 32461cc63eStholo much input is available; NEED is ignored. Return 0 on success, 33461cc63eStholo or -1 on end of file, or an errno code. Set the number of 34461cc63eStholo bytes read in *GOT. 35461cc63eStholo 36461cc63eStholo If there are a nonzero number of bytes available, less than NEED, 37461cc63eStholo followed by end of file, just read those bytes and return 0. */ 3850bf276cStholo int (*input) PROTO((void *closure, char *data, int need, int size, 3950bf276cStholo int *got)); 4050bf276cStholo 4150bf276cStholo /* Write data. This should write up to HAVE bytes from DATA. 4250bf276cStholo This should return 0 on success, or an errno code. It should 4350bf276cStholo set the number of bytes written in *WROTE. */ 4450bf276cStholo int (*output) PROTO((void *closure, const char *data, int have, 4550bf276cStholo int *wrote)); 4650bf276cStholo 4750bf276cStholo /* Flush any data which may be buffered up after previous calls to 4850bf276cStholo OUTPUT. This should return 0 on success, or an errno code. */ 4950bf276cStholo int (*flush) PROTO((void *closure)); 5050bf276cStholo 5150bf276cStholo /* Change the blocking mode of the underlying communication 5250bf276cStholo stream. If BLOCK is non-zero, it should be placed into 5350bf276cStholo blocking mode. Otherwise, it should be placed into 5450bf276cStholo non-blocking mode. This should return 0 on success, or an 5550bf276cStholo errno code. */ 5650bf276cStholo int (*block) PROTO ((void *closure, int block)); 5750bf276cStholo 5850bf276cStholo /* Shut down the communication stream. This does not mean that it 5950bf276cStholo should be closed. It merely means that no more data will be 6050bf276cStholo read or written, and that any final processing that is 6150bf276cStholo appropriate should be done at this point. This may be NULL. 6250bf276cStholo It should return 0 on success, or an errno code. This entry 6350bf276cStholo point exists for the compression code. */ 6450bf276cStholo int (*shutdown) PROTO((void *closure)); 6550bf276cStholo 6650bf276cStholo /* This field is passed to the INPUT, OUTPUT, and BLOCK functions. */ 6750bf276cStholo void *closure; 6850bf276cStholo 6950bf276cStholo /* Function to call if we can't allocate memory. */ 7050bf276cStholo void (*memory_error) PROTO((struct buffer *)); 7150bf276cStholo }; 7250bf276cStholo 7350bf276cStholo /* Data is stored in lists of these structures. */ 7450bf276cStholo 7550bf276cStholo struct buffer_data 7650bf276cStholo { 7750bf276cStholo /* Next buffer in linked list. */ 7850bf276cStholo struct buffer_data *next; 7950bf276cStholo 8050bf276cStholo /* 8150bf276cStholo * A pointer into the data area pointed to by the text field. This 8250bf276cStholo * is where to find data that has not yet been written out. 8350bf276cStholo */ 8450bf276cStholo char *bufp; 8550bf276cStholo 8650bf276cStholo /* The number of data bytes found at BUFP. */ 8750bf276cStholo int size; 8850bf276cStholo 8950bf276cStholo /* 9050bf276cStholo * Actual buffer. This never changes after the structure is 9150bf276cStholo * allocated. The buffer is BUFFER_DATA_SIZE bytes. 9250bf276cStholo */ 9350bf276cStholo char *text; 9450bf276cStholo }; 9550bf276cStholo 9650bf276cStholo /* The size we allocate for each buffer_data structure. */ 9750bf276cStholo #define BUFFER_DATA_SIZE (4096) 9850bf276cStholo 99*5e617892Stholo /* The type of a function passed as a memory error handler. */ 100*5e617892Stholo typedef void (*BUFMEMERRPROC) PROTO ((struct buffer *)); 101*5e617892Stholo 10250bf276cStholo extern struct buffer *buf_initialize PROTO((int (*) (void *, char *, int, 10350bf276cStholo int, int *), 10450bf276cStholo int (*) (void *, const char *, 10550bf276cStholo int, int *), 10650bf276cStholo int (*) (void *), 10750bf276cStholo int (*) (void *, int), 10850bf276cStholo int (*) (void *), 10950bf276cStholo void (*) (struct buffer *), 11050bf276cStholo void *)); 111*5e617892Stholo extern void buf_free PROTO((struct buffer *)); 11250bf276cStholo extern struct buffer *buf_nonio_initialize PROTO((void (*) (struct buffer *))); 11350bf276cStholo extern struct buffer *stdio_buffer_initialize 11450bf276cStholo PROTO((FILE *, int, void (*) (struct buffer *))); 11550bf276cStholo extern struct buffer *compress_buffer_initialize 11650bf276cStholo PROTO((struct buffer *, int, int, void (*) (struct buffer *))); 1172286d8edStholo extern struct buffer *packetizing_buffer_initialize 1182286d8edStholo PROTO((struct buffer *, int (*) (void *, const char *, char *, int), 1192286d8edStholo int (*) (void *, const char *, char *, int, int *), void *, 1202286d8edStholo void (*) (struct buffer *))); 12150bf276cStholo extern int buf_empty_p PROTO((struct buffer *)); 12250bf276cStholo extern void buf_output PROTO((struct buffer *, const char *, int)); 12350bf276cStholo extern void buf_output0 PROTO((struct buffer *, const char *)); 12450bf276cStholo extern void buf_append_char PROTO((struct buffer *, int)); 12550bf276cStholo extern int buf_send_output PROTO((struct buffer *)); 12650bf276cStholo extern int buf_flush PROTO((struct buffer *, int)); 12750bf276cStholo extern int set_nonblock PROTO((struct buffer *)); 12850bf276cStholo extern int set_block PROTO((struct buffer *)); 12950bf276cStholo extern int buf_send_counted PROTO((struct buffer *)); 13050bf276cStholo extern int buf_send_special_count PROTO((struct buffer *, int)); 13150bf276cStholo extern void buf_append_data PROTO((struct buffer *, 13250bf276cStholo struct buffer_data *, 13350bf276cStholo struct buffer_data *)); 134*5e617892Stholo extern void buf_append_buffer PROTO((struct buffer *, struct buffer *)); 13550bf276cStholo extern int buf_read_file PROTO((FILE *, long, struct buffer_data **, 13650bf276cStholo struct buffer_data **)); 13750bf276cStholo extern int buf_read_file_to_eof PROTO((FILE *, struct buffer_data **, 13850bf276cStholo struct buffer_data **)); 13950bf276cStholo extern int buf_input_data PROTO((struct buffer *, int *)); 14050bf276cStholo extern int buf_read_line PROTO((struct buffer *, char **, int *)); 14150bf276cStholo extern int buf_read_data PROTO((struct buffer *, int, char **, int *)); 14250bf276cStholo extern void buf_copy_lines PROTO((struct buffer *, struct buffer *, int)); 14350bf276cStholo extern int buf_copy_counted PROTO((struct buffer *, struct buffer *, int *)); 14450bf276cStholo extern int buf_chain_length PROTO((struct buffer_data *)); 145*5e617892Stholo extern int buf_length PROTO((struct buffer *)); 14650bf276cStholo extern int buf_shutdown PROTO((struct buffer *)); 14750bf276cStholo 14850bf276cStholo #ifdef SERVER_FLOWCONTROL 14950bf276cStholo extern int buf_count_mem PROTO((struct buffer *)); 15050bf276cStholo #endif /* SERVER_FLOWCONTROL */ 15150bf276cStholo 15250bf276cStholo #endif /* defined (SERVER_SUPPORT) || defined (CLIENT_SUPPORT) */ 153