chiark / gitweb /
Fix a function declaration which slipped through the net.
[mLib] / man / selbuf.3
CommitLineData
b6b9d458 1.\" -*-nroff-*-
08da152e 2.TH selbuf 3 "23 May 1999" mLib
b6b9d458 3.SH NAME
4selbuf \- line-buffering input selector
08da152e 5.\" @selbuf_enable
6.\" @selbuf_disable
7.\" @selbuf_init
b6b9d458 8.SH SYNOPSIS
9.nf
10.B "#include <mLib/selbuf.h>"
11
12.BI "void selbuf_enable(selbuf *" b );
13.BI "void selbuf_disable(selbuf *" b );
cededfbe 14.BI "void selbuf_setsize(selbuf *" b ", size_t " sz );
b6b9d458 15.BI "void selbuf_init(selbuf *" b ,
16.BI " sel_state *" s ,
17.BI " int " fd ,
18.BI " void (*" func ")(char *" s ", void *" p ),
19.BI " void *" p );
cededfbe 20.BI "void selbuf_destroy(selbuf *" b );
b6b9d458 21.fi
22.SH DESCRIPTION
23The
24.B selbuf
25subsystem is a selector which integrates with the
08da152e 26.BR sel (3)
b6b9d458 27system for I/O multiplexing. It reads entire text lines from a file
28descriptor and passes them to a caller-defined function. It uses the
29line buffer described in
08da152e 30.BR lbuf (3)
b6b9d458 31to do its work: you should read about it in order to understand exactly
32what gets considered to be a line of text and what doesn't, and the
33exact rules about what your line handling function should and shouldn't
34do.
35.PP
cededfbe 36The data for a
b6b9d458 37.B selbuf
38selector is stored in an object of type
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
ff76c38f 59.BI "void (*" func ")(char *" s ", void *" p )
b6b9d458 60The
61.I "line handler"
62function. It is passed a pointer to each line read from the file (or
63null to indicate end-of-file) and an arbitrary pointer (the
64.I p
65argument to
66.B selbuf_init
67described below).
68.TP
ff76c38f 69.BI "void *" p
b6b9d458 70A pointer argument passed to
71.I func
72for each line read from the file. Apart from this, the pointer is not
73used at all.
74.PP
75The
76.B selbuf
77selector is immediately active. Subsequent calls to
78.B sel_select
79on the same multiplexor will cause any complete lines read from the file
80to be passed to your handling function. This function can at any time
81call
82.B selbuf_disable
83to stop itself from being called any more. The selector is then
84disengaged from the I/O multiplexor and won't do anything until
85.B selbuf_enable
86is called. Note that
87.B selbuf_enable
88may well immediately start emitting complete lines of text which were
89queued up from the last I/O operation: it doesn't necessarily wait for
90the next
91.B sel_select
92call.
cededfbe 93.PP
94The line buffer has a finite amount of memory for reading strings. The
95size of this buffer is set by calling
96.B selbuf_setsize
97with the requested size. The default buffer size is 256 bytes.
98.PP
99When it's finished with, a line buffer selector must be destroyed by
100calling
101.BR selbuf_destroy .
08da152e 102.SH "SEE ALSO"
103.BR lbuf (3),
104.BR sel (3),
105.BR mLib (3).
b6b9d458 106.SH AUTHOR
107Mark Wooding, <mdw@nsict.org>