97f65b00 |
1 | /* -*-c-*- |
2 | * |
e03be5f4 |
3 | * $Id: selbuf.h,v 1.3 2000/06/17 10:38:14 mdw Exp $ |
97f65b00 |
4 | * |
5 | * Line-buffering select handler |
6 | * |
7 | * (c) 1999 Straylight/Edgeware |
8 | */ |
9 | |
10 | /*----- Licensing notice --------------------------------------------------* |
11 | * |
12 | * This file is part of the mLib utilities library. |
13 | * |
14 | * mLib is free software; you can redistribute it and/or modify |
15 | * it under the terms of the GNU Library General Public License as |
16 | * published by the Free Software Foundation; either version 2 of the |
17 | * License, or (at your option) any later version. |
18 | * |
19 | * mLib is distributed in the hope that it will be useful, |
20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22 | * GNU Library General Public License for more details. |
23 | * |
24 | * You should have received a copy of the GNU Library General Public |
25 | * License along with mLib; if not, write to the Free |
26 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
27 | * MA 02111-1307, USA. |
28 | */ |
29 | |
30 | /*----- Revision history --------------------------------------------------* |
31 | * |
32 | * $Log: selbuf.h,v $ |
e03be5f4 |
33 | * Revision 1.3 2000/06/17 10:38:14 mdw |
34 | * Add support for variable buffer sizes. |
35 | * |
c6e0eaf0 |
36 | * Revision 1.2 1999/12/10 23:42:04 mdw |
37 | * Change header file guard names. |
38 | * |
97f65b00 |
39 | * Revision 1.1 1999/05/14 21:01:15 mdw |
40 | * Integrated `select' handling bits from the background resolver project. |
41 | * |
42 | */ |
43 | |
c6e0eaf0 |
44 | #ifndef MLIB_SELBUF_H |
45 | #define MLIB_SELBUF_H |
97f65b00 |
46 | |
47 | #ifdef __cplusplus |
48 | extern "C" { |
49 | #endif |
50 | |
51 | /*----- Header files ------------------------------------------------------*/ |
52 | |
c6e0eaf0 |
53 | #ifndef MLIB_LBUF_H |
97f65b00 |
54 | # include "lbuf.h" |
55 | #endif |
56 | |
c6e0eaf0 |
57 | #ifndef MLIB_SEL_H |
97f65b00 |
58 | # include "sel.h" |
59 | #endif |
60 | |
61 | /*----- Data structures ---------------------------------------------------*/ |
62 | |
63 | typedef struct selbuf { |
64 | sel_file reader; /* File selection object */ |
65 | lbuf b; /* Line buffering object */ |
66 | } selbuf; |
67 | |
68 | /*----- Functions provided ------------------------------------------------*/ |
69 | |
70 | /* --- @selbuf_enable@ --- * |
71 | * |
72 | * Arguments: @selbuf *b@ = pointer to buffer block |
73 | * |
74 | * Returns: --- |
75 | * |
76 | * Use: Enables a buffer for reading, and emits any queued lines |
77 | * to the buffer's owner. |
78 | */ |
79 | |
80 | extern void selbuf_enable(selbuf */*b*/); |
81 | |
82 | /* --- @selbuf_disable@ --- * |
83 | * |
84 | * Arguments: @selbuf *b@ = pointer to a buffer block |
85 | * |
86 | * Returns: --- |
87 | * |
88 | * Use: Disables a buffer. It won't be read from until it's |
89 | * enabled again. |
90 | */ |
91 | |
92 | extern void selbuf_disable(selbuf */*b*/); |
93 | |
e03be5f4 |
94 | /* --- @selbuf_setsize@ --- * |
95 | * |
96 | * Arguments: @selbuf *b@ = pointer to buffer block |
97 | * @size_t sz@ = size of buffer |
98 | * |
99 | * Returns: --- |
100 | * |
101 | * Use: Sets the size of the buffer used for reading lines. |
102 | */ |
103 | |
104 | extern void selbuf_setsize(selbuf */*b*/, size_t /*sz*/); |
105 | |
97f65b00 |
106 | /* --- @selbuf_init@ --- * |
107 | * |
108 | * Arguments: @selbuf *b@ = pointer to buffer block |
109 | * @sel_state *s@ = pointer to select state to attach to |
110 | * @int fd@ = file descriptor to listen to |
111 | * @void (*func)(char *s, void *p)@ = function to call |
112 | * @void *p@ = argument for function |
113 | * |
114 | * Returns: --- |
115 | * |
116 | * Use: Initializes a buffer block. |
117 | */ |
118 | |
119 | extern void selbuf_init(selbuf */*b*/, |
120 | sel_state */*s*/, |
121 | int /*fd*/, |
122 | void (*/*func*/)(char */*s*/, void */*p*/), |
123 | void */*p*/); |
124 | |
e03be5f4 |
125 | /* --- @selbuf_destroy@ --- * |
126 | * |
127 | * Arguments: @selbuf *b@ = pointer to buffer block |
128 | * |
129 | * Returns: --- |
130 | * |
131 | * Use: Deallocates a line buffer and frees any resources it owned. |
132 | */ |
133 | |
134 | extern void selbuf_destroy(selbuf */*b*/); |
135 | |
97f65b00 |
136 | /*----- That's all, folks -------------------------------------------------*/ |
137 | |
138 | #ifdef __cplusplus |
139 | } |
140 | #endif |
141 | |
142 | #endif |