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.1 2002/12/30 17:14:28 alex Exp $";
21 #include "imp.h"
22 #include <assert.h>
24 #include "conn.h"
26 #include "exp.h"
27 #include "conn-func.h"
30 GLOBAL VOID
31 Conn_UpdateIdle( CONN_ID Idx )
32 {
33 /* Idle-Timer zuruecksetzen */
35 assert( Idx > NONE );
36 My_Connections[Idx].lastprivmsg = time( NULL );
37 }
40 GLOBAL time_t
41 Conn_GetIdle( CONN_ID Idx )
42 {
43 /* Idle-Time einer Verbindung liefern (in Sekunden) */
45 assert( Idx > NONE );
46 return time( NULL ) - My_Connections[Idx].lastprivmsg;
47 } /* Conn_GetIdle */
50 GLOBAL time_t
51 Conn_LastPing( CONN_ID Idx )
52 {
53 /* Zeitpunkt des letzten PING liefern */
55 assert( Idx > NONE );
56 return My_Connections[Idx].lastping;
57 } /* Conn_LastPing */
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. */
68 time_t t;
70 assert( Idx > NONE );
71 assert( Seconds >= 0 );
73 t = time( NULL ) + Seconds;
74 if( t > My_Connections[Idx].delaytime ) My_Connections[Idx].delaytime = t;
75 } /* Conn_SetPenalty */
78 GLOBAL VOID
79 Conn_ResetPenalty( CONN_ID Idx )
80 {
81 assert( Idx > NONE );
82 My_Connections[Idx].delaytime = 0;
83 } /* Conn_ResetPenalty */
86 GLOBAL VOID
87 Conn_ClearFlags( VOID )
88 {
89 /* Alle Connection auf "nicht-markiert" setzen */
91 CONN_ID i;
93 for( i = 0; i < Pool_Size; i++ ) My_Connections[i].flag = 0;
94 } /* Conn_ClearFlags */
97 GLOBAL INT
98 Conn_Flag( CONN_ID Idx )
99 {
100 /* Ist eine Connection markiert (TRUE) oder nicht? */
102 assert( Idx > NONE );
103 return My_Connections[Idx].flag;
104 } /* Conn_Flag */
107 GLOBAL VOID
108 Conn_SetFlag( CONN_ID Idx, INT Flag )
110 /* Connection markieren */
112 assert( Idx > NONE );
113 My_Connections[Idx].flag = Flag;
114 } /* Conn_SetFlag */
117 GLOBAL CONN_ID
118 Conn_First( VOID )
120 /* Connection-Struktur der ersten Verbindung liefern;
121 * Ist keine Verbindung vorhanden, wird NONE geliefert. */
123 CONN_ID i;
125 for( i = 0; i < Pool_Size; i++ )
127 if( My_Connections[i].sock != NONE ) return i;
129 return NONE;
130 } /* Conn_First */
133 GLOBAL CONN_ID
134 Conn_Next( CONN_ID Idx )
136 /* Naechste Verbindungs-Struktur liefern; existiert keine
137 * weitere, so wird NONE geliefert. */
139 CONN_ID i = NONE;
141 assert( Idx > NONE );
143 for( i = Idx + 1; i < Pool_Size; i++ )
145 if( My_Connections[i].sock != NONE ) return i;
147 return NONE;
148 } /* Conn_Next */
151 GLOBAL VOID
152 Conn_SetOption( CONN_ID Idx, INT Option )
154 /* Option fuer Verbindung setzen.
155 * Initial sind alle Optionen _nicht_ gesetzt. */
157 assert( Idx > NONE );
158 assert( Option != 0 );
160 My_Connections[Idx].options |= Option;
161 } /* Conn_SetOption */
164 GLOBAL VOID
165 Conn_UnsetOption( CONN_ID Idx, INT Option )
167 /* Option fuer Verbindung loeschen */
169 assert( Idx > NONE );
170 assert( Option != 0 );
172 My_Connections[Idx].options &= ~Option;
173 } /* Conn_UnsetOption */
176 GLOBAL INT
177 Conn_Options( CONN_ID Idx )
179 assert( Idx > NONE );
180 return My_Connections[Idx].options;
181 } /* Conn_Options */
184 GLOBAL time_t
185 Conn_StartTime( CONN_ID Idx )
187 /* Zeitpunkt des Link-Starts liefern (in Sekunden) */
189 assert( Idx > NONE );
190 return My_Connections[Idx].starttime;
191 } /* Conn_Uptime */
194 GLOBAL INT
195 Conn_SendQ( CONN_ID Idx )
197 /* Laenge der Daten im Schreibbuffer liefern */
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 */
208 GLOBAL LONG
209 Conn_SendMsg( CONN_ID Idx )
211 /* Anzahl gesendeter Nachrichten liefern */
213 assert( Idx > NONE );
214 return My_Connections[Idx].msg_out;
215 } /* Conn_SendMsg */
218 GLOBAL LONG
219 Conn_SendBytes( CONN_ID Idx )
221 /* Anzahl gesendeter Bytes (unkomprimiert) liefern */
223 assert( Idx > NONE );
224 return My_Connections[Idx].bytes_out;
225 } /* Conn_SendBytes */
228 GLOBAL INT
229 Conn_RecvQ( CONN_ID Idx )
231 /* Laenge der Daten im Lesebuffer liefern */
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 */
242 GLOBAL LONG
243 Conn_RecvMsg( CONN_ID Idx )
245 /* Anzahl empfangener Nachrichten liefern */
247 assert( Idx > NONE );
248 return My_Connections[Idx].msg_in;
249 } /* Conn_RecvMsg */
252 GLOBAL LONG
253 Conn_RecvBytes( CONN_ID Idx )
255 /* Anzahl empfangener Bytes (unkomprimiert) liefern */
257 assert( Idx > NONE );
258 return My_Connections[Idx].bytes_in;
259 } /* Conn_RecvBytes */
262 GLOBAL VOID
263 Conn_ResetWCounter( VOID )
265 WCounter = 0;
266 } /* Conn_ResetWCounter */
269 GLOBAL LONG
270 Conn_WCounter( VOID )
272 return WCounter;
273 } /* Conn_WCounter */
276 /* -eof- */