chiark / gitweb /
Version bump.
[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 );
14.BI "void selbuf_init(selbuf *" b ,
15.BI " sel_state *" s ,
16.BI " int " fd ,
17.BI " void (*" func ")(char *" s ", void *" p ),
18.BI " void *" p );
19.fi
20.SH DESCRIPTION
21The
22.B selbuf
23subsystem is a selector which integrates with the
08da152e 24.BR sel (3)
b6b9d458 25system for I/O multiplexing. It reads entire text lines from a file
26descriptor and passes them to a caller-defined function. It uses the
27line buffer described in
08da152e 28.BR lbuf (3)
b6b9d458 29to do its work: you should read about it in order to understand exactly
30what gets considered to be a line of text and what doesn't, and the
31exact rules about what your line handling function should and shouldn't
32do.
33.PP
34All the data for a
35.B selbuf
36selector is stored in an object of type
37.BR selbuf .
38This object must be allocated by the caller, and initialized using the
39.B selbuf_init
40function. This requires a fair few arguments:
41.TP
ff76c38f 42.BI "selbuf *" b
b6b9d458 43Pointer to the
44.B selbuf
45object to initialize.
46.TP
ff76c38f 47.BI "sel_state *" s
b6b9d458 48Pointer to a multiplexor object (type
49.BR sel_state )
50to which this selector should be attached. See
08da152e 51.BR sel (3)
b6b9d458 52for more details about multiplexors, and how this whole system works.
53.TP
ff76c38f 54.BI "int " fd
b6b9d458 55The file descriptor of the stream the selector should read from.
56.TP
ff76c38f 57.BI "void (*" func ")(char *" s ", void *" p )
b6b9d458 58The
59.I "line handler"
60function. It is passed a pointer to each line read from the file (or
61null to indicate end-of-file) and an arbitrary pointer (the
62.I p
63argument to
64.B selbuf_init
65described below).
66.TP
ff76c38f 67.BI "void *" p
b6b9d458 68A pointer argument passed to
69.I func
70for each line read from the file. Apart from this, the pointer is not
71used at all.
72.PP
73The
74.B selbuf
75selector is immediately active. Subsequent calls to
76.B sel_select
77on the same multiplexor will cause any complete lines read from the file
78to be passed to your handling function. This function can at any time
79call
80.B selbuf_disable
81to stop itself from being called any more. The selector is then
82disengaged from the I/O multiplexor and won't do anything until
83.B selbuf_enable
84is called. Note that
85.B selbuf_enable
86may well immediately start emitting complete lines of text which were
87queued up from the last I/O operation: it doesn't necessarily wait for
88the next
89.B sel_select
90call.
08da152e 91.SH "SEE ALSO"
92.BR lbuf (3),
93.BR sel (3),
94.BR mLib (3).
b6b9d458 95.SH AUTHOR
96Mark Wooding, <mdw@nsict.org>