2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de)
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.
11 * Connection management: Global functions
19 static char UNUSED id[] = "$Id: conn-func.c,v 1.10 2006/05/10 21:24:01 alex Exp $";
29 #include "conn-func.h"
33 Conn_UpdateIdle( CONN_ID Idx )
35 /* Idle-Timer zuruecksetzen */
38 My_Connections[Idx].lastprivmsg = time( NULL );
43 Conn_GetIdle( CONN_ID Idx )
45 /* Idle-Time einer Verbindung liefern (in Sekunden) */
48 return time( NULL ) - My_Connections[Idx].lastprivmsg;
53 Conn_LastPing( CONN_ID Idx )
55 /* Zeitpunkt des letzten PING liefern */
58 return My_Connections[Idx].lastping;
63 Conn_SetPenalty( CONN_ID Idx, time_t Seconds )
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. */
73 assert( Seconds >= 0 );
75 t = time( NULL ) + Seconds;
76 if (t > My_Connections[Idx].delaytime)
77 My_Connections[Idx].delaytime = t;
80 Log(LOG_DEBUG, "Add penalty time on connection %d: %ld second(s).",
83 } /* Conn_SetPenalty */
87 Conn_ResetPenalty( CONN_ID Idx )
90 My_Connections[Idx].delaytime = 0;
91 } /* Conn_ResetPenalty */
95 Conn_ClearFlags( void )
97 /* Alle Connection auf "nicht-markiert" setzen */
101 for( i = 0; i < Pool_Size; i++ ) My_Connections[i].flag = 0;
102 } /* Conn_ClearFlags */
106 Conn_Flag( CONN_ID Idx )
108 /* Ist eine Connection markiert (true) oder nicht? */
110 assert( Idx > NONE );
111 return My_Connections[Idx].flag;
116 Conn_SetFlag( CONN_ID Idx, int Flag )
118 /* Connection markieren */
120 assert( Idx > NONE );
121 My_Connections[Idx].flag = Flag;
128 /* Connection-Struktur der ersten Verbindung liefern;
129 * Ist keine Verbindung vorhanden, wird NONE geliefert. */
133 for( i = 0; i < Pool_Size; i++ )
135 if( My_Connections[i].sock != NONE ) return i;
142 Conn_Next( CONN_ID Idx )
144 /* Naechste Verbindungs-Struktur liefern; existiert keine
145 * weitere, so wird NONE geliefert. */
149 assert( Idx > NONE );
151 for( i = Idx + 1; i < Pool_Size; i++ )
153 if( My_Connections[i].sock != NONE ) return i;
160 Conn_Options( CONN_ID Idx )
162 assert( Idx > NONE );
163 return My_Connections[Idx].options;
168 * Get the start time of the connection.
169 * The result is the start time in seconds since 1970-01-01, as reported
170 * by the C function time(NULL).
173 Conn_StartTime( CONN_ID Idx )
179 /* Search client structure for this link ... */
180 c = Conn_GetClient(Idx);
182 return Client_StartTime(c);
185 } /* Conn_StartTime */
189 Conn_SendQ( CONN_ID Idx )
191 /* Laenge der Daten im Schreibbuffer liefern */
193 assert( Idx > NONE );
195 if( My_Connections[Idx].options & CONN_ZIP )
196 return array_bytes(&My_Connections[Idx].zip.wbuf);
199 return array_bytes(&My_Connections[Idx].wbuf);
204 Conn_SendMsg( CONN_ID Idx )
206 /* Anzahl gesendeter Nachrichten liefern */
208 assert( Idx > NONE );
209 return My_Connections[Idx].msg_out;
214 Conn_SendBytes( CONN_ID Idx )
216 /* Anzahl gesendeter Bytes (unkomprimiert) liefern */
218 assert( Idx > NONE );
219 return My_Connections[Idx].bytes_out;
220 } /* Conn_SendBytes */
224 Conn_RecvQ( CONN_ID Idx )
226 /* Laenge der Daten im Lesebuffer liefern */
228 assert( Idx > NONE );
230 if( My_Connections[Idx].options & CONN_ZIP )
231 return array_bytes(&My_Connections[Idx].zip.rbuf);
234 return array_bytes(&My_Connections[Idx].rbuf);
239 Conn_RecvMsg( CONN_ID Idx )
241 /* Anzahl empfangener Nachrichten liefern */
243 assert( Idx > NONE );
244 return My_Connections[Idx].msg_in;
249 Conn_RecvBytes( CONN_ID Idx )
251 /* Anzahl empfangener Bytes (unkomprimiert) liefern */
253 assert( Idx > NONE );
254 return My_Connections[Idx].bytes_in;
255 } /* Conn_RecvBytes */
259 Conn_ResetWCounter( void )
262 } /* Conn_ResetWCounter */
266 Conn_WCounter( void )
269 } /* Conn_WCounter */