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.6 2005/06/12 16:32:17 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 ) My_Connections[Idx].delaytime = t;
77 } /* Conn_SetPenalty */
81 Conn_ResetPenalty( CONN_ID Idx )
84 My_Connections[Idx].delaytime = 0;
85 } /* Conn_ResetPenalty */
89 Conn_ClearFlags( void )
91 /* Alle Connection auf "nicht-markiert" setzen */
95 for( i = 0; i < Pool_Size; i++ ) My_Connections[i].flag = 0;
96 } /* Conn_ClearFlags */
100 Conn_Flag( CONN_ID Idx )
102 /* Ist eine Connection markiert (true) oder nicht? */
104 assert( Idx > NONE );
105 return My_Connections[Idx].flag;
110 Conn_SetFlag( CONN_ID Idx, int Flag )
112 /* Connection markieren */
114 assert( Idx > NONE );
115 My_Connections[Idx].flag = Flag;
122 /* Connection-Struktur der ersten Verbindung liefern;
123 * Ist keine Verbindung vorhanden, wird NONE geliefert. */
127 for( i = 0; i < Pool_Size; i++ )
129 if( My_Connections[i].sock != NONE ) return i;
136 Conn_Next( CONN_ID Idx )
138 /* Naechste Verbindungs-Struktur liefern; existiert keine
139 * weitere, so wird NONE geliefert. */
143 assert( Idx > NONE );
145 for( i = Idx + 1; i < Pool_Size; i++ )
147 if( My_Connections[i].sock != NONE ) return i;
154 Conn_Options( CONN_ID Idx )
156 assert( Idx > NONE );
157 return My_Connections[Idx].options;
162 * Get the start time of the connection.
163 * The result is the start time in seconds since 1970-01-01, as reported
164 * by the C function time(NULL).
167 Conn_StartTime( CONN_ID Idx )
173 /* Search client structure for this link ... */
174 c = Client_GetFromConn(Idx);
176 return Client_StartTime(c);
179 } /* Conn_StartTime */
183 Conn_SendQ( CONN_ID Idx )
185 /* Laenge der Daten im Schreibbuffer liefern */
187 assert( Idx > NONE );
189 if( My_Connections[Idx].options & CONN_ZIP ) return My_Connections[Idx].zip.wdatalen;
192 return My_Connections[Idx].wdatalen;
197 Conn_SendMsg( CONN_ID Idx )
199 /* Anzahl gesendeter Nachrichten liefern */
201 assert( Idx > NONE );
202 return My_Connections[Idx].msg_out;
207 Conn_SendBytes( CONN_ID Idx )
209 /* Anzahl gesendeter Bytes (unkomprimiert) liefern */
211 assert( Idx > NONE );
212 return My_Connections[Idx].bytes_out;
213 } /* Conn_SendBytes */
217 Conn_RecvQ( CONN_ID Idx )
219 /* Laenge der Daten im Lesebuffer liefern */
221 assert( Idx > NONE );
223 if( My_Connections[Idx].options & CONN_ZIP ) return My_Connections[Idx].zip.rdatalen;
226 return My_Connections[Idx].rdatalen;
231 Conn_RecvMsg( CONN_ID Idx )
233 /* Anzahl empfangener Nachrichten liefern */
235 assert( Idx > NONE );
236 return My_Connections[Idx].msg_in;
241 Conn_RecvBytes( CONN_ID Idx )
243 /* Anzahl empfangener Bytes (unkomprimiert) liefern */
245 assert( Idx > NONE );
246 return My_Connections[Idx].bytes_in;
247 } /* Conn_RecvBytes */
251 Conn_ResetWCounter( void )
254 } /* Conn_ResetWCounter */
258 Conn_WCounter( void )
261 } /* Conn_WCounter */