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.
18 * Connection management: Global functions
30 #include "conn-func.h"
34 Conn_UpdateIdle( CONN_ID Idx )
37 My_Connections[Idx].lastprivmsg = time( NULL );
42 * Get signon time of a connection.
45 Conn_GetSignon(CONN_ID Idx)
48 return My_Connections[Idx].signon;
52 Conn_GetIdle( CONN_ID Idx )
54 /* Return Idle-Timer of a connetion */
56 return time( NULL ) - My_Connections[Idx].lastprivmsg;
61 Conn_LastPing( CONN_ID Idx )
64 return My_Connections[Idx].lastping;
69 * Add "penalty time" for a connection.
71 * During the "penalty time" the socket is ignored completely, no new data
72 * is read. This function only increases the penalty, it is not possible to
73 * decrease the penalty time.
75 * @param Idex Connection index.
76 * @param Seconds Seconds to add.
77 * @see Conn_ResetPenalty
80 Conn_SetPenalty(CONN_ID Idx, time_t Seconds)
88 if (My_Connections[Idx].delaytime < t)
89 My_Connections[Idx].delaytime = t;
91 My_Connections[Idx].delaytime += Seconds;
95 "Add penalty time on connection %d: %ld second%s, total %ld second%s.",
96 Idx, (long)Seconds, Seconds != 1 ? "s" : "",
97 My_Connections[Idx].delaytime - t,
98 My_Connections[Idx].delaytime - t != 1 ? "s" : "");
100 } /* Conn_SetPenalty */
104 * Reset the "penalty time" for one connection.
106 * @param Idx Connection index.
107 * @see Conn_SetPenalty
110 Conn_ResetPenalty(CONN_ID Idx)
114 My_Connections[Idx].delaytime = 0;
116 Log(LOG_DEBUG, "Penalty time on connection %d has been reset.");
118 } /* Conn_ResetPenalty */
122 Conn_ClearFlags( void )
126 for( i = 0; i < Pool_Size; i++ ) My_Connections[i].flag = 0;
127 } /* Conn_ClearFlags */
131 Conn_Flag( CONN_ID Idx )
133 assert( Idx > NONE );
134 return My_Connections[Idx].flag;
139 Conn_SetFlag( CONN_ID Idx, int Flag )
141 /* Connection markieren */
143 assert( Idx > NONE );
144 My_Connections[Idx].flag = Flag;
151 /* Connection-Struktur der ersten Verbindung liefern;
152 * Ist keine Verbindung vorhanden, wird NONE geliefert. */
156 for( i = 0; i < Pool_Size; i++ )
158 if( My_Connections[i].sock != NONE ) return i;
165 Conn_Next( CONN_ID Idx )
167 /* Naechste Verbindungs-Struktur liefern; existiert keine
168 * weitere, so wird NONE geliefert. */
172 assert( Idx > NONE );
174 for( i = Idx + 1; i < Pool_Size; i++ )
176 if( My_Connections[i].sock != NONE ) return i;
183 Conn_Options( CONN_ID Idx )
185 assert( Idx > NONE );
186 return My_Connections[Idx].options;
191 * Set connection option.
194 Conn_SetOption(CONN_ID Idx, int Option)
197 Conn_OPTION_ADD(&My_Connections[Idx], Option);
198 } /* Conn_SetOption */
202 * Get the start time of the connection.
203 * The result is the start time in seconds since 1970-01-01, as reported
204 * by the C function time(NULL).
207 Conn_StartTime( CONN_ID Idx )
213 /* Search client structure for this link ... */
214 c = Conn_GetClient(Idx);
216 return Client_StartTime(c);
219 } /* Conn_StartTime */
222 * return number of bytes queued for writing
225 Conn_SendQ( CONN_ID Idx )
227 assert( Idx > NONE );
229 if( My_Connections[Idx].options & CONN_ZIP )
230 return array_bytes(&My_Connections[Idx].zip.wbuf);
233 return array_bytes(&My_Connections[Idx].wbuf);
238 * return number of messages sent on this connection so far
241 Conn_SendMsg( CONN_ID Idx )
244 assert( Idx > NONE );
245 return My_Connections[Idx].msg_out;
250 * return number of (uncompressed) bytes sent
251 * on this connection so far
254 Conn_SendBytes( CONN_ID Idx )
256 assert( Idx > NONE );
257 return My_Connections[Idx].bytes_out;
258 } /* Conn_SendBytes */
262 * return number of bytes pending in read buffer
265 Conn_RecvQ( CONN_ID Idx )
267 assert( Idx > NONE );
269 if( My_Connections[Idx].options & CONN_ZIP )
270 return array_bytes(&My_Connections[Idx].zip.rbuf);
273 return array_bytes(&My_Connections[Idx].rbuf);
278 * return number of messages received on this connection so far
281 Conn_RecvMsg( CONN_ID Idx )
283 assert( Idx > NONE );
284 return My_Connections[Idx].msg_in;
289 * return number of (uncompressed) bytes received on this
293 Conn_RecvBytes( CONN_ID Idx )
295 assert( Idx > NONE );
296 return My_Connections[Idx].bytes_in;
297 } /* Conn_RecvBytes */
300 * Return the remote IP address of this connection as string.
303 Conn_IPA(CONN_ID Idx)
306 return ng_ipaddr_tostr(&My_Connections[Idx].addr);
311 Conn_ResetWCounter( void )
314 } /* Conn_ResetWCounter */
318 Conn_WCounter( void )
321 } /* Conn_WCounter */