1 /* CVS client logging buffer.
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details. */
19 #include "ms-buffer.h"
21 #if defined (SERVER_SUPPORT) || defined (CLIENT_SUPPORT)
24 /* This structure is the closure field of a multi-source buffer. */
27 /* Our buffer struct. */
30 /* The underlying buffers. */
34 /* Whether we are in blocking mode or not. */
40 /* The block function for a multi-source buffer. */
42 ms_buffer_block (void *closure, bool block)
44 struct ms_buffer *mb = closure;
48 return set_block (mb->cur);
50 return set_nonblock (mb->cur);
55 /* The input function for a log buffer. */
57 ms_buffer_input (void *closure, char *data, size_t need, size_t size,
60 struct ms_buffer *mb = closure;
63 assert (mb->cur->input);
64 status = (*mb->cur->input) (mb->cur->closure, data, need, size, got);
68 /* EOF. Set up the next buffer in line but return success and no
69 * data since our caller may have selected on the target to find
70 * ready data before calling us.
72 * If there are no more buffers, return EOF.
74 if (list_isempty (mb->bufs)) return -1;
75 buf_shutdown (mb->cur);
77 p = mb->bufs->list->next;
82 if (!buf_empty_p (mb->cur)) buf_append_buffer (mb->buf, mb->cur);
83 ms_buffer_block (closure, mb->block);
93 /* Return the file descriptor underlying any child buffers. */
95 ms_buffer_get_fd (void *closure)
97 struct ms_buffer *mb = closure;
98 return buf_get_fd (mb->cur);
103 /* The shutdown function for a multi-source buffer. */
105 ms_buffer_shutdown (struct buffer *buf)
107 struct ms_buffer *mb = buf->closure;
112 err += buf_shutdown (mb->cur);
114 for (p = mb->bufs->list->next; p != mb->bufs->list; p = p->next)
117 err += buf_shutdown (p->data);
135 /* Create a multi-source buffer. This could easily be generalized to support
136 * any number of source buffers, but for now only two are necessary.
139 ms_buffer_initialize (void (*memory) (struct buffer *),
140 struct buffer *buf, struct buffer *buf2/*, ...*/)
142 struct ms_buffer *mb = xmalloc (sizeof *mb);
143 struct buffer *retbuf;
149 mb->bufs = getlist ();
152 p->delproc = delbuflist;
153 addnode (mb->bufs, p);
154 retbuf = buf_initialize (ms_buffer_input, NULL, NULL,
155 ms_buffer_block, ms_buffer_get_fd,
156 ms_buffer_shutdown, memory, mb);
157 if (!buf_empty_p (buf)) buf_append_buffer (retbuf, buf);
162 #endif /* PROXY_SUPPORT */
163 #endif /* defined (SERVER_SUPPORT) || defined (CLIENT_SUPPORT) */