2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001-2008 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 * Set connection option.
182 Conn_SetOption(CONN_ID Idx, int Option)
185 Conn_OPTION_ADD(&My_Connections[Idx], Option);
186 } /* Conn_SetOption */
190 * Get the start time of the connection.
191 * The result is the start time in seconds since 1970-01-01, as reported
192 * by the C function time(NULL).
195 Conn_StartTime( CONN_ID Idx )
201 /* Search client structure for this link ... */
202 c = Conn_GetClient(Idx);
204 return Client_StartTime(c);
207 } /* Conn_StartTime */
211 Conn_SendQ( CONN_ID Idx )
213 /* Laenge der Daten im Schreibbuffer liefern */
215 assert( Idx > NONE );
217 if( My_Connections[Idx].options & CONN_ZIP )
218 return array_bytes(&My_Connections[Idx].zip.wbuf);
221 return array_bytes(&My_Connections[Idx].wbuf);
226 Conn_SendMsg( CONN_ID Idx )
228 /* Anzahl gesendeter Nachrichten liefern */
230 assert( Idx > NONE );
231 return My_Connections[Idx].msg_out;
236 Conn_SendBytes( CONN_ID Idx )
238 /* Anzahl gesendeter Bytes (unkomprimiert) liefern */
240 assert( Idx > NONE );
241 return My_Connections[Idx].bytes_out;
242 } /* Conn_SendBytes */
246 Conn_RecvQ( CONN_ID Idx )
248 /* Laenge der Daten im Lesebuffer liefern */
250 assert( Idx > NONE );
252 if( My_Connections[Idx].options & CONN_ZIP )
253 return array_bytes(&My_Connections[Idx].zip.rbuf);
256 return array_bytes(&My_Connections[Idx].rbuf);
261 Conn_RecvMsg( CONN_ID Idx )
263 /* Anzahl empfangener Nachrichten liefern */
265 assert( Idx > NONE );
266 return My_Connections[Idx].msg_in;
271 Conn_RecvBytes( CONN_ID Idx )
273 /* Anzahl empfangener Bytes (unkomprimiert) liefern */
275 assert( Idx > NONE );
276 return My_Connections[Idx].bytes_in;
277 } /* Conn_RecvBytes */
281 Conn_ResetWCounter( void )
284 } /* Conn_ResetWCounter */
288 Conn_WCounter( void )
291 } /* Conn_WCounter */