fc1a4c8f243dd4fd529250d918cc4ee3f18213ef
[silc.git] / lib / silcutil / silcfdstream.h
1 /*
2
3   silcfdstream.h
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 2005 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, SilcSchedule schedule);
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  ***/
50 SilcStream silc_fd_stream_create(int fd, SilcSchedule schedule);
51
52 /****f* silcutil/SilcFDStreamAPI/silc_fd_stream_create2
53  *
54  * SYNOPSIS
55  *
56  *    SilcStream silc_fd_stream_create2(int read_fd, int write_fd,
57  *                                      SilcSchedule schedule);
58  *
59  * DESCRIPTION
60  *
61  *    Creates file descriptor stream for the open file descriptors indicated
62  *    by `read_fd' and `write_fd'.  The `read_fd' must be opened for reading
63  *    and `write_fd' opened for writing.  The stream is closed with the
64  *    silc_stream_close and destroyed with the silc_stream_destroy.
65  *
66  ***/
67 SilcStream silc_fd_stream_create2(int read_fd, int write_fd,
68                                   SilcSchedule schedule);
69
70 /****f* silcutil/SilcFDStreamAPI/silc_fd_stream_file
71  *
72  * SYNOPSIS
73  *
74  *    SilcStream silc_fd_stream_file(const char *filename, SilcBool reading,
75  *                                   SilcBool writing, SilcSchedule schedule);
76  *
77  * DESCRIPTION
78  *
79  *    Same as silc_fd_stream_create but creates the stream by opening the
80  *    file indicated by `filename'.  If the `reading' is TRUE the file is
81  *    opened for reading.  If the `writing' is TRUE the file is opened
82  *    for writing.
83  *
84  ***/
85 SilcStream silc_fd_stream_file(const char *filename, SilcBool reading, 
86                                SilcBool writing, SilcSchedule schedule);
87
88 /****f* silcutil/SilcFDStreamAPI/silc_fd_stream_get_info
89  *
90  * SYNOPSIS
91  *
92  *    SilcBool
93  *    silc_fd_stream_get_info(SilcStream stream, int *read_fd, int *write_fd);
94  *
95  * DESCRIPTION
96  *
97  *    Returns the file descriptors associated with the stream.  The 'write_fd'
98  *    is available only if the stream was created with silc_fd_stream_create2
99  *    function.
100  *
101  ***/
102 SilcBool silc_fd_stream_get_info(SilcStream stream, int *read_fd, int *write_fd);
103
104 /****f* silcutil/SilcFDStreamAPI/silc_fd_stream_get_error
105  *
106  * SYNOPSIS
107  *
108  *    int silc_fd_stream_get_error(SilcStream stream);
109  *
110  * DESCRIPTION
111  *
112  *    If error occurred during file descriptor stream operations, this
113  *    function can be used to retrieve the error number that occurred.
114  *
115  ***/
116 int silc_fd_stream_get_error(SilcStream stream);
117
118 #endif /* SILCFDSTREAM_H */