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.12 2008/03/11 14:05:27 alex Exp $";
30 #include "conn-func.h"
34 Conn_UpdateIdle( CONN_ID Idx )
36 /* Idle-Timer zuruecksetzen */
39 My_Connections[Idx].lastprivmsg = time( NULL );
44 * Get signon time of a connection.
47 Conn_GetSignon(CONN_ID Idx)
50 return My_Connections[Idx].signon;
54 Conn_GetIdle( CONN_ID Idx )
56 /* Idle-Time einer Verbindung liefern (in Sekunden) */
59 return time( NULL ) - My_Connections[Idx].lastprivmsg;
64 Conn_LastPing( CONN_ID Idx )
66 /* Zeitpunkt des letzten PING liefern */
69 return My_Connections[Idx].lastping;
74 Conn_SetPenalty( CONN_ID Idx, time_t Seconds )
76 /* Penalty-Delay fuer eine Verbindung (in Sekunden) setzen;
77 * waehrend dieser Zeit wird der entsprechende Socket vom Server
78 * bei Lese-Operationen komplett ignoriert. Der Delay kann mit
79 * dieser Funktion nur erhoeht, nicht aber verringert werden. */
84 assert( Seconds >= 0 );
86 t = time( NULL ) + Seconds;
87 if (t > My_Connections[Idx].delaytime)
88 My_Connections[Idx].delaytime = t;
91 Log(LOG_DEBUG, "Add penalty time on connection %d: %ld second(s).",
94 } /* Conn_SetPenalty */
98 Conn_ResetPenalty( CONN_ID Idx )
100 assert( Idx > NONE );
101 My_Connections[Idx].delaytime = 0;
102 } /* Conn_ResetPenalty */
106 Conn_ClearFlags( void )
108 /* Alle Connection auf "nicht-markiert" setzen */
112 for( i = 0; i < Pool_Size; i++ ) My_Connections[i].flag = 0;
113 } /* Conn_ClearFlags */
117 Conn_Flag( CONN_ID Idx )
119 /* Ist eine Connection markiert (true) oder nicht? */
121 assert( Idx > NONE );
122 return My_Connections[Idx].flag;
127 Conn_SetFlag( CONN_ID Idx, int Flag )
129 /* Connection markieren */
131 assert( Idx > NONE );
132 My_Connections[Idx].flag = Flag;
139 /* Connection-Struktur der ersten Verbindung liefern;
140 * Ist keine Verbindung vorhanden, wird NONE geliefert. */
144 for( i = 0; i < Pool_Size; i++ )
146 if( My_Connections[i].sock != NONE ) return i;
153 Conn_Next( CONN_ID Idx )
155 /* Naechste Verbindungs-Struktur liefern; existiert keine
156 * weitere, so wird NONE geliefert. */
160 assert( Idx > NONE );
162 for( i = Idx + 1; i < Pool_Size; i++ )
164 if( My_Connections[i].sock != NONE ) return i;
171 Conn_Options( CONN_ID Idx )
173 assert( Idx > NONE );
174 return My_Connections[Idx].options;
179 * Get the start time of the connection.
180 * The result is the start time in seconds since 1970-01-01, as reported
181 * by the C function time(NULL).
184 Conn_StartTime( CONN_ID Idx )
190 /* Search client structure for this link ... */
191 c = Conn_GetClient(Idx);
193 return Client_StartTime(c);
196 } /* Conn_StartTime */
200 Conn_SendQ( CONN_ID Idx )
202 /* Laenge der Daten im Schreibbuffer liefern */
204 assert( Idx > NONE );
206 if( My_Connections[Idx].options & CONN_ZIP )
207 return array_bytes(&My_Connections[Idx].zip.wbuf);
210 return array_bytes(&My_Connections[Idx].wbuf);
215 Conn_SendMsg( CONN_ID Idx )
217 /* Anzahl gesendeter Nachrichten liefern */
219 assert( Idx > NONE );
220 return My_Connections[Idx].msg_out;
225 Conn_SendBytes( CONN_ID Idx )
227 /* Anzahl gesendeter Bytes (unkomprimiert) liefern */
229 assert( Idx > NONE );
230 return My_Connections[Idx].bytes_out;
231 } /* Conn_SendBytes */
235 Conn_RecvQ( CONN_ID Idx )
237 /* Laenge der Daten im Lesebuffer liefern */
239 assert( Idx > NONE );
241 if( My_Connections[Idx].options & CONN_ZIP )
242 return array_bytes(&My_Connections[Idx].zip.rbuf);
245 return array_bytes(&My_Connections[Idx].rbuf);
250 Conn_RecvMsg( CONN_ID Idx )
252 /* Anzahl empfangener Nachrichten liefern */
254 assert( Idx > NONE );
255 return My_Connections[Idx].msg_in;
260 Conn_RecvBytes( CONN_ID Idx )
262 /* Anzahl empfangener Bytes (unkomprimiert) liefern */
264 assert( Idx > NONE );
265 return My_Connections[Idx].bytes_in;
266 } /* Conn_RecvBytes */
270 Conn_ResetWCounter( void )
273 } /* Conn_ResetWCounter */
277 Conn_WCounter( void )
280 } /* Conn_WCounter */