summaryrefslogtreecommitdiff
path: root/lib/buffer.h
diff options
context:
space:
mode:
authorajs <ajs>2004-11-04 19:26:16 +0000
committerajs <ajs>2004-11-04 19:26:16 +0000
commit49ff6d9d7a9ef9419dd7aab58ac9f7806e3e1040 (patch)
treebb9e1d36b5bef56d2e47c69b6bab1ef54cf9696e /lib/buffer.h
parent62d8e96a06e664c929a164bfb66b515d1c6877a8 (diff)
2004-11-04 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
* vty.c: Vtysh connections to daemons should use buffering. (vty_out) Remove exception for vty_shell_serv, just use buffer_write. (vty_new) Increase output buffer size to 4096 rounded up to a multiple of pagesize. (vtysh_read) After command has been executed and all output buffered, call buffer_flush_available and schedule further writes if the buffers are not yet empty. (vtysh_write) New function to flush output to vtysh when the socket is writeable. (vty_event) Added new VTYSH_WRITE event for flushing buffers to vtysh clients. Also, should save read thread in vty->t_read so the thread can be cancelled in vty_close. * buffer.h: In struct buffer_data, remove unused "parent" field. Convert "unsigned char *data" to "unsigned char data[0]" to save a malloc. Declare new function buffer_flush_available that works with non-blocking sockets. * buffer.c: (buffer_data_new) Use a single malloc now that data is a variable-size array at end of structure. (buffer_data_free) Just a single free now that data is part of the structure. (buffer_write) Simplify the logic to make behavior more transparent. (buffer_flush) Decrease b->length as data is written out. (buffer_flush_vty_all) Decrease b->length as buffers are freed. (buffer_flush_vty) Decrease b->length as data is written out. (buffer_flush_available) New function to flush non-blocking sockets.
Diffstat (limited to 'lib/buffer.h')
-rw-r--r--lib/buffer.h16
1 files changed, 11 insertions, 5 deletions
diff --git a/lib/buffer.h b/lib/buffer.h
index 9d453b1d..2acd571f 100644
--- a/lib/buffer.h
+++ b/lib/buffer.h
@@ -33,7 +33,7 @@ struct buffer
/* Current allocated data. */
unsigned long alloc;
- /* Total length of buffer. */
+ /* Size of each buffer_data chunk. */
unsigned long size;
/* For allocation. */
@@ -47,18 +47,17 @@ struct buffer
/* Data container. */
struct buffer_data
{
- struct buffer *parent;
struct buffer_data *next;
struct buffer_data *prev;
- /* Acctual data stream. */
- unsigned char *data;
-
/* Current pointer. */
unsigned long cp;
/* Start pointer. */
unsigned long sp;
+
+ /* Actual data stream (variable length). */
+ unsigned char data[0]; /* real dimension is buffer->size */
};
/* Buffer prototypes. */
@@ -74,4 +73,11 @@ int buffer_flush_vty_all (struct buffer *, int, int, int);
int buffer_flush_window (struct buffer *, int, int, int, int, int);
int buffer_empty (struct buffer *);
+/* buffer_flush_available attempts to flush the queued data to the given
+ file descriptor. It returns 0 if the buffers are now empty (after
+ flushing), or 1 if more data remains on the buffer queue (must be flushed
+ later). This function (unlike the other buffer_flush* functions) is
+ designed to work with non-blocking file descriptors. */
+int buffer_flush_available(struct buffer *, int fd);
+
#endif /* _ZEBRA_BUFFER_H */