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