Added SILC Thread Queue API
[silc.git] / lib / silcutil / silcsocketstream_i.h
1 /*
2
3   silcsocketstream_i.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 #ifndef SILCSOCKETSTREAM_I_H
21 #define SILCSOCKETSTREAM_I_H
22
23 #ifndef SILCSOCKETSTREAM_H
24 #error "Do not include this header directly"
25 #endif
26
27 typedef struct SilcSocketStreamStruct *SilcSocketStream;
28
29 /* Qos context */
30 typedef struct SilcSocketQosStruct {
31   SilcUInt16 read_limit_bytes;      /* Max read bytes */
32   SilcUInt16 read_rate;             /* Max read rate/second */
33   SilcUInt16 limit_sec;             /* Limit seconds */
34   SilcUInt32 limit_usec;            /* Limit microseconds */
35   struct timeval next_limit;
36   unsigned int cur_rate : 31;
37   unsigned int applied  : 1;
38   SilcUInt32 data_len;
39   unsigned char *buffer;
40   SilcSocketStream sock;
41 } *SilcSocketQos;
42
43 /* SILC Socket Stream context */
44 struct SilcSocketStreamStruct {
45   const SilcStreamOps *ops;
46   SilcSchedule schedule;
47   SilcSocket sock;
48   char *hostname;
49   char *ip;
50   SilcSocketQos qos;
51   SilcStreamNotifier notifier;
52   void *notifier_context;
53   SilcUInt16 port;
54   unsigned int ipv6      : 1;       /* UDP IPv6 */
55   unsigned int connected : 1;       /* UDP connected state */
56 };
57
58 #define SILC_IS_SOCKET_STREAM(s) (s->ops == &silc_socket_stream_ops)
59 #define SILC_IS_SOCKET_STREAM_UDP(s) (s->ops == &silc_socket_udp_stream_ops)
60
61 extern const SilcStreamOps silc_socket_stream_ops;
62 extern const SilcStreamOps silc_socket_udp_stream_ops;
63
64 /* Backwards support */
65 #define SilcSocketStreamStatus SilcResult
66 #define silc_socket_stream_get_error(stream) silc_errno
67 #define SILC_SOCKET_OK SILC_OK
68 #define SILC_SOCKET_UNKNOWN_IP SILC_ERR_UNKNOWN_IP
69 #define SILC_SOCKET_UNKNOWN_HOST SILC_ERR_UNKNOWN_HOST
70 #define SILC_SOCKET_NO_MEMORY SILC_ERR_OUT_OF_MEMORY
71 #define SILC_SOCKET_ERROR SILC_ERR
72
73 #endif /* SILCSOCKETSTREAM_I_H */