Blob


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 */
15 #define CONN_MODULE
17 #include "portab.h"
19 static char UNUSED id[] = "$Id: conn-func.c,v 1.6 2005/06/12 16:32:17 alex Exp $";
21 #include "imp.h"
22 #include <assert.h>
23 #include <log.h>
25 #include "conn.h"
26 #include "client.h"
28 #include "exp.h"
29 #include "conn-func.h"
32 GLOBAL void
33 Conn_UpdateIdle( CONN_ID Idx )
34 {
35 /* Idle-Timer zuruecksetzen */
37 assert( Idx > NONE );
38 My_Connections[Idx].lastprivmsg = time( NULL );
39 }
42 GLOBAL time_t
43 Conn_GetIdle( CONN_ID Idx )
44 {
45 /* Idle-Time einer Verbindung liefern (in Sekunden) */
47 assert( Idx > NONE );
48 return time( NULL ) - My_Connections[Idx].lastprivmsg;
49 } /* Conn_GetIdle */
52 GLOBAL time_t
53 Conn_LastPing( CONN_ID Idx )
54 {
55 /* Zeitpunkt des letzten PING liefern */
57 assert( Idx > NONE );
58 return My_Connections[Idx].lastping;
59 } /* Conn_LastPing */
62 GLOBAL void
63 Conn_SetPenalty( CONN_ID Idx, time_t Seconds )
64 {
65 /* Penalty-Delay fuer eine Verbindung (in Sekunden) setzen;
66 * waehrend dieser Zeit wird der entsprechende Socket vom Server
67 * bei Lese-Operationen komplett ignoriert. Der Delay kann mit
68 * dieser Funktion nur erhoeht, nicht aber verringert werden. */
70 time_t t;
72 assert( Idx > NONE );
73 assert( Seconds >= 0 );
75 t = time( NULL ) + Seconds;
76 if( t > My_Connections[Idx].delaytime ) My_Connections[Idx].delaytime = t;
77 } /* Conn_SetPenalty */
80 GLOBAL void
81 Conn_ResetPenalty( CONN_ID Idx )
82 {
83 assert( Idx > NONE );
84 My_Connections[Idx].delaytime = 0;
85 } /* Conn_ResetPenalty */
88 GLOBAL void
89 Conn_ClearFlags( void )
90 {
91 /* Alle Connection auf "nicht-markiert" setzen */
93 CONN_ID i;
95 for( i = 0; i < Pool_Size; i++ ) My_Connections[i].flag = 0;
96 } /* Conn_ClearFlags */
99 GLOBAL int
100 Conn_Flag( CONN_ID Idx )
102 /* Ist eine Connection markiert (true) oder nicht? */
104 assert( Idx > NONE );
105 return My_Connections[Idx].flag;
106 } /* Conn_Flag */
109 GLOBAL void
110 Conn_SetFlag( CONN_ID Idx, int Flag )
112 /* Connection markieren */
114 assert( Idx > NONE );
115 My_Connections[Idx].flag = Flag;
116 } /* Conn_SetFlag */
119 GLOBAL CONN_ID
120 Conn_First( void )
122 /* Connection-Struktur der ersten Verbindung liefern;
123 * Ist keine Verbindung vorhanden, wird NONE geliefert. */
125 CONN_ID i;
127 for( i = 0; i < Pool_Size; i++ )
129 if( My_Connections[i].sock != NONE ) return i;
131 return NONE;
132 } /* Conn_First */
135 GLOBAL CONN_ID
136 Conn_Next( CONN_ID Idx )
138 /* Naechste Verbindungs-Struktur liefern; existiert keine
139 * weitere, so wird NONE geliefert. */
141 CONN_ID i = NONE;
143 assert( Idx > NONE );
145 for( i = Idx + 1; i < Pool_Size; i++ )
147 if( My_Connections[i].sock != NONE ) return i;
149 return NONE;
150 } /* Conn_Next */
153 GLOBAL int
154 Conn_Options( CONN_ID Idx )
156 assert( Idx > NONE );
157 return My_Connections[Idx].options;
158 } /* Conn_Options */
161 /**
162 * Get the start time of the connection.
163 * The result is the start time in seconds since 1970-01-01, as reported
164 * by the C function time(NULL).
165 */
166 GLOBAL time_t
167 Conn_StartTime( CONN_ID Idx )
169 CLIENT *c;
171 assert(Idx > NONE);
173 /* Search client structure for this link ... */
174 c = Client_GetFromConn(Idx);
175 if(c != NULL)
176 return Client_StartTime(c);
178 return 0;
179 } /* Conn_StartTime */
182 GLOBAL int
183 Conn_SendQ( CONN_ID Idx )
185 /* Laenge der Daten im Schreibbuffer liefern */
187 assert( Idx > NONE );
188 #ifdef ZLIB
189 if( My_Connections[Idx].options & CONN_ZIP ) return My_Connections[Idx].zip.wdatalen;
190 else
191 #endif
192 return My_Connections[Idx].wdatalen;
193 } /* Conn_SendQ */
196 GLOBAL long
197 Conn_SendMsg( CONN_ID Idx )
199 /* Anzahl gesendeter Nachrichten liefern */
201 assert( Idx > NONE );
202 return My_Connections[Idx].msg_out;
203 } /* Conn_SendMsg */
206 GLOBAL long
207 Conn_SendBytes( CONN_ID Idx )
209 /* Anzahl gesendeter Bytes (unkomprimiert) liefern */
211 assert( Idx > NONE );
212 return My_Connections[Idx].bytes_out;
213 } /* Conn_SendBytes */
216 GLOBAL int
217 Conn_RecvQ( CONN_ID Idx )
219 /* Laenge der Daten im Lesebuffer liefern */
221 assert( Idx > NONE );
222 #ifdef ZLIB
223 if( My_Connections[Idx].options & CONN_ZIP ) return My_Connections[Idx].zip.rdatalen;
224 else
225 #endif
226 return My_Connections[Idx].rdatalen;
227 } /* Conn_RecvQ */
230 GLOBAL long
231 Conn_RecvMsg( CONN_ID Idx )
233 /* Anzahl empfangener Nachrichten liefern */
235 assert( Idx > NONE );
236 return My_Connections[Idx].msg_in;
237 } /* Conn_RecvMsg */
240 GLOBAL long
241 Conn_RecvBytes( CONN_ID Idx )
243 /* Anzahl empfangener Bytes (unkomprimiert) liefern */
245 assert( Idx > NONE );
246 return My_Connections[Idx].bytes_in;
247 } /* Conn_RecvBytes */
250 GLOBAL void
251 Conn_ResetWCounter( void )
253 WCounter = 0;
254 } /* Conn_ResetWCounter */
257 GLOBAL long
258 Conn_WCounter( void )
260 return WCounter;
261 } /* Conn_WCounter */
264 /* -eof- */