@@@ man wip
[mLib] / sel / selbuf.3
CommitLineData
b6b9d458 1.\" -*-nroff-*-
fbf20b5b 2.TH selbuf 3 "23 May 1999" "Straylight/Edgeware" "mLib utilities library"
b6b9d458 3.SH NAME
4selbuf \- line-buffering input selector
08da152e 5.\" @selbuf_enable
6.\" @selbuf_disable
31e83d07 7.\" @selbuf_setsize
08da152e 8.\" @selbuf_init
31e83d07 9.\" @selbuf_destroy
b6b9d458 10.SH SYNOPSIS
11.nf
12.B "#include <mLib/selbuf.h>"
d056fbdf 13.PP
4729aa69 14.B "typedef struct { ...\& } selbuf;"
d056fbdf 15.PP
b6b9d458 16.BI "void selbuf_enable(selbuf *" b );
17.BI "void selbuf_disable(selbuf *" b );
cededfbe 18.BI "void selbuf_setsize(selbuf *" b ", size_t " sz );
adec5584
MW
19.ta \w'\fBvoid selbuf_init('u
20.BI "void selbuf_init(selbuf *" b ", sel_state *" s ", int " fd ,
21.BI " lbuf_func *" func ", void *" p );
cededfbe 22.BI "void selbuf_destroy(selbuf *" b );
b6b9d458 23.fi
24.SH DESCRIPTION
25The
26.B selbuf
27subsystem is a selector which integrates with the
08da152e 28.BR sel (3)
b6b9d458 29system for I/O multiplexing. It reads entire text lines from a file
30descriptor and passes them to a caller-defined function. It uses the
31line buffer described in
08da152e 32.BR lbuf (3)
b6b9d458 33to do its work: you should read about it in order to understand exactly
34what gets considered to be a line of text and what doesn't, and the
35exact rules about what your line handling function should and shouldn't
36do.
37.PP
31e83d07 38The data for a line selector is stored in an object of type
b6b9d458 39.BR selbuf .
40This object must be allocated by the caller, and initialized using the
41.B selbuf_init
42function. This requires a fair few arguments:
43.TP
ff76c38f 44.BI "selbuf *" b
b6b9d458 45Pointer to the
46.B selbuf
47object to initialize.
48.TP
ff76c38f 49.BI "sel_state *" s
b6b9d458 50Pointer to a multiplexor object (type
51.BR sel_state )
52to which this selector should be attached. See
08da152e 53.BR sel (3)
b6b9d458 54for more details about multiplexors, and how this whole system works.
55.TP
ff76c38f 56.BI "int " fd
b6b9d458 57The file descriptor of the stream the selector should read from.
58.TP
b342b114 59.BI "lbuf_func *" func
b6b9d458 60The
61.I "line handler"
62function. It is passed a pointer to each line read from the file (or
b342b114 63null to indicate end-of-file), the length of the line, and an arbitrary
64pointer (the
b6b9d458 65.I p
66argument to
67.B selbuf_init
b342b114 68described below). For full details, see
69.BR lbuf (3).
b6b9d458 70.TP
ff76c38f 71.BI "void *" p
b6b9d458 72A pointer argument passed to
73.I func
74for each line read from the file. Apart from this, the pointer is not
75used at all.
76.PP
77The
78.B selbuf
79selector is immediately active. Subsequent calls to
80.B sel_select
81on the same multiplexor will cause any complete lines read from the file
82to be passed to your handling function. This function can at any time
83call
84.B selbuf_disable
85to stop itself from being called any more. The selector is then
86disengaged from the I/O multiplexor and won't do anything until
87.B selbuf_enable
88is called. Note that
89.B selbuf_enable
90may well immediately start emitting complete lines of text which were
91queued up from the last I/O operation: it doesn't necessarily wait for
92the next
93.B sel_select
94call.
cededfbe 95.PP
96The line buffer has a finite amount of memory for reading strings. The
97size of this buffer is set by calling
98.B selbuf_setsize
99with the requested size. The default buffer size is 256 bytes.
100.PP
101When it's finished with, a line buffer selector must be destroyed by
102calling
103.BR selbuf_destroy .
08da152e 104.SH "SEE ALSO"
105.BR lbuf (3),
106.BR sel (3),
107.BR mLib (3).
b6b9d458 108.SH AUTHOR
9b5ac6ff 109Mark Wooding, <mdw@distorted.org.uk>