\doxysection{buffer.\+h}
\label{buffer_8h_source}\index{include/osmocom/vty/buffer.h@{include/osmocom/vty/buffer.h}}
\textbf{ Go to the documentation of this file.}
\begin{DoxyCode}{0}
\DoxyCodeLine{1 }
\DoxyCodeLine{3 \textcolor{comment}{/*}}
\DoxyCodeLine{4 \textcolor{comment}{ * Copyright (C) 1998 Kunihiro Ishiguro}}
\DoxyCodeLine{5 \textcolor{comment}{ *}}
\DoxyCodeLine{6 \textcolor{comment}{ * This file is part of GNU Zebra.}}
\DoxyCodeLine{7 \textcolor{comment}{ *}}
\DoxyCodeLine{8 \textcolor{comment}{ * GNU Zebra is free software; you can redistribute it and/or modify}}
\DoxyCodeLine{9 \textcolor{comment}{ * it under the terms of the GNU General Public License as published}}
\DoxyCodeLine{10 \textcolor{comment}{ * by the Free Software Foundation; either version 2, or (at your}}
\DoxyCodeLine{11 \textcolor{comment}{ * option) any later version.}}
\DoxyCodeLine{12 \textcolor{comment}{ *}}
\DoxyCodeLine{13 \textcolor{comment}{ * GNU Zebra is distributed in the hope that it will be useful, but}}
\DoxyCodeLine{14 \textcolor{comment}{ * WITHOUT ANY WARRANTY; without even the implied warranty of}}
\DoxyCodeLine{15 \textcolor{comment}{ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU}}
\DoxyCodeLine{16 \textcolor{comment}{ * General Public License for more details.}}
\DoxyCodeLine{17 \textcolor{comment}{ *}}
\DoxyCodeLine{18 \textcolor{comment}{ * You should have received a copy of the GNU General Public License}}
\DoxyCodeLine{19 \textcolor{comment}{ * along with GNU Zebra; see the file COPYING.  If not, write to the}}
\DoxyCodeLine{20 \textcolor{comment}{ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,}}
\DoxyCodeLine{21 \textcolor{comment}{ * Boston, MA  02110-\/1301, USA.}}
\DoxyCodeLine{22 \textcolor{comment}{ */}}
\DoxyCodeLine{23 }
\DoxyCodeLine{24 \textcolor{preprocessor}{\#pragma once}}
\DoxyCodeLine{25 }
\DoxyCodeLine{26 \textcolor{preprocessor}{\#include <sys/types.h>}}
\DoxyCodeLine{27 }
\DoxyCodeLine{28 \textcolor{comment}{/* Create a new buffer.  Memory will be allocated in chunks of the given}}
\DoxyCodeLine{29 \textcolor{comment}{   size.  If the argument is 0, the library will supply a reasonable}}
\DoxyCodeLine{30 \textcolor{comment}{   default size suitable for buffering socket I/O. */}}
\DoxyCodeLine{31 \textcolor{keyword}{struct }buffer *buffer\_new(\textcolor{keywordtype}{void} *ctx, \textcolor{keywordtype}{size\_t});}
\DoxyCodeLine{32 }
\DoxyCodeLine{33 \textcolor{comment}{/* Free all data in the buffer. */}}
\DoxyCodeLine{34 \textcolor{keywordtype}{void} buffer\_reset(\textcolor{keyword}{struct} buffer *);}
\DoxyCodeLine{35 }
\DoxyCodeLine{36 \textcolor{comment}{/* This function first calls buffer\_reset to release all buffered data.}}
\DoxyCodeLine{37 \textcolor{comment}{   Then it frees the struct buffer itself. */}}
\DoxyCodeLine{38 \textcolor{keywordtype}{void} buffer\_free(\textcolor{keyword}{struct} buffer *);}
\DoxyCodeLine{39 }
\DoxyCodeLine{40 \textcolor{comment}{/* Add the given data to the end of the buffer. */}}
\DoxyCodeLine{41 \textcolor{keyword}{extern} \textcolor{keywordtype}{void} buffer\_put(\textcolor{keyword}{struct} buffer *, \textcolor{keyword}{const} \textcolor{keywordtype}{void} *, \textcolor{keywordtype}{size\_t});}
\DoxyCodeLine{42 \textcolor{comment}{/* Add a single character to the end of the buffer. */}}
\DoxyCodeLine{43 \textcolor{keyword}{extern} \textcolor{keywordtype}{void} buffer\_putc(\textcolor{keyword}{struct} buffer *, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{char});}
\DoxyCodeLine{44 \textcolor{comment}{/* Add a NUL-\/terminated string to the end of the buffer. */}}
\DoxyCodeLine{45 \textcolor{keyword}{extern} \textcolor{keywordtype}{void} buffer\_putstr(\textcolor{keyword}{struct} buffer *, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *);}
\DoxyCodeLine{46 }
\DoxyCodeLine{47 \textcolor{comment}{/* Combine all accumulated (and unflushed) data inside the buffer into a}}
\DoxyCodeLine{48 \textcolor{comment}{   single NUL-\/terminated string allocated using XMALLOC(MTYPE\_TMP).  Note}}
\DoxyCodeLine{49 \textcolor{comment}{   that this function does not alter the state of the buffer, so the data}}
\DoxyCodeLine{50 \textcolor{comment}{   is still inside waiting to be flushed. */}}
\DoxyCodeLine{51 \textcolor{keywordtype}{char} *buffer\_getstr(\textcolor{keyword}{struct} buffer *);}
\DoxyCodeLine{52 }
\DoxyCodeLine{53 \textcolor{comment}{/* Returns 1 if there is no pending data in the buffer.  Otherwise returns 0. */}}
\DoxyCodeLine{54 \textcolor{keywordtype}{int} buffer\_empty(\textcolor{keyword}{struct} buffer *);}
\DoxyCodeLine{55 }
\DoxyCodeLine{56 \textcolor{keyword}{typedef} \textcolor{keyword}{enum} \{}
\DoxyCodeLine{57         \textcolor{comment}{/* An I/O error occurred.  The buffer should be destroyed and the}}
\DoxyCodeLine{58 \textcolor{comment}{           file descriptor should be closed. */}}
\DoxyCodeLine{59         BUFFER\_ERROR = -\/1,}
\DoxyCodeLine{60 }
\DoxyCodeLine{61         \textcolor{comment}{/* The data was written successfully, and the buffer is now empty}}
\DoxyCodeLine{62 \textcolor{comment}{           (there is no pending data waiting to be flushed). */}}
\DoxyCodeLine{63         BUFFER\_EMPTY = 0,}
\DoxyCodeLine{64 }
\DoxyCodeLine{65         \textcolor{comment}{/* There is pending data in the buffer waiting to be flushed.  Please}}
\DoxyCodeLine{66 \textcolor{comment}{           try flushing the buffer when select indicates that the file descriptor}}
\DoxyCodeLine{67 \textcolor{comment}{           is writeable. */}}
\DoxyCodeLine{68         BUFFER\_PENDING = 1}
\DoxyCodeLine{69 \} buffer\_status\_t;}
\DoxyCodeLine{70 }
\DoxyCodeLine{71 \textcolor{comment}{/* Try to write this data to the file descriptor.  Any data that cannot}}
\DoxyCodeLine{72 \textcolor{comment}{   be written immediately is added to the buffer queue. */}}
\DoxyCodeLine{73 \textcolor{keyword}{extern} buffer\_status\_t buffer\_write(\textcolor{keyword}{struct} buffer *, \textcolor{keywordtype}{int} fd,}
\DoxyCodeLine{74                                     \textcolor{keyword}{const} \textcolor{keywordtype}{void} *, \textcolor{keywordtype}{size\_t});}
\DoxyCodeLine{75 }
\DoxyCodeLine{76 \textcolor{comment}{/* This function attempts to flush some (but perhaps not all) of}}
\DoxyCodeLine{77 \textcolor{comment}{   the queued data to the given file descriptor. */}}
\DoxyCodeLine{78 \textcolor{keyword}{extern} buffer\_status\_t buffer\_flush\_available(\textcolor{keyword}{struct} buffer *, \textcolor{keywordtype}{int} fd);}
\DoxyCodeLine{79 }
\DoxyCodeLine{80 \textcolor{comment}{/* The following 2 functions (buffer\_flush\_all and buffer\_flush\_window)}}
\DoxyCodeLine{81 \textcolor{comment}{   are for use in lib/vty.c only.  They should not be used elsewhere. */}}
\DoxyCodeLine{82 }
\DoxyCodeLine{83 \textcolor{comment}{/* Call buffer\_flush\_available repeatedly until either all data has been}}
\DoxyCodeLine{84 \textcolor{comment}{   flushed, or an I/O error has been encountered, or the operation would}}
\DoxyCodeLine{85 \textcolor{comment}{   block. */}}
\DoxyCodeLine{86 \textcolor{keyword}{extern} buffer\_status\_t buffer\_flush\_all(\textcolor{keyword}{struct} buffer *, \textcolor{keywordtype}{int} fd);}
\DoxyCodeLine{87 }
\DoxyCodeLine{88 \textcolor{comment}{/* Attempt to write enough data to the given fd to fill a window of the}}
\DoxyCodeLine{89 \textcolor{comment}{   given width and height (and remove the data written from the buffer).}}
\DoxyCodeLine{90 \textcolor{comment}{}}
\DoxyCodeLine{91 \textcolor{comment}{   If !no\_more, then a message saying "{} -\/-\/More-\/-\/ "{} is appended.}}
\DoxyCodeLine{92 \textcolor{comment}{   If erase is true, then first overwrite the previous "{} -\/-\/More-\/-\/ "{} message}}
\DoxyCodeLine{93 \textcolor{comment}{   with spaces.}}
\DoxyCodeLine{94 \textcolor{comment}{}}
\DoxyCodeLine{95 \textcolor{comment}{   Any write error (including EAGAIN or EINTR) will cause this function}}
\DoxyCodeLine{96 \textcolor{comment}{   to return -\/1 (because the logic for handling the erase and more features}}
\DoxyCodeLine{97 \textcolor{comment}{   is too complicated to retry the write later).}}
\DoxyCodeLine{98 \textcolor{comment}{*/}}
\DoxyCodeLine{99 \textcolor{keyword}{extern} buffer\_status\_t buffer\_flush\_window(\textcolor{keyword}{struct} buffer *, \textcolor{keywordtype}{int} fd, \textcolor{keywordtype}{int} width,}
\DoxyCodeLine{100                                            \textcolor{keywordtype}{int} height, \textcolor{keywordtype}{int} erase, \textcolor{keywordtype}{int} no\_more);}

\end{DoxyCode}
