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.3 2003/12/26 15:55:07 alex Exp $";
21 #include "imp.h"
22 #include <assert.h>
23 #include <log.h>
25 #include "conn.h"
27 #include "exp.h"
28 #include "conn-func.h"
31 GLOBAL VOID
32 Conn_UpdateIdle( CONN_ID Idx )
33 {
34 /* Idle-Timer zuruecksetzen */
36 assert( Idx > NONE );
37 My_Connections[Idx].lastprivmsg = time( NULL );
38 }
41 GLOBAL time_t
42 Conn_GetIdle( CONN_ID Idx )
43 {
44 /* Idle-Time einer Verbindung liefern (in Sekunden) */
46 assert( Idx > NONE );
47 return time( NULL ) - My_Connections[Idx].lastprivmsg;
48 } /* Conn_GetIdle */
51 GLOBAL time_t
52 Conn_LastPing( CONN_ID Idx )
53 {
54 /* Zeitpunkt des letzten PING liefern */
56 assert( Idx > NONE );
57 return My_Connections[Idx].lastping;
58 } /* Conn_LastPing */
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. */
69 time_t t;
71 assert( Idx > NONE );
72 assert( Seconds >= 0 );
74 t = time( NULL ) + Seconds;
75 if( t > My_Connections[Idx].delaytime ) My_Connections[Idx].delaytime = t;
76 } /* Conn_SetPenalty */
79 GLOBAL VOID
80 Conn_ResetPenalty( CONN_ID Idx )
81 {
82 assert( Idx > NONE );
83 My_Connections[Idx].delaytime = 0;
84 } /* Conn_ResetPenalty */
87 GLOBAL VOID
88 Conn_ClearFlags( VOID )
89 {
90 /* Alle Connection auf "nicht-markiert" setzen */
92 CONN_ID i;
94 for( i = 0; i < Pool_Size; i++ ) My_Connections[i].flag = 0;
95 } /* Conn_ClearFlags */
98 GLOBAL INT
99 Conn_Flag( CONN_ID Idx )
101 /* Ist eine Connection markiert (TRUE) oder nicht? */
103 assert( Idx > NONE );
104 return My_Connections[Idx].flag;
105 } /* Conn_Flag */
108 GLOBAL VOID
109 Conn_SetFlag( CONN_ID Idx, INT Flag )
111 /* Connection markieren */
113 assert( Idx > NONE );
114 My_Connections[Idx].flag = Flag;
115 } /* Conn_SetFlag */
118 GLOBAL CONN_ID
119 Conn_First( VOID )
121 /* Connection-Struktur der ersten Verbindung liefern;
122 * Ist keine Verbindung vorhanden, wird NONE geliefert. */
124 CONN_ID i;
126 for( i = 0; i < Pool_Size; i++ )
128 if( My_Connections[i].sock != NONE ) return i;
130 return NONE;
131 } /* Conn_First */
134 GLOBAL CONN_ID
135 Conn_Next( CONN_ID Idx )
137 /* Naechste Verbindungs-Struktur liefern; existiert keine
138 * weitere, so wird NONE geliefert. */
140 CONN_ID i = NONE;
142 assert( Idx > NONE );
144 for( i = Idx + 1; i < Pool_Size; i++ )
146 if( My_Connections[i].sock != NONE ) return i;
148 return NONE;
149 } /* Conn_Next */
152 GLOBAL VOID
153 Conn_SetOption( CONN_ID Idx, INT Option )
155 /* Option fuer Verbindung setzen.
156 * Initial sind alle Optionen _nicht_ gesetzt. */
158 assert( Idx > NONE );
159 assert( Option != 0 );
161 My_Connections[Idx].options |= Option;
162 } /* Conn_SetOption */
165 GLOBAL VOID
166 Conn_UnsetOption( CONN_ID Idx, INT Option )
168 /* Option fuer Verbindung loeschen */
170 assert( Idx > NONE );
171 assert( Option != 0 );
173 My_Connections[Idx].options &= ~Option;
174 } /* Conn_UnsetOption */
177 GLOBAL INT
178 Conn_Options( CONN_ID Idx )
180 assert( Idx > NONE );
181 return My_Connections[Idx].options;
182 } /* Conn_Options */
185 GLOBAL time_t
186 Conn_StartTime( CONN_ID Idx )
188 /* Zeitpunkt des Link-Starts liefern (in Sekunden) */
190 assert( Idx > NONE );
191 return My_Connections[Idx].starttime;
192 } /* Conn_Uptime */
195 GLOBAL INT
196 Conn_SendQ( CONN_ID Idx )
198 /* Laenge der Daten im Schreibbuffer liefern */
200 assert( Idx > NONE );
201 #ifdef 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 */
209 GLOBAL LONG
210 Conn_SendMsg( CONN_ID Idx )
212 /* Anzahl gesendeter Nachrichten liefern */
214 assert( Idx > NONE );
215 return My_Connections[Idx].msg_out;
216 } /* Conn_SendMsg */
219 GLOBAL LONG
220 Conn_SendBytes( CONN_ID Idx )
222 /* Anzahl gesendeter Bytes (unkomprimiert) liefern */
224 assert( Idx > NONE );
225 return My_Connections[Idx].bytes_out;
226 } /* Conn_SendBytes */
229 GLOBAL INT
230 Conn_RecvQ( CONN_ID Idx )
232 /* Laenge der Daten im Lesebuffer liefern */
234 assert( Idx > NONE );
235 #ifdef 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 */
243 GLOBAL LONG
244 Conn_RecvMsg( CONN_ID Idx )
246 /* Anzahl empfangener Nachrichten liefern */
248 assert( Idx > NONE );
249 return My_Connections[Idx].msg_in;
250 } /* Conn_RecvMsg */
253 GLOBAL LONG
254 Conn_RecvBytes( CONN_ID Idx )
256 /* Anzahl empfangener Bytes (unkomprimiert) liefern */
258 assert( Idx > NONE );
259 return My_Connections[Idx].bytes_in;
260 } /* Conn_RecvBytes */
263 GLOBAL VOID
264 Conn_ResetWCounter( VOID )
266 WCounter = 0;
267 } /* Conn_ResetWCounter */
270 GLOBAL LONG
271 Conn_WCounter( VOID )
273 return WCounter;
274 } /* Conn_WCounter */
277 /* -eof- */