]> arthur.barton.de Git - ngircd-alex.git/blob - src/ngircd/conn-func.c
- Client structures are removed correctly now if an outgoing connection can't be...
[ngircd-alex.git] / src / ngircd / conn-func.c
1 /*
2  * ngIRCd -- The Next Generation IRC Daemon
3  * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de)
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  * Please read the file COPYING, README and AUTHORS for more information.
10  *
11  * Connection management: Global functions
12  */
13
14
15 #define CONN_MODULE
16
17 #include "portab.h"
18
19 static char UNUSED id[] = "$Id: conn-func.c,v 1.1 2002/12/30 17:14:28 alex Exp $";
20
21 #include "imp.h"
22 #include <assert.h>
23
24 #include "conn.h"
25
26 #include "exp.h"
27 #include "conn-func.h"
28
29
30 GLOBAL VOID
31 Conn_UpdateIdle( CONN_ID Idx )
32 {
33         /* Idle-Timer zuruecksetzen */
34
35         assert( Idx > NONE );
36         My_Connections[Idx].lastprivmsg = time( NULL );
37 }
38
39
40 GLOBAL time_t
41 Conn_GetIdle( CONN_ID Idx )
42 {
43         /* Idle-Time einer Verbindung liefern (in Sekunden) */
44
45         assert( Idx > NONE );
46         return time( NULL ) - My_Connections[Idx].lastprivmsg;
47 } /* Conn_GetIdle */
48
49
50 GLOBAL time_t
51 Conn_LastPing( CONN_ID Idx )
52 {
53         /* Zeitpunkt des letzten PING liefern */
54
55         assert( Idx > NONE );
56         return My_Connections[Idx].lastping;
57 } /* Conn_LastPing */
58
59
60 GLOBAL VOID
61 Conn_SetPenalty( CONN_ID Idx, time_t Seconds )
62 {
63         /* Penalty-Delay fuer eine Verbindung (in Sekunden) setzen;
64          * waehrend dieser Zeit wird der entsprechende Socket vom Server
65          * bei Lese-Operationen komplett ignoriert. Der Delay kann mit
66          * dieser Funktion nur erhoeht, nicht aber verringert werden. */
67         
68         time_t t;
69         
70         assert( Idx > NONE );
71         assert( Seconds >= 0 );
72         
73         t = time( NULL ) + Seconds;
74         if( t > My_Connections[Idx].delaytime ) My_Connections[Idx].delaytime = t;
75 } /* Conn_SetPenalty */
76
77
78 GLOBAL VOID
79 Conn_ResetPenalty( CONN_ID Idx )
80 {
81         assert( Idx > NONE );
82         My_Connections[Idx].delaytime = 0;
83 } /* Conn_ResetPenalty */
84
85
86 GLOBAL VOID
87 Conn_ClearFlags( VOID )
88 {
89         /* Alle Connection auf "nicht-markiert" setzen */
90
91         CONN_ID i;
92
93         for( i = 0; i < Pool_Size; i++ ) My_Connections[i].flag = 0;
94 } /* Conn_ClearFlags */
95
96
97 GLOBAL INT
98 Conn_Flag( CONN_ID Idx )
99 {
100         /* Ist eine Connection markiert (TRUE) oder nicht? */
101
102         assert( Idx > NONE );
103         return My_Connections[Idx].flag;
104 } /* Conn_Flag */
105
106
107 GLOBAL VOID
108 Conn_SetFlag( CONN_ID Idx, INT Flag )
109 {
110         /* Connection markieren */
111
112         assert( Idx > NONE );
113         My_Connections[Idx].flag = Flag;
114 } /* Conn_SetFlag */
115
116
117 GLOBAL CONN_ID
118 Conn_First( VOID )
119 {
120         /* Connection-Struktur der ersten Verbindung liefern;
121          * Ist keine Verbindung vorhanden, wird NONE geliefert. */
122
123         CONN_ID i;
124         
125         for( i = 0; i < Pool_Size; i++ )
126         {
127                 if( My_Connections[i].sock != NONE ) return i;
128         }
129         return NONE;
130 } /* Conn_First */
131
132
133 GLOBAL CONN_ID
134 Conn_Next( CONN_ID Idx )
135 {
136         /* Naechste Verbindungs-Struktur liefern; existiert keine
137          * weitere, so wird NONE geliefert. */
138
139         CONN_ID i = NONE;
140
141         assert( Idx > NONE );
142         
143         for( i = Idx + 1; i < Pool_Size; i++ )
144         {
145                 if( My_Connections[i].sock != NONE ) return i;
146         }
147         return NONE;
148 } /* Conn_Next */
149
150
151 GLOBAL VOID
152 Conn_SetOption( CONN_ID Idx, INT Option )
153 {
154         /* Option fuer Verbindung setzen.
155          * Initial sind alle Optionen _nicht_ gesetzt. */
156
157         assert( Idx > NONE );
158         assert( Option != 0 );
159
160         My_Connections[Idx].options |= Option;
161 } /* Conn_SetOption */
162
163
164 GLOBAL VOID
165 Conn_UnsetOption( CONN_ID Idx, INT Option )
166 {
167         /* Option fuer Verbindung loeschen */
168
169         assert( Idx > NONE );
170         assert( Option != 0 );
171
172         My_Connections[Idx].options &= ~Option;
173 } /* Conn_UnsetOption */
174
175
176 GLOBAL INT
177 Conn_Options( CONN_ID Idx )
178 {
179         assert( Idx > NONE );
180         return My_Connections[Idx].options;
181 } /* Conn_Options */
182
183
184 GLOBAL time_t
185 Conn_StartTime( CONN_ID Idx )
186 {
187         /* Zeitpunkt des Link-Starts liefern (in Sekunden) */
188
189         assert( Idx > NONE );
190         return My_Connections[Idx].starttime;
191 } /* Conn_Uptime */
192
193
194 GLOBAL INT
195 Conn_SendQ( CONN_ID Idx )
196 {
197         /* Laenge der Daten im Schreibbuffer liefern */
198
199         assert( Idx > NONE );
200 #ifdef USE_ZLIB
201         if( My_Connections[Idx].options & CONN_ZIP ) return My_Connections[Idx].zip.wdatalen;
202         else
203 #endif
204         return My_Connections[Idx].wdatalen;
205 } /* Conn_SendQ */
206
207
208 GLOBAL LONG
209 Conn_SendMsg( CONN_ID Idx )
210 {
211         /* Anzahl gesendeter Nachrichten liefern */
212
213         assert( Idx > NONE );
214         return My_Connections[Idx].msg_out;
215 } /* Conn_SendMsg */
216
217
218 GLOBAL LONG
219 Conn_SendBytes( CONN_ID Idx )
220 {
221         /* Anzahl gesendeter Bytes (unkomprimiert) liefern */
222
223         assert( Idx > NONE );
224         return My_Connections[Idx].bytes_out;
225 } /* Conn_SendBytes */
226
227
228 GLOBAL INT
229 Conn_RecvQ( CONN_ID Idx )
230 {
231         /* Laenge der Daten im Lesebuffer liefern */
232
233         assert( Idx > NONE );
234 #ifdef USE_ZLIB
235         if( My_Connections[Idx].options & CONN_ZIP ) return My_Connections[Idx].zip.rdatalen;
236         else
237 #endif
238         return My_Connections[Idx].rdatalen;
239 } /* Conn_RecvQ */
240
241
242 GLOBAL LONG
243 Conn_RecvMsg( CONN_ID Idx )
244 {
245         /* Anzahl empfangener Nachrichten liefern */
246
247         assert( Idx > NONE );
248         return My_Connections[Idx].msg_in;
249 } /* Conn_RecvMsg */
250
251
252 GLOBAL LONG
253 Conn_RecvBytes( CONN_ID Idx )
254 {
255         /* Anzahl empfangener Bytes (unkomprimiert) liefern */
256
257         assert( Idx > NONE );
258         return My_Connections[Idx].bytes_in;
259 } /* Conn_RecvBytes */
260
261
262 GLOBAL VOID
263 Conn_ResetWCounter( VOID )
264 {
265         WCounter = 0;
266 } /* Conn_ResetWCounter */
267
268
269 GLOBAL LONG
270 Conn_WCounter( VOID )
271 {
272         return WCounter;
273 } /* Conn_WCounter */
274
275
276 /* -eof- */