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.5 2005/04/25 18:37:16 fw Exp $";
28 #include "conn-func.h"
32 Conn_UpdateIdle( CONN_ID Idx )
34 /* Idle-Timer zuruecksetzen */
37 My_Connections[Idx].lastprivmsg = time( NULL );
42 Conn_GetIdle( CONN_ID Idx )
44 /* Idle-Time einer Verbindung liefern (in Sekunden) */
47 return time( NULL ) - My_Connections[Idx].lastprivmsg;
52 Conn_LastPing( CONN_ID Idx )
54 /* Zeitpunkt des letzten PING liefern */
57 return My_Connections[Idx].lastping;
62 Conn_SetPenalty( CONN_ID Idx, time_t Seconds )
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. */
72 assert( Seconds >= 0 );
74 t = time( NULL ) + Seconds;
75 if( t > My_Connections[Idx].delaytime ) My_Connections[Idx].delaytime = t;
76 } /* Conn_SetPenalty */
80 Conn_ResetPenalty( CONN_ID Idx )
83 My_Connections[Idx].delaytime = 0;
84 } /* Conn_ResetPenalty */
88 Conn_ClearFlags( void )
90 /* Alle Connection auf "nicht-markiert" setzen */
94 for( i = 0; i < Pool_Size; i++ ) My_Connections[i].flag = 0;
95 } /* Conn_ClearFlags */
99 Conn_Flag( CONN_ID Idx )
101 /* Ist eine Connection markiert (true) oder nicht? */
103 assert( Idx > NONE );
104 return My_Connections[Idx].flag;
109 Conn_SetFlag( CONN_ID Idx, int Flag )
111 /* Connection markieren */
113 assert( Idx > NONE );
114 My_Connections[Idx].flag = Flag;
121 /* Connection-Struktur der ersten Verbindung liefern;
122 * Ist keine Verbindung vorhanden, wird NONE geliefert. */
126 for( i = 0; i < Pool_Size; i++ )
128 if( My_Connections[i].sock != NONE ) return i;
135 Conn_Next( CONN_ID Idx )
137 /* Naechste Verbindungs-Struktur liefern; existiert keine
138 * weitere, so wird NONE geliefert. */
142 assert( Idx > NONE );
144 for( i = Idx + 1; i < Pool_Size; i++ )
146 if( My_Connections[i].sock != NONE ) return i;
153 Conn_Options( CONN_ID Idx )
155 assert( Idx > NONE );
156 return My_Connections[Idx].options;
161 Conn_StartTime( CONN_ID Idx )
163 /* Zeitpunkt des Link-Starts liefern (in Sekunden) */
165 assert( Idx > NONE );
166 return My_Connections[Idx].starttime;
171 Conn_SendQ( CONN_ID Idx )
173 /* Laenge der Daten im Schreibbuffer liefern */
175 assert( Idx > NONE );
177 if( My_Connections[Idx].options & CONN_ZIP ) return My_Connections[Idx].zip.wdatalen;
180 return My_Connections[Idx].wdatalen;
185 Conn_SendMsg( CONN_ID Idx )
187 /* Anzahl gesendeter Nachrichten liefern */
189 assert( Idx > NONE );
190 return My_Connections[Idx].msg_out;
195 Conn_SendBytes( CONN_ID Idx )
197 /* Anzahl gesendeter Bytes (unkomprimiert) liefern */
199 assert( Idx > NONE );
200 return My_Connections[Idx].bytes_out;
201 } /* Conn_SendBytes */
205 Conn_RecvQ( CONN_ID Idx )
207 /* Laenge der Daten im Lesebuffer liefern */
209 assert( Idx > NONE );
211 if( My_Connections[Idx].options & CONN_ZIP ) return My_Connections[Idx].zip.rdatalen;
214 return My_Connections[Idx].rdatalen;
219 Conn_RecvMsg( CONN_ID Idx )
221 /* Anzahl empfangener Nachrichten liefern */
223 assert( Idx > NONE );
224 return My_Connections[Idx].msg_in;
229 Conn_RecvBytes( CONN_ID Idx )
231 /* Anzahl empfangener Bytes (unkomprimiert) liefern */
233 assert( Idx > NONE );
234 return My_Connections[Idx].bytes_in;
235 } /* Conn_RecvBytes */
239 Conn_ResetWCounter( void )
242 } /* Conn_ResetWCounter */
246 Conn_WCounter( void )
249 } /* Conn_WCounter */