Revert mistaken change: it is UNIX, not Unix.
[platform/upstream/glib.git] / docs / reference / glib / tmpl / iochannels.sgml
1 <!-- ##### SECTION Title ##### -->
2 IO Channels
3
4 <!-- ##### SECTION Short_Description ##### -->
5 portable support for using files, pipes and sockets.
6
7 <!-- ##### SECTION Long_Description ##### -->
8 <para>
9 The #GIOChannel data type aims to provide a portable method for using file
10 descriptors, pipes, and sockets, and integrating them into the
11 <link linkend="glib-The-Main-Event-Loop">main event loop</link>.
12 Currently full support is available on UNIX platforms, support for
13 Windows is only partially complete.
14 </para>
15 <para>
16 To create a new #GIOChannel on UNIX systems use g_io_channel_unix_new().
17 This works for plain file descriptors, pipes and sockets.
18 Alternatively, a channel can be created for a file in a system independent
19 manner using g_io_channel_new_file().
20 </para>
21 <para>
22 Once a #GIOChannel has been created, it can be used in a generic manner
23 with the functions g_io_channel_read_chars(), g_io_channel_write_chars(),
24 g_io_channel_seek_position(), and g_io_channel_close().
25 </para>
26 <para>
27 To add a #GIOChannel to the 
28 <link linkend="glib-The-Main-Event-Loop">main event loop</link>
29 use g_io_add_watch() or g_io_add_watch_full(). Here you specify which events
30 you are interested in on the #GIOChannel, and provide a function to be
31 called whenever these events occur.
32 </para>
33 <para>
34 #GIOChannel instances are created with an initial reference count of 1.
35 g_io_channel_ref() and g_io_channel_unref() can be used to increment or
36 decrement the reference count respectively. When the reference count falls
37 to 0, the #GIOChannel is freed. (Though it isn't closed automatically,
38 unless it was created using g_io_channel_new_from_file().)
39 Using g_io_add_watch() or g_io_add_watch_full() increments a channel's
40 reference count.
41 </para>
42 <para>
43 GTK+ contains the convenience function gtk_input_add_full()
44 which creates a #GIOChannel from a file descriptor and adds it to the
45 <link linkend="glib-The-Main-Event-Loop">main event loop</link>.
46 The event source can later be removed with gtk_input_remove().
47 Similar functions can also be found in GDK.
48 </para>
49 <para>
50 The new functions g_io_channel_read_chars(), g_io_channel_read_line(),
51 g_io_channel_read_line_string(), g_io_channel_read_to_end(),
52 g_io_channel_write_chars(), g_io_channel_seek_position(),
53 and g_io_channel_flush() should not be mixed with the
54 deprecated functions g_io_channel_read(), g_io_channel_write(),
55 and g_io_channel_seek() on the same channel.
56 </para>
57
58 <!-- ##### SECTION See_Also ##### -->
59 <para>
60 <variablelist>
61
62 <varlistentry>
63 <term>gtk_input_add_full(), gtk_input_remove(), gdk_input_add(),
64 gdk_input_add_full(), gdk_input_remove()</term>
65 <listitem><para>
66 Convenience functions for creating #GIOChannel instances and adding them to the
67 <link linkend="glib-The-Main-Event-Loop">main event loop</link>.
68 </para></listitem>
69 </varlistentry>
70
71 </variablelist>
72 </para>
73
74 <!-- ##### STRUCT GIOChannel ##### -->
75 <para>
76 A data structure representing an IO Channel. The fields should be considered
77 private and should only be accessed with the following functions.
78 </para>
79
80
81 <!-- ##### FUNCTION g_io_channel_unix_new ##### -->
82 <para>
83 Creates a new #GIOChannel given a file descriptor.
84 On UNIX systems this works for plain files, pipes, and sockets.
85 </para>
86 <para>
87 The returned #GIOChannel has a reference count of 1.
88 </para>
89
90 @fd: a file descriptor.
91 @Returns: a new #GIOChannel.
92
93
94 <!-- ##### FUNCTION g_io_channel_unix_get_fd ##### -->
95 <para>
96 Returns the file descriptor of the UNIX #GIOChannel.
97 </para>
98
99 @channel: a #GIOChannel, created with g_io_channel_unix_new().
100 @Returns: the file descriptor of the #GIOChannel.
101
102
103 <!-- ##### FUNCTION g_io_channel_init ##### -->
104 <para>
105 Initializes a #GIOChannel struct. This is called by each of the above functions
106 when creating a #GIOChannel, and so is not often needed by the application
107 programmer (unless you are creating a new type of #GIOChannel).
108 </para>
109
110 @channel: a #GIOChannel.
111
112
113 <!-- ##### FUNCTION g_io_channel_new_file ##### -->
114 <para>
115 </para>
116
117 @filename: 
118 @mode: 
119 @error: 
120 @Returns: 
121
122
123 <!-- ##### FUNCTION g_io_channel_read_chars ##### -->
124 <para>
125
126 </para>
127
128 @channel: 
129 @buf: 
130 @count: 
131 @bytes_read: 
132 @error: 
133 @Returns: 
134
135
136 <!-- ##### FUNCTION g_io_channel_read_unichar ##### -->
137 <para>
138
139 </para>
140
141 @channel: 
142 @thechar: 
143 @error: 
144 @Returns: 
145
146
147 <!-- ##### FUNCTION g_io_channel_read_line ##### -->
148 <para>
149
150 </para>
151
152 @channel: 
153 @str_return: 
154 @length: 
155 @terminator_pos: 
156 @error: 
157 @Returns: 
158
159
160 <!-- ##### FUNCTION g_io_channel_read_line_string ##### -->
161 <para>
162
163 </para>
164
165 @channel: 
166 @buffer: 
167 @terminator_pos: 
168 @error: 
169 @Returns: 
170
171
172 <!-- ##### FUNCTION g_io_channel_read_to_end ##### -->
173 <para>
174
175 </para>
176
177 @channel: 
178 @str_return: 
179 @length: 
180 @error: 
181 @Returns: 
182
183
184 <!-- ##### FUNCTION g_io_channel_write_chars ##### -->
185 <para>
186
187 </para>
188
189 @channel: 
190 @buf: 
191 @count: 
192 @bytes_written: 
193 @error: 
194 @Returns: 
195
196
197 <!-- ##### FUNCTION g_io_channel_write_unichar ##### -->
198 <para>
199
200 </para>
201
202 @channel: 
203 @thechar: 
204 @error: 
205 @Returns: 
206
207
208 <!-- ##### FUNCTION g_io_channel_flush ##### -->
209 <para>
210
211 </para>
212
213 @channel: 
214 @error: 
215 @Returns: 
216
217
218 <!-- ##### FUNCTION g_io_channel_seek_position ##### -->
219 <para>
220
221 </para>
222
223 @channel: 
224 @offset: 
225 @type: 
226 @error: 
227 @Returns: 
228
229
230 <!-- ##### ENUM GSeekType ##### -->
231 <para>
232 An enumeration specifying the base position for a g_io_channel_seek_position()
233 operation.
234 </para>
235
236 @G_SEEK_CUR: the current position in the file.
237 @G_SEEK_SET: the start of the file.
238 @G_SEEK_END: the end of the file.
239
240 <!-- ##### FUNCTION g_io_channel_shutdown ##### -->
241 <para>
242
243 </para>
244
245 @channel: 
246 @flush: 
247 @err: 
248 @Returns: 
249
250
251 <!-- ##### ENUM GIOStatus ##### -->
252 <para>
253 Stati returned by most of the #GIOFuncs functions. 
254 </para>
255
256 @G_IO_STATUS_ERROR: An error occurred.
257 @G_IO_STATUS_NORMAL: Success.
258 @G_IO_STATUS_EOF: End of file.
259 @G_IO_STATUS_AGAIN: Resource temporarily unavailable.
260
261 <!-- ##### ENUM GIOChannelError ##### -->
262 <para>
263 Error codes returned by #GIOChannel operations.
264 </para>
265
266 @G_IO_CHANNEL_ERROR_FBIG: File too large.
267 @G_IO_CHANNEL_ERROR_INVAL: Invalid argument.
268 @G_IO_CHANNEL_ERROR_IO: IO error.
269 @G_IO_CHANNEL_ERROR_ISDIR: File is a directory.
270 @G_IO_CHANNEL_ERROR_NOSPC: No space left on device.
271 @G_IO_CHANNEL_ERROR_NXIO: No such device or address.
272 @G_IO_CHANNEL_ERROR_OVERFLOW: Value too large for defined datatype.
273 @G_IO_CHANNEL_ERROR_PIPE: Broken pipe.
274 @G_IO_CHANNEL_ERROR_FAILED: Some other error.
275
276 <!-- ##### MACRO G_IO_CHANNEL_ERROR ##### -->
277 <para>
278 Error domain for #GIOChannel operations. Errors in this domain will
279 be from the #IOChannelError enumeration. See #GError for information on
280 error domains.
281 </para>
282
283
284
285 <!-- ##### FUNCTION g_io_channel_error_from_errno ##### -->
286 <para>
287
288 </para>
289
290 @en: 
291 @Returns: 
292
293
294 <!-- ##### FUNCTION g_io_channel_ref ##### -->
295 <para>
296 Increments the reference count of a #GIOChannel.
297 </para>
298
299 @channel: a #GIOChannel.
300
301
302 <!-- ##### FUNCTION g_io_channel_unref ##### -->
303 <para>
304 Decrements the reference count of a #GIOChannel.
305 </para>
306
307 @channel: a #GIOChannel.
308
309
310 <!-- ##### FUNCTION g_io_create_watch ##### -->
311 <para>
312 Creates a #GSource that's dispatched when @condition is met for the given
313 @channel. For example, if condition is #G_IO_IN, the source will be dispatched
314 when there's data available for reading.  g_io_add_watch() is a simpler
315 interface to this same functionality, for the case where you want to add the
316 source to the default main loop at the default priority.
317 </para>
318
319 @channel: a #GIOChannel to watch
320 @condition: conditions to watch for
321 @Returns: a new #GSource
322
323
324 <!-- ##### FUNCTION g_io_add_watch ##### -->
325 <para>
326 Adds the #GIOChannel into the
327 <link linkend="glib-The-Main-Event-Loop">main event loop</link>
328 with the default priority.
329 </para>
330
331 @channel: a #GIOChannel.
332 @condition: the condition to watch for.
333 @func: the function to call when the condition is satisfied.
334 @user_data: user data to pass to @func.
335 @Returns: the event source id.
336
337
338 <!-- ##### FUNCTION g_io_add_watch_full ##### -->
339 <para>
340 Adds the #GIOChannel into the
341 <link linkend="glib-The-Main-Event-Loop">main event loop</link>
342 with the given priority.
343 </para>
344
345 @channel: a #GIOChannel.
346 @priority: the priority of the #GIOChannel source.
347 @condition: the condition to watch for.
348 @func: the function to call when the condition is satisfied.
349 @user_data: user data to pass to @func.
350 @notify: the function to call when the source is removed.
351 @Returns: the event source id.
352
353
354 <!-- ##### ENUM GIOCondition ##### -->
355 <para>
356 A bitwise combination representing a condition to watch for on an event
357 source.
358 </para>
359
360 @G_IO_IN: There is data to read.
361 @G_IO_OUT: Data can be written (without blocking).
362 @G_IO_PRI: There is urgent data to read.
363 @G_IO_ERR: Error condition.
364 @G_IO_HUP: Hung up (the connection has been broken, usually for pipes 
365            and sockets).
366 @G_IO_NVAL: Invalid request. The file descriptor is not open.
367
368 <!-- ##### USER_FUNCTION GIOFunc ##### -->
369 <para>
370 Specifies the type of function passed to g_io_add_watch() or
371 g_io_add_watch_full(), which is called when the requested condition on a
372 #GIOChannel is satisfied.
373 </para>
374
375 @source: the #GIOChannel event source.
376 @condition: the condition which has been satisfied.
377 @data: user data set in g_io_add_watch() or g_io_add_watch_full().
378 @Returns: the function should return %FALSE if the event source should be
379 removed.
380
381
382 <!-- ##### STRUCT GIOFuncs ##### -->
383 <para>
384 A table of functions used to handle different types of #GIOChannel in a
385 generic way.
386 </para>
387
388 @io_read: 
389 @io_write: 
390 @io_seek: 
391 @io_close: 
392 @io_create_watch: 
393 @io_free: 
394 @io_set_flags: 
395 @io_get_flags: 
396
397 <!-- ##### FUNCTION g_io_channel_get_buffer_size ##### -->
398 <para>
399
400 </para>
401
402 @channel: 
403 @Returns: 
404
405
406 <!-- ##### FUNCTION g_io_channel_set_buffer_size ##### -->
407 <para>
408
409 </para>
410
411 @channel: 
412 @size: 
413
414
415 <!-- ##### FUNCTION g_io_channel_get_buffer_condition ##### -->
416 <para>
417
418 </para>
419
420 @channel: 
421 @Returns: 
422
423
424 <!-- ##### FUNCTION g_io_channel_get_flags ##### -->
425 <para>
426
427 </para>
428
429 @channel: 
430 @Returns: 
431
432
433 <!-- ##### FUNCTION g_io_channel_set_flags ##### -->
434 <para>
435
436 </para>
437
438 @channel: 
439 @flags: 
440 @error: 
441 @Returns: 
442
443
444 <!-- ##### ENUM GIOFlags ##### -->
445 <para>
446 Specifies properties of a #GIOChannel. Some of the flags can only
447 be read with g_io_channel_get_flags(), but not changed with
448 g_io_channel_set_flags(). 
449 </para>
450
451 @G_IO_FLAG_APPEND: turns on append mode, corresponds to %O_APPEND (see the 
452    documentation of the UNIX <function>open()</function> syscall).
453 @G_IO_FLAG_NONBLOCK: turns on nonblocking mode, corresponds to 
454    %O_NONBLOCK/%O_NDELAY (see the documentation of the UNIX 
455    <function>open()</function> syscall).
456 @G_IO_FLAG_IS_READABLE: indicates that the io channel is readable. This flag 
457    can not be changed.
458 @G_IO_FLAG_IS_WRITEABLE: indicates that the io channel is writable. This flag 
459    can not be changed.
460 @G_IO_FLAG_IS_SEEKABLE: indicates that the io channel is seekable, i.e. that 
461    g_io_channel_seek_position() can be used on it. This flag can not be changed.
462 @G_IO_FLAG_MASK: 
463 @G_IO_FLAG_GET_MASK: 
464 @G_IO_FLAG_SET_MASK: 
465
466 <!-- ##### FUNCTION g_io_channel_get_line_term ##### -->
467 <para>
468
469 </para>
470
471 @channel: 
472 @length: 
473 @Returns: 
474
475
476 <!-- ##### FUNCTION g_io_channel_set_line_term ##### -->
477 <para>
478
479 </para>
480
481 @channel: 
482 @line_term: 
483 @length: 
484
485
486 <!-- ##### FUNCTION g_io_channel_get_buffered ##### -->
487 <para>
488
489 </para>
490
491 @channel: 
492 @Returns: 
493
494
495 <!-- ##### FUNCTION g_io_channel_set_buffered ##### -->
496 <para>
497
498 </para>
499
500 @channel: 
501 @buffered: 
502
503
504 <!-- ##### FUNCTION g_io_channel_get_encoding ##### -->
505 <para>
506
507 </para>
508
509 @channel: 
510 @Returns: 
511
512
513 <!-- ##### FUNCTION g_io_channel_set_encoding ##### -->
514 <para>
515
516 </para>
517
518 @channel: 
519 @encoding: 
520 @error: 
521 @Returns: 
522
523
524 <!-- ##### FUNCTION g_io_channel_get_close_on_unref ##### -->
525 <para>
526
527 </para>
528
529 @channel: 
530 @Returns: 
531
532
533 <!-- ##### FUNCTION g_io_channel_set_close_on_unref ##### -->
534 <para>
535
536 </para>
537
538 @channel: 
539 @do_close: 
540
541
542 <!-- ##### FUNCTION g_io_channel_read ##### -->
543 <para>
544 </para>
545
546 @channel: 
547 @buf: 
548 @count: 
549 @bytes_read: 
550 @Returns: 
551
552
553 <!-- ##### ENUM GIOError ##### -->
554 <para>
555 #GIOError is only used by the deprecated functions g_io_channel_read(),
556 g_io_channel_write(), and g_io_channel_seek().
557 </para>
558
559 @G_IO_ERROR_NONE: 
560 @G_IO_ERROR_AGAIN: 
561 @G_IO_ERROR_INVAL: 
562 @G_IO_ERROR_UNKNOWN: 
563
564 <!-- ##### FUNCTION g_io_channel_write ##### -->
565 <para>
566 </para>
567
568 @channel: 
569 @buf: 
570 @count: 
571 @bytes_written: 
572 @Returns: 
573
574
575 <!-- ##### FUNCTION g_io_channel_seek ##### -->
576 <para>
577 </para>
578
579 @channel: 
580 @offset: 
581 @type.
582 @type: 
583 @Returns: 
584
585
586 <!-- ##### FUNCTION g_io_channel_close ##### -->
587 <para>
588 </para>
589
590 @channel: 
591
592