5 Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
7 Copyright (C) 1997 - 2000 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; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
21 #ifndef SILCSOCKCONN_H
22 #define SILCSOCKCONN_H
24 /* Forward declarations */
25 typedef struct SilcSocketConnectionStruct *SilcSocketConnection;
26 typedef struct SilcSocketConnectionHB *SilcSocketConnectionHB;
28 /* Socket types. These identifies the socket connection. */
30 SILC_SOCKET_TYPE_UNKNOWN = 0,
31 SILC_SOCKET_TYPE_CLIENT = 1,
32 SILC_SOCKET_TYPE_SERVER = 2,
33 SILC_SOCKET_TYPE_ROUTER = 3
37 #define SILC_SF_NONE 0
38 #define SILC_SF_INBUF_PENDING 1
39 #define SILC_SF_OUTBUF_PENDING 2
40 #define SILC_SF_DISCONNECTING 3
41 #define SILC_SF_DISCONNECTED 4
43 /* Heartbeat callback function. This is the function in the application
44 that this library will call when it is time to send the keepalive
45 packet SILC_PACKET_HEARTBEAT. */
46 typedef void (*SilcSocketConnectionHBCb)(SilcSocketConnection sock,
50 SILC Socket Connection object.
52 This object holds information about the connected sockets to the server.
53 This is quite important object since this is referenced by the server all
54 the time when figuring out what the connection is supposed to be doing
55 and to whom we should send a message.
57 Following short description of the fields:
61 The actual connected socket. This is usually saved when accepting
62 new connection to the server.
66 Type of the socket. This identifies the type of the connection. This
67 is mainly used to identify whether the connection is a client or a
72 This is a pointer to a data that is is saved here at the same
73 time a new connection object is allocated. Usually this is a
74 back-pointer to some important data for fast referencing. For
75 SILC server this is a pointer to the ID list and for SILC client
76 to object holding active connections (windows).
80 Protocol object for the socket. Currently only one protocol can be
81 executing at a time for a particular socket.
85 Socket flags that indicate the status of the socket. This can
86 indicate several different status that can affect the use of the
91 Reference counter. When allocated it is set to one (1) and it won't
92 be freed until it hits zero (0).
98 Resolved hostname, IP address and port of the connection who owns
104 Incoming and outgoing buffers for the particular socket connection.
105 Incoming data from the socket is put after decryption in to the
106 inbuf buffer and outgoing data after encryption is put to the outbuf
109 SilcSocketConnectionHB hb
111 The heartbeat context. If NULL, heartbeat is not performed.
114 struct SilcSocketConnectionStruct {
118 SilcProtocol protocol;
129 SilcSocketConnectionHB hb;
132 /* Heartbeat context */
133 struct SilcSocketConnectionHB {
135 SilcSocketConnectionHBCb hb_callback;
139 SilcSocketConnection sock;
144 /* Generic manipulation of flags */
145 #define SF_SET(x, f) (x)->flags |= (1L << (f))
146 #define SF_UNSET(x, f) (x)->flags &= ~(1L << (f))
147 #define SF_IS(x, f) ((x)->flags & (1L << (f)))
149 /* Setting/Unsetting flags */
150 #define SILC_SET_OUTBUF_PENDING(x) SF_SET((x), SILC_SF_OUTBUF_PENDING)
151 #define SILC_SET_INBUF_PENDING(x) SF_SET((x), SILC_SF_INBUF_PENDING)
152 #define SILC_SET_DISCONNECTING(x) SF_SET((x), SILC_SF_DISCONNECTING)
153 #define SILC_SET_DISCONNECTED(x) SF_SET((x), SILC_SF_DISCONNECTED)
154 #define SILC_UNSET_OUTBUF_PENDING(x) SF_UNSET((x), SILC_SF_OUTBUF_PENDING)
155 #define SILC_UNSET_INBUF_PENDING(x) SF_UNSET((x), SILC_SF_INBUF_PENDING)
156 #define SILC_UNSET_DISCONNECTING(x) SF_UNSET((x), SILC_SF_DISCONNECTING)
157 #define SILC_UNSET_DISCONNECTED(x) SF_UNSET((x), SILC_SF_DISCONNECTED)
159 /* Checking for flags */
160 #define SILC_IS_OUTBUF_PENDING(x) SF_IS((x), SILC_SF_OUTBUF_PENDING)
161 #define SILC_IS_INBUF_PENDING(x) SF_IS((x), SILC_SF_INBUF_PENDING)
162 #define SILC_IS_DISCONNECTING(x) SF_IS((x), SILC_SF_DISCONNECTING)
163 #define SILC_IS_DISCONNECTED(x) SF_IS((x), SILC_SF_DISCONNECTED)
166 void silc_socket_alloc(int sock, SilcSocketType type, void *user_data,
167 SilcSocketConnection *new_socket);
168 void silc_socket_free(SilcSocketConnection sock);
169 SilcSocketConnection silc_socket_dup(SilcSocketConnection sock);
170 void silc_socket_set_heartbeat(SilcSocketConnection sock,
173 SilcSocketConnectionHBCb hb_callback,
174 void *timeout_queue);