]> arthur.barton.de Git - ngircd-alex.git/blob - src/ngircd/conn-func.c
removed Conn_UnsetOption() function. It was not used anymore.
[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.5 2005/04/25 18:37:16 fw 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 int
153 Conn_Options( CONN_ID Idx )
154 {
155         assert( Idx > NONE );
156         return My_Connections[Idx].options;
157 } /* Conn_Options */
158
159
160 GLOBAL time_t
161 Conn_StartTime( CONN_ID Idx )
162 {
163         /* Zeitpunkt des Link-Starts liefern (in Sekunden) */
164
165         assert( Idx > NONE );
166         return My_Connections[Idx].starttime;
167 } /* Conn_Uptime */
168
169
170 GLOBAL int
171 Conn_SendQ( CONN_ID Idx )
172 {
173         /* Laenge der Daten im Schreibbuffer liefern */
174
175         assert( Idx > NONE );
176 #ifdef ZLIB
177         if( My_Connections[Idx].options & CONN_ZIP ) return My_Connections[Idx].zip.wdatalen;
178         else
179 #endif
180         return My_Connections[Idx].wdatalen;
181 } /* Conn_SendQ */
182
183
184 GLOBAL long
185 Conn_SendMsg( CONN_ID Idx )
186 {
187         /* Anzahl gesendeter Nachrichten liefern */
188
189         assert( Idx > NONE );
190         return My_Connections[Idx].msg_out;
191 } /* Conn_SendMsg */
192
193
194 GLOBAL long
195 Conn_SendBytes( CONN_ID Idx )
196 {
197         /* Anzahl gesendeter Bytes (unkomprimiert) liefern */
198
199         assert( Idx > NONE );
200         return My_Connections[Idx].bytes_out;
201 } /* Conn_SendBytes */
202
203
204 GLOBAL int
205 Conn_RecvQ( CONN_ID Idx )
206 {
207         /* Laenge der Daten im Lesebuffer liefern */
208
209         assert( Idx > NONE );
210 #ifdef ZLIB
211         if( My_Connections[Idx].options & CONN_ZIP ) return My_Connections[Idx].zip.rdatalen;
212         else
213 #endif
214         return My_Connections[Idx].rdatalen;
215 } /* Conn_RecvQ */
216
217
218 GLOBAL long
219 Conn_RecvMsg( CONN_ID Idx )
220 {
221         /* Anzahl empfangener Nachrichten liefern */
222
223         assert( Idx > NONE );
224         return My_Connections[Idx].msg_in;
225 } /* Conn_RecvMsg */
226
227
228 GLOBAL long
229 Conn_RecvBytes( CONN_ID Idx )
230 {
231         /* Anzahl empfangener Bytes (unkomprimiert) liefern */
232
233         assert( Idx > NONE );
234         return My_Connections[Idx].bytes_in;
235 } /* Conn_RecvBytes */
236
237
238 GLOBAL void
239 Conn_ResetWCounter( void )
240 {
241         WCounter = 0;
242 } /* Conn_ResetWCounter */
243
244
245 GLOBAL long
246 Conn_WCounter( void )
247 {
248         return WCounter;
249 } /* Conn_WCounter */
250
251
252 /* -eof- */