Added silc_thread_yield.
[silc.git] / lib / silcutil / silcfdstream.h
1 /*
2
3   silcfdstream.h
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 2005 - 2007 Pekka Riikonen
8
9   This program is free software; you can redistribute it and/or modify
10   it under the terms of the GNU General Public License as published by
11   the Free Software Foundation; version 2 of the License.
12
13   This program is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   GNU General Public License for more details.
17
18 */
19
20 /****h* silcutil/SILC File Descriptor Stream Interface
21  *
22  * DESCRIPTION
23  *
24  * Implementation of SILC File Descriptor Stream.  The file descriptor
25  * stream can be used read from and write to a file descriptor.  This
26  * interface should be used only with real file descriptors, not with
27  * sockets.  Use the SILC Socket Stream for sockets.
28  *
29  * SILC File Descriptor Stream is not thread-safe.  If same stream must be
30  * used in multithreaded environment concurrency control must be employed.
31  *
32  ***/
33
34 #ifndef SILCFDSTREAM_H
35 #define SILCFDSTREAM_H
36
37 /****f* silcutil/SilcFDStreamAPI/silc_fd_stream_create
38  *
39  * SYNOPSIS
40  *
41  *    SilcStream silc_fd_stream_create(int fd);
42  *
43  * DESCRIPTION
44  *
45  *    Creates file descriptor stream for the open file descriptor indicated
46  *    by `fd'.  The stream is closed with the silc_stream_close and destroyed
47  *    with the silc_stream_destroy.
48  *
49  *    The silc_stream_set_notifier must be called in order to be able to read
50  *    from and write to this file descriptor stream if the `fd' is in
51  *    non-blocking mode.
52  *
53  ***/
54 SilcStream silc_fd_stream_create(int fd);
55
56 /****f* silcutil/SilcFDStreamAPI/silc_fd_stream_create2
57  *
58  * SYNOPSIS
59  *
60  *    SilcStream silc_fd_stream_create2(int read_fd, int write_fd);
61  *
62  * DESCRIPTION
63  *
64  *    Creates file descriptor stream for the open file descriptors indicated
65  *    by `read_fd' and `write_fd'.  The `read_fd' must be opened for reading
66  *    and `write_fd' opened for writing.  The stream is closed with the
67  *    silc_stream_close and destroyed with the silc_stream_destroy.
68  *
69  *    The silc_stream_set_notifier must be called in order to be able to read
70  *    from and write to this file descriptor stream if the `fd' is in
71  *    non-blocking mode.
72  *
73  ***/
74 SilcStream silc_fd_stream_create2(int read_fd, int write_fd);
75
76 /****f* silcutil/SilcFDStreamAPI/silc_fd_stream_file
77  *
78  * SYNOPSIS
79  *
80  *    SilcStream silc_fd_stream_file(const char *filename, SilcBool reading,
81  *                                   SilcBool writing);
82  *
83  * DESCRIPTION
84  *
85  *    Same as silc_fd_stream_create but creates the stream by opening the
86  *    file indicated by `filename'.  If the `reading' is TRUE the file is
87  *    opened for reading.  If the `writing' is TRUE the file is opened
88  *    for writing.
89  *
90  *    The silc_stream_set_notifier must be called in order to be able to read
91  *    from and write to this file descriptor stream if the `fd' is in
92  *    non-blocking mode.
93  *
94  ***/
95 SilcStream silc_fd_stream_file(const char *filename, SilcBool reading,
96                                SilcBool writing);
97
98 /****f* silcutil/SilcFDStreamAPI/silc_fd_stream_get_info
99  *
100  * SYNOPSIS
101  *
102  *    SilcBool
103  *    silc_fd_stream_get_info(SilcStream stream, int *read_fd, int *write_fd);
104  *
105  * DESCRIPTION
106  *
107  *    Returns the file descriptors associated with the stream.  The 'write_fd'
108  *    is available only if the stream was created with silc_fd_stream_create2
109  *    function.
110  *
111  ***/
112 SilcBool silc_fd_stream_get_info(SilcStream stream,
113                                  int *read_fd, int *write_fd);
114
115 /****f* silcutil/SilcFDStreamAPI/silc_fd_stream_get_error
116  *
117  * SYNOPSIS
118  *
119  *    int silc_fd_stream_get_error(SilcStream stream);
120  *
121  * DESCRIPTION
122  *
123  *    If error occurred during file descriptor stream operations, this
124  *    function can be used to retrieve the error number that occurred.
125  *
126  ***/
127 int silc_fd_stream_get_error(SilcStream stream);
128
129 #endif /* SILCFDSTREAM_H */