3 .\" Manual for event-driven line buffer
5 .\" (c) 1999--2002, 2005, 2009, 2023, 2024 Straylight/Edgeware
8 .\"----- Licensing notice ---------------------------------------------------
10 .\" This file is part of the mLib utilities library.
12 .\" mLib is free software: you can redistribute it and/or modify it under
13 .\" the terms of the GNU Library General Public License as published by
14 .\" the Free Software Foundation; either version 2 of the License, or (at
15 .\" your option) any later version.
17 .\" mLib is distributed in the hope that it will be useful, but WITHOUT
18 .\" ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 .\" FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
20 .\" License for more details.
22 .\" You should have received a copy of the GNU Library General Public
23 .\" License along with mLib. If not, write to the Free Software
24 .\" Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
27 .\"--------------------------------------------------------------------------
28 .so ../defs.man \" @@@PRE@@@
30 .\"--------------------------------------------------------------------------
31 .TH selbuf 3mLib "23 May 1999" "Straylight/Edgeware" "mLib utilities library"
38 .\"--------------------------------------------------------------------------
40 selbuf \- line-buffering input selector
42 .\"--------------------------------------------------------------------------
46 .B "#include <mLib/selbuf.h>"
48 .B "typedef struct { ...\& } selbuf;"
50 .BI "void selbuf_enable(selbuf *" b );
51 .BI "void selbuf_disable(selbuf *" b );
52 .BI "void selbuf_setsize(selbuf *" b ", size_t " sz );
53 .ta \w'\fBvoid selbuf_init('u
54 .BI "void selbuf_init(selbuf *" b ", sel_state *" s ", int " fd ,
55 .BI " lbuf_func *" func ", void *" p );
56 .BI "void selbuf_destroy(selbuf *" b );
59 .\"--------------------------------------------------------------------------
63 subsystem is a selector which integrates with the
65 system for I/O multiplexing. It reads entire text lines from a file
66 descriptor and passes them to a caller-defined function. It uses the
67 line buffer described in
69 to do its work: you should read about it in order to understand exactly
70 what gets considered to be a line of text and what doesn't, and the
71 exact rules about what your line handling function should and shouldn't
74 The data for a line selector is stored in an object of type
76 This object must be allocated by the caller, and initialized using the
78 function. This requires a fair few arguments:
86 Pointer to a multiplexor object (type
88 to which this selector should be attached. See
90 for more details about multiplexors, and how this whole system works.
93 The file descriptor of the stream the selector should read from.
95 .BI "lbuf_func *" func
98 function. It is passed a pointer to each line read from the file (or
99 null to indicate end-of-file), the length of the line, and an arbitrary
104 described below). For full details, see
108 A pointer argument passed to
110 for each line read from the file. Apart from this, the pointer is not
115 selector is immediately active. Subsequent calls to
117 on the same multiplexor will cause any complete lines read from the file
118 to be passed to your handling function. This function can at any time
121 to stop itself from being called any more. The selector is then
122 disengaged from the I/O multiplexor and won't do anything until
126 may well immediately start emitting complete lines of text which were
127 queued up from the last I/O operation: it doesn't necessarily wait for
132 The line buffer has a finite amount of memory for reading strings. The
133 size of this buffer is set by calling
135 with the requested size. The default buffer size is 256 bytes.
137 When it's finished with, a line buffer selector must be destroyed by
141 .\"--------------------------------------------------------------------------
148 .\"--------------------------------------------------------------------------
151 Mark Wooding, <mdw@distorted.org.uk>
153 .\"----- That's all, folks --------------------------------------------------