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