Added SILC Thread Queue API
[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, SilcStack stack);
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.  Returns NULL if system is out of memory.
48  *
49  *    If the silc_stream_set_notifier is called the stream is set to
50  *    non-blocking mode.
51  *
52  *    If `stack' is non-NULL all memory is allocated from the `stack' and
53  *    will be released back to `stack' after the stream is destroyed.
54  *
55  ***/
56 SilcStream silc_fd_stream_create(int fd, SilcStack stack);
57
58 /****f* silcutil/SilcFDStreamAPI/silc_fd_stream_create2
59  *
60  * SYNOPSIS
61  *
62  *    SilcStream silc_fd_stream_create2(int read_fd, int write_fd,
63  *                                      SilcStack stack);
64  *
65  * DESCRIPTION
66  *
67  *    Creates file descriptor stream for the open file descriptors indicated
68  *    by `read_fd' and `write_fd'.  The `read_fd' must be opened for reading
69  *    and `write_fd' opened for writing.  The stream is closed with the
70  *    silc_stream_close and destroyed with the silc_stream_destroy.  Returns
71  *    NULL if system is out of memory.
72  *
73  *    If the silc_stream_set_notifier is called the stream is set to
74  *    non-blocking mode.
75  *
76  *    If `stack' is non-NULL all memory is allocated from the `stack' and
77  *    will be released back to `stack' after the stream is destroyed.
78  *
79  ***/
80 SilcStream silc_fd_stream_create2(int read_fd, int write_fd, SilcStack stack);
81
82 /****f* silcutil/SilcFDStreamAPI/silc_fd_stream_file
83  *
84  * SYNOPSIS
85  *
86  *    SilcStream silc_fd_stream_file(const char *filename, SilcBool reading,
87  *                                   SilcBool writing, SilcStack stack);
88  *
89  * DESCRIPTION
90  *
91  *    Same as silc_fd_stream_create but creates the stream by opening the
92  *    file indicated by `filename'.  If the `reading' is TRUE the file is
93  *    opened for reading.  If the `writing' is TRUE the file is opened
94  *    for writing.  Returns NULL if system is out of memory.
95  *
96  *    If the silc_stream_set_notifier is called the stream is set to
97  *    non-blocking mode.
98  *
99  *    If `stack' is non-NULL all memory is allocated from the `stack' and
100  *    will be released back to `stack' after the stream is destroyed.
101  *
102  ***/
103 SilcStream silc_fd_stream_file(const char *filename, SilcBool reading,
104                                SilcBool writing, SilcStack stack);
105
106 /****f* silcutil/SilcFDStreamAPI/silc_fd_stream_file2
107  *
108  * SYNOPSIS
109  *
110  *    SilcStream silc_fd_stream_file2(const char *read_file,
111  *                                    const char *write_file,
112  *                                    SilcStack stack);
113  *
114  * DESCRIPTION
115  *
116  *    Same as silc_fd_stream_file but creates the stream by opening `read_file'
117  *    for reading and `write_file' for writing.  Returns NULL if system is
118  *    out of memory.
119  *
120  *    If the silc_stream_set_notifier is called the stream is set to
121  *    non-blocking mode.
122  *
123  *    If `stack' is non-NULL all memory is allocated from the `stack' and
124  *    will be released back to `stack' after the stream is destroyed.
125  *
126  ***/
127 SilcStream silc_fd_stream_file2(const char *read_file, const char *write_file,
128                                 SilcStack stack);
129
130 /****f* silcutil/SilcFDStreamAPI/silc_fd_stream_get_info
131  *
132  * SYNOPSIS
133  *
134  *    SilcBool
135  *    silc_fd_stream_get_info(SilcStream stream, int *read_fd, int *write_fd);
136  *
137  * DESCRIPTION
138  *
139  *    Returns the file descriptors associated with the stream.  The 'write_fd'
140  *    is available only if the stream was created with silc_fd_stream_create2
141  *    function.  Returns FALSE if the information is not available.
142  *
143  ***/
144 SilcBool silc_fd_stream_get_info(SilcStream stream,
145                                  int *read_fd, int *write_fd);
146
147 /* Backwards support */
148 #define silc_fd_stream_get_error(stream) silc_errno
149
150 #endif /* SILCFDSTREAM_H */