5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2005 Pekka Riikonen
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.
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.
20 /****h* silcutil/SILC Socket Stream Interface
24 * Implementation of SILC Socket Stream. SILC Socket Stream can be used
25 * read data from and write data to a socket connection. The SILC Socket
26 * Stream provides also Quality of Service (QoS) support that can be used
27 * to control the throughput of the stream.
29 * SILC Socket Stream is not thread-safe. If the same socket stream must be
30 * used in multithreaded environment concurrency control must be employed.
34 #ifndef SILCSOCKETSTREAM_H
35 #define SILCSOCKETSTREAM_H
37 /****d* silcutil/SilcSocketStreamAPI/SilcSocketStreamStatus
41 * typedef enum { ... } SilcStreamStatus;
45 * Socket Stream status. This status is returned into the
46 * SilcSocketStreamCallback function after the socket stream is
52 SILC_SOCKET_OK, /* Normal status */
53 SILC_SOCKET_UNKNOWN_IP, /* Remote does not have IP address */
54 SILC_SOCKET_UNKNOWN_HOST, /* Remote does not have host name */
55 SILC_SOCKET_NO_MEMORY, /* System out of memory */
56 SILC_SOCKET_ERROR, /* Unknown error */
57 } SilcSocketStreamStatus;
60 /****f* silcutil/SilcSocketStreamAPI/SilcSocketStreamCallback
64 * typedef void (*SilcSocketStreamCallback)(SilcSocketStreamStatus status,
70 * Callback function of this type is called after the socket stream
71 * creation is completed. If the `stream' is NULL the socket stream could
72 * not be created of the socket connection is not otherwise allowed. The
73 * `status' will indicate the error status. The `stream' is socket stream
74 * representing the socket connection and silc_socket_stream_* functions
75 * can be used to access the stream. All other silc_stream_* functions
76 * can also be used to read data, send data, and otherwise handle the
80 typedef void (*SilcSocketStreamCallback)(SilcSocketStreamStatus status,
81 SilcStream stream, void *context);
83 /****f* silcutil/SilcSocketStreamAPI/silc_socket_stream_create
88 * silc_socket_stream_create(int sock, SilcBool lookup, SilcBool require_fqdn,
89 * SilcSchedule schedule,
90 * SilcSocketStreamCallback callback,
95 * Creates new socket stream of the socket connection indicated by `sock'.
96 * The stream can be destroyed by calling the silc_stream_destroy. Data
97 * can be sent and received from the stream by calling silc_stream_write
98 * and silc_stream_read. The creation process is asynchronous since
99 * socket connection information, such as hostname and IP address are
100 * resolved, so SilcAsyncOperation is returned which can be used to cancel
101 * the creationg process. The `callback' will be called to return the
102 * created socket stream. To destroy the stream call silc_stream_destroy.
104 * If the `lookup' is TRUE then this will performed IP and hostname lookup
105 * for the socket. If the `require_fqdn' is TRUE then the socket must
106 * have valid hostname and IP address, otherwise the stream creation will
107 * fail. If it is FALSE then only valid IP address is required. Note that,
108 * if the `lookup' is FALSE then the hostname, IP and port information
109 * will not be available from the socket stream.
113 silc_socket_stream_create(int sock, SilcBool lookup, SilcBool require_fqdn,
114 SilcSchedule schedule,
115 SilcSocketStreamCallback callback,
118 /****f* silcutil/SilcSocketStreamAPI/silc_socket_stream_get_info
123 * silc_socket_stream_get_info(SilcStream stream,
124 * int *sock, const char **hostname,
125 * const char **ip, SilcUInt16 *port);
129 * Returns socket stream information such as the socket number, hostname,
130 * IP address and the port of the remote socket connection. Return FALSE
131 * if these informations are not available.
134 SilcBool silc_socket_stream_get_info(SilcStream stream,
135 int *sock, const char **hostname,
136 const char **ip, SilcUInt16 *port);
138 /****f* silcutil/SilcSocketStreamAPI/silc_socket_stream_set_info
143 * silc_socket_stream_set_info(SilcStream stream,
144 * const char *hostname,
145 * const char *ip, SilcUInt16 port);
149 * Use this function to set the hostname, IP address and remote port
150 * information to the socket stream indicated by `stream' if you did not
151 * perform lookup in the silc_socket_create_stream. This is not mandatory
152 * but if you would like to associate the information with the stream
153 * use this function. If the lookup was performed when creating the
154 * stream then calling this function is not necessary. Use the function
155 * silc_socket_stream_get_info to get the information from the stream.
158 SilcBool silc_socket_stream_set_info(SilcStream stream,
159 const char *hostname,
160 const char *ip, SilcUInt16 port);
162 /****f* silcutil/SilcSocketStreamAPI/silc_socket_stream_get_error
166 * int silc_socket_stream_get_error(SilcStream stream);
170 * If error occurred during socket stream operations, this function
171 * can be used to retrieve the error number that occurred.
174 int silc_socket_stream_get_error(SilcStream stream);
176 /****f* silcutil/SilcSocketStreamAPI/silc_socket_stream_set_qos
180 * SilcBool silc_socket_stream_set_qos(SilcStream stream,
181 * SilcUInt32 read_rate,
182 * SilcUInt32 read_limit_bytes,
183 * SilcUInt32 limit_sec,
184 * SilcUInt32 limit_usec)
188 * Sets a "Quality of Service" settings for socket stream `stream'.
189 * The `read_rate' specifies the maximum read operations per second.
190 * If more read operations are executed the limit will be applied for
191 * the reading. The `read_limit_bytes' specifies the maximum data
192 * that is read. It is guaranteed that silc_stream_read never returns
193 * more than `read_limit_bytes' of data. The `limit_sec' and `limit_usec'
194 * specifies the time limit that is applied if `read_rate' and/or
195 * `read_limit_bytes' is reached. If all arguments except `stream'
196 * are zero this resets the QoS from the socket stream, all QoS for
197 * this socket stream that may be pending will be cancelled.
200 SilcBool silc_socket_stream_set_qos(SilcStream stream,
201 SilcUInt32 read_rate,
202 SilcUInt32 read_limit_bytes,
203 SilcUInt32 limit_sec,
204 SilcUInt32 limit_usec);
206 #include "silcsocketstream_i.h"
208 #endif /* SILCSOCKETSTREAM_H */