home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / cvs-1.8.7-src.tgz / tar.out / fsf / cvs / src / buffer.h < prev    next >
C/C++ Source or Header  |  1996-09-28  |  5KB  |  137 lines

  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.  
  13. struct 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.  At least NEED bytes must be read (NEED may be 0).  This
  30.        should return 0 on success, or -1 on end of file, or an errno
  31.        code.  It should set the number of bytes read in *GOT.  */
  32.     int (*input) PROTO((void *closure, char *data, int need, int size,
  33.             int *got));
  34.  
  35.     /* Write data.  This should write up to HAVE bytes from DATA.
  36.        This should return 0 on success, or an errno code.  It should
  37.        set the number of bytes written in *WROTE.  */
  38.     int (*output) PROTO((void *closure, const char *data, int have,
  39.              int *wrote));
  40.  
  41.     /* Flush any data which may be buffered up after previous calls to
  42.        OUTPUT.  This should return 0 on success, or an errno code.  */
  43.     int (*flush) PROTO((void *closure));
  44.  
  45.     /* Change the blocking mode of the underlying communication
  46.        stream.  If BLOCK is non-zero, it should be placed into
  47.        blocking mode.  Otherwise, it should be placed into
  48.        non-blocking mode.  This should return 0 on success, or an
  49.        errno code.  */
  50.     int (*block) PROTO ((void *closure, int block));
  51.  
  52.     /* Shut down the communication stream.  This does not mean that it
  53.        should be closed.  It merely means that no more data will be
  54.        read or written, and that any final processing that is
  55.        appropriate should be done at this point.  This may be NULL.
  56.        It should return 0 on success, or an errno code.  This entry
  57.        point exists for the compression code.  */
  58.     int (*shutdown) PROTO((void *closure));
  59.  
  60.     /* This field is passed to the INPUT, OUTPUT, and BLOCK functions.  */
  61.     void *closure;
  62.  
  63.     /* Function to call if we can't allocate memory.  */
  64.     void (*memory_error) PROTO((struct buffer *));
  65. };
  66.  
  67. /* Data is stored in lists of these structures.  */
  68.  
  69. struct buffer_data
  70. {
  71.     /* Next buffer in linked list.  */
  72.     struct buffer_data *next;
  73.  
  74.     /*
  75.      * A pointer into the data area pointed to by the text field.  This
  76.      * is where to find data that has not yet been written out.
  77.      */
  78.     char *bufp;
  79.  
  80.     /* The number of data bytes found at BUFP.  */
  81.     int size;
  82.  
  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.  
  90. /* The size we allocate for each buffer_data structure.  */
  91. #define BUFFER_DATA_SIZE (4096)
  92.  
  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 (*) (void *),
  100.                         void (*) (struct buffer *),
  101.                         void *));
  102. extern struct buffer *buf_nonio_initialize PROTO((void (*) (struct buffer *)));
  103. extern struct buffer *stdio_buffer_initialize
  104.   PROTO((FILE *, int, void (*) (struct buffer *)));
  105. extern struct buffer *compress_buffer_initialize
  106.   PROTO((struct buffer *, int, int, void (*) (struct buffer *)));
  107. extern int buf_empty_p PROTO((struct buffer *));
  108. extern void buf_output PROTO((struct buffer *, const char *, int));
  109. extern void buf_output0 PROTO((struct buffer *, const char *));
  110. extern void buf_append_char PROTO((struct buffer *, int));
  111. extern int buf_send_output PROTO((struct buffer *));
  112. extern int buf_flush PROTO((struct buffer *, int));
  113. extern int set_nonblock PROTO((struct buffer *));
  114. extern int set_block PROTO((struct buffer *));
  115. extern int buf_send_counted PROTO((struct buffer *));
  116. extern int buf_send_special_count PROTO((struct buffer *, int));
  117. extern void buf_append_data PROTO((struct buffer *,
  118.                    struct buffer_data *,
  119.                    struct buffer_data *));
  120. extern int buf_read_file PROTO((FILE *, long, struct buffer_data **,
  121.                 struct buffer_data **));
  122. extern int buf_read_file_to_eof PROTO((FILE *, struct buffer_data **,
  123.                        struct buffer_data **));
  124. extern int buf_input_data PROTO((struct buffer *, int *));
  125. extern int buf_read_line PROTO((struct buffer *, char **, int *));
  126. extern int buf_read_data PROTO((struct buffer *, int, char **, int *));
  127. extern void buf_copy_lines PROTO((struct buffer *, struct buffer *, int));
  128. extern int buf_copy_counted PROTO((struct buffer *, struct buffer *, int *));
  129. extern int buf_chain_length PROTO((struct buffer_data *));
  130. extern int buf_shutdown PROTO((struct buffer *));
  131.  
  132. #ifdef SERVER_FLOWCONTROL
  133. extern int buf_count_mem PROTO((struct buffer *));
  134. #endif /* SERVER_FLOWCONTROL */
  135.  
  136. #endif /* defined (SERVER_SUPPORT) || defined (CLIENT_SUPPORT) */
  137.