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.11 2007/10/04 15:03:56 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 * Get signon time of a connection.
46 Conn_GetSignon(CONN_ID Idx)
49 return My_Connections[Idx].signon;
53 Conn_GetIdle( CONN_ID Idx )
55 /* Idle-Time einer Verbindung liefern (in Sekunden) */
58 return time( NULL ) - My_Connections[Idx].lastprivmsg;
63 Conn_LastPing( CONN_ID Idx )
65 /* Zeitpunkt des letzten PING liefern */
68 return My_Connections[Idx].lastping;
73 Conn_SetPenalty( CONN_ID Idx, time_t Seconds )
75 /* Penalty-Delay fuer eine Verbindung (in Sekunden) setzen;
76 * waehrend dieser Zeit wird der entsprechende Socket vom Server
77 * bei Lese-Operationen komplett ignoriert. Der Delay kann mit
78 * dieser Funktion nur erhoeht, nicht aber verringert werden. */
83 assert( Seconds >= 0 );
85 t = time( NULL ) + Seconds;
86 if (t > My_Connections[Idx].delaytime)
87 My_Connections[Idx].delaytime = t;
90 Log(LOG_DEBUG, "Add penalty time on connection %d: %ld second(s).",
93 } /* Conn_SetPenalty */
97 Conn_ResetPenalty( CONN_ID Idx )
100 My_Connections[Idx].delaytime = 0;
101 } /* Conn_ResetPenalty */
105 Conn_ClearFlags( void )
107 /* Alle Connection auf "nicht-markiert" setzen */
111 for( i = 0; i < Pool_Size; i++ ) My_Connections[i].flag = 0;
112 } /* Conn_ClearFlags */
116 Conn_Flag( CONN_ID Idx )
118 /* Ist eine Connection markiert (true) oder nicht? */
120 assert( Idx > NONE );
121 return My_Connections[Idx].flag;
126 Conn_SetFlag( CONN_ID Idx, int Flag )
128 /* Connection markieren */
130 assert( Idx > NONE );
131 My_Connections[Idx].flag = Flag;
138 /* Connection-Struktur der ersten Verbindung liefern;
139 * Ist keine Verbindung vorhanden, wird NONE geliefert. */
143 for( i = 0; i < Pool_Size; i++ )
145 if( My_Connections[i].sock != NONE ) return i;
152 Conn_Next( CONN_ID Idx )
154 /* Naechste Verbindungs-Struktur liefern; existiert keine
155 * weitere, so wird NONE geliefert. */
159 assert( Idx > NONE );
161 for( i = Idx + 1; i < Pool_Size; i++ )
163 if( My_Connections[i].sock != NONE ) return i;
170 Conn_Options( CONN_ID Idx )
172 assert( Idx > NONE );
173 return My_Connections[Idx].options;
178 * Get the start time of the connection.
179 * The result is the start time in seconds since 1970-01-01, as reported
180 * by the C function time(NULL).
183 Conn_StartTime( CONN_ID Idx )
189 /* Search client structure for this link ... */
190 c = Conn_GetClient(Idx);
192 return Client_StartTime(c);
195 } /* Conn_StartTime */
199 Conn_SendQ( CONN_ID Idx )
201 /* Laenge der Daten im Schreibbuffer liefern */
203 assert( Idx > NONE );
205 if( My_Connections[Idx].options & CONN_ZIP )
206 return array_bytes(&My_Connections[Idx].zip.wbuf);
209 return array_bytes(&My_Connections[Idx].wbuf);
214 Conn_SendMsg( CONN_ID Idx )
216 /* Anzahl gesendeter Nachrichten liefern */
218 assert( Idx > NONE );
219 return My_Connections[Idx].msg_out;
224 Conn_SendBytes( CONN_ID Idx )
226 /* Anzahl gesendeter Bytes (unkomprimiert) liefern */
228 assert( Idx > NONE );
229 return My_Connections[Idx].bytes_out;
230 } /* Conn_SendBytes */
234 Conn_RecvQ( CONN_ID Idx )
236 /* Laenge der Daten im Lesebuffer liefern */
238 assert( Idx > NONE );
240 if( My_Connections[Idx].options & CONN_ZIP )
241 return array_bytes(&My_Connections[Idx].zip.rbuf);
244 return array_bytes(&My_Connections[Idx].rbuf);
249 Conn_RecvMsg( CONN_ID Idx )
251 /* Anzahl empfangener Nachrichten liefern */
253 assert( Idx > NONE );
254 return My_Connections[Idx].msg_in;
259 Conn_RecvBytes( CONN_ID Idx )
261 /* Anzahl empfangener Bytes (unkomprimiert) liefern */
263 assert( Idx > NONE );
264 return My_Connections[Idx].bytes_in;
265 } /* Conn_RecvBytes */
269 Conn_ResetWCounter( void )
272 } /* Conn_ResetWCounter */
276 Conn_WCounter( void )
279 } /* Conn_WCounter */