chiark / gitweb /
@@@ much mess, mostly manpages
[mLib] / sel / selbuf.3.in
CommitLineData
b6b9d458 1.\" -*-nroff-*-
c4ccbbf9
MW
2.\"
3.\" Manual for event-driven line buffer
4.\"
5.\" (c) 1999--2002, 2005, 2009, 2023, 2024 Straylight/Edgeware
6.\"
7.
8.\"----- Licensing notice ---------------------------------------------------
9.\"
10.\" This file is part of the mLib utilities library.
11.\"
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.
16.\"
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.
21.\"
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,
25.\" USA.
26.
27.\"--------------------------------------------------------------------------
28.so ../defs.man \" @@@PRE@@@
29.
30.\"--------------------------------------------------------------------------
31.TH selbuf 3mLib "23 May 1999" "Straylight/Edgeware" "mLib utilities library"
08da152e 32.\" @selbuf_enable
33.\" @selbuf_disable
31e83d07 34.\" @selbuf_setsize
08da152e 35.\" @selbuf_init
31e83d07 36.\" @selbuf_destroy
c4ccbbf9
MW
37.
38.\"--------------------------------------------------------------------------
39.SH NAME
40selbuf \- line-buffering input selector
41.
42.\"--------------------------------------------------------------------------
b6b9d458 43.SH SYNOPSIS
c4ccbbf9 44.
b6b9d458 45.nf
46.B "#include <mLib/selbuf.h>"
d056fbdf 47.PP
4729aa69 48.B "typedef struct { ...\& } selbuf;"
d056fbdf 49.PP
b6b9d458 50.BI "void selbuf_enable(selbuf *" b );
51.BI "void selbuf_disable(selbuf *" b );
cededfbe 52.BI "void selbuf_setsize(selbuf *" b ", size_t " sz );
adec5584
MW
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 );
cededfbe 56.BI "void selbuf_destroy(selbuf *" b );
b6b9d458 57.fi
c4ccbbf9
MW
58.
59.\"--------------------------------------------------------------------------
b6b9d458 60.SH DESCRIPTION
61The
62.B selbuf
63subsystem is a selector which integrates with the
08da152e 64.BR sel (3)
b6b9d458 65system for I/O multiplexing. It reads entire text lines from a file
66descriptor and passes them to a caller-defined function. It uses the
67line buffer described in
08da152e 68.BR lbuf (3)
b6b9d458 69to do its work: you should read about it in order to understand exactly
70what gets considered to be a line of text and what doesn't, and the
71exact rules about what your line handling function should and shouldn't
72do.
73.PP
31e83d07 74The data for a line selector is stored in an object of type
b6b9d458 75.BR selbuf .
76This object must be allocated by the caller, and initialized using the
77.B selbuf_init
78function. This requires a fair few arguments:
79.TP
ff76c38f 80.BI "selbuf *" b
b6b9d458 81Pointer to the
82.B selbuf
83object to initialize.
84.TP
ff76c38f 85.BI "sel_state *" s
b6b9d458 86Pointer to a multiplexor object (type
87.BR sel_state )
88to which this selector should be attached. See
08da152e 89.BR sel (3)
b6b9d458 90for more details about multiplexors, and how this whole system works.
91.TP
ff76c38f 92.BI "int " fd
b6b9d458 93The file descriptor of the stream the selector should read from.
94.TP
b342b114 95.BI "lbuf_func *" func
b6b9d458 96The
97.I "line handler"
98function. It is passed a pointer to each line read from the file (or
b342b114 99null to indicate end-of-file), the length of the line, and an arbitrary
100pointer (the
b6b9d458 101.I p
102argument to
103.B selbuf_init
b342b114 104described below). For full details, see
105.BR lbuf (3).
b6b9d458 106.TP
ff76c38f 107.BI "void *" p
b6b9d458 108A pointer argument passed to
109.I func
110for each line read from the file. Apart from this, the pointer is not
111used at all.
112.PP
113The
114.B selbuf
115selector is immediately active. Subsequent calls to
116.B sel_select
117on the same multiplexor will cause any complete lines read from the file
118to be passed to your handling function. This function can at any time
119call
120.B selbuf_disable
121to stop itself from being called any more. The selector is then
122disengaged from the I/O multiplexor and won't do anything until
123.B selbuf_enable
124is called. Note that
125.B selbuf_enable
126may well immediately start emitting complete lines of text which were
127queued up from the last I/O operation: it doesn't necessarily wait for
128the next
129.B sel_select
130call.
cededfbe 131.PP
132The line buffer has a finite amount of memory for reading strings. The
133size of this buffer is set by calling
134.B selbuf_setsize
135with the requested size. The default buffer size is 256 bytes.
136.PP
137When it's finished with, a line buffer selector must be destroyed by
138calling
139.BR selbuf_destroy .
c4ccbbf9
MW
140.
141.\"--------------------------------------------------------------------------
08da152e 142.SH "SEE ALSO"
c4ccbbf9 143.
08da152e 144.BR lbuf (3),
145.BR sel (3),
146.BR mLib (3).
c4ccbbf9
MW
147.
148.\"--------------------------------------------------------------------------
b6b9d458 149.SH AUTHOR
c4ccbbf9 150.
9b5ac6ff 151Mark Wooding, <mdw@distorted.org.uk>
c4ccbbf9
MW
152.
153.\"----- That's all, folks --------------------------------------------------