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 Conn_SetPenalty( CONN_ID Idx, time_t Seconds )
71 /* set Penalty-Delay for a socket.
72 * during the penalty, the socket is ignored completely, no new
73 * data is read. This function only increases the penalty, it is
74 * not possible to decrease the penalty time.
79 assert( Seconds >= 0 );
81 t = time( NULL ) + Seconds;
82 if (t > My_Connections[Idx].delaytime)
83 My_Connections[Idx].delaytime = t;
86 Log(LOG_DEBUG, "Add penalty time on connection %d: %ld second(s).",
89 } /* Conn_SetPenalty */
93 Conn_ResetPenalty( CONN_ID Idx )
96 My_Connections[Idx].delaytime = 0;
97 } /* Conn_ResetPenalty */
101 Conn_ClearFlags( void )
105 for( i = 0; i < Pool_Size; i++ ) My_Connections[i].flag = 0;
106 } /* Conn_ClearFlags */
110 Conn_Flag( CONN_ID Idx )
112 assert( Idx > NONE );
113 return My_Connections[Idx].flag;
118 Conn_SetFlag( CONN_ID Idx, int Flag )
120 /* Connection markieren */
122 assert( Idx > NONE );
123 My_Connections[Idx].flag = Flag;
130 /* Connection-Struktur der ersten Verbindung liefern;
131 * Ist keine Verbindung vorhanden, wird NONE geliefert. */
135 for( i = 0; i < Pool_Size; i++ )
137 if( My_Connections[i].sock != NONE ) return i;
144 Conn_Next( CONN_ID Idx )
146 /* Naechste Verbindungs-Struktur liefern; existiert keine
147 * weitere, so wird NONE geliefert. */
151 assert( Idx > NONE );
153 for( i = Idx + 1; i < Pool_Size; i++ )
155 if( My_Connections[i].sock != NONE ) return i;
162 Conn_Options( CONN_ID Idx )
164 assert( Idx > NONE );
165 return My_Connections[Idx].options;
170 * Set connection option.
173 Conn_SetOption(CONN_ID Idx, int Option)
176 Conn_OPTION_ADD(&My_Connections[Idx], Option);
177 } /* Conn_SetOption */
181 * Get the start time of the connection.
182 * The result is the start time in seconds since 1970-01-01, as reported
183 * by the C function time(NULL).
186 Conn_StartTime( CONN_ID Idx )
192 /* Search client structure for this link ... */
193 c = Conn_GetClient(Idx);
195 return Client_StartTime(c);
198 } /* Conn_StartTime */
201 * return number of bytes queued for writing
204 Conn_SendQ( CONN_ID Idx )
206 assert( Idx > NONE );
208 if( My_Connections[Idx].options & CONN_ZIP )
209 return array_bytes(&My_Connections[Idx].zip.wbuf);
212 return array_bytes(&My_Connections[Idx].wbuf);
217 * return number of messages sent on this connection so far
220 Conn_SendMsg( CONN_ID Idx )
223 assert( Idx > NONE );
224 return My_Connections[Idx].msg_out;
229 * return number of (uncompressed) bytes sent
230 * on this connection so far
233 Conn_SendBytes( CONN_ID Idx )
235 assert( Idx > NONE );
236 return My_Connections[Idx].bytes_out;
237 } /* Conn_SendBytes */
241 * return number of bytes pending in read buffer
244 Conn_RecvQ( CONN_ID Idx )
246 assert( Idx > NONE );
248 if( My_Connections[Idx].options & CONN_ZIP )
249 return array_bytes(&My_Connections[Idx].zip.rbuf);
252 return array_bytes(&My_Connections[Idx].rbuf);
257 * return number of messages received on this connection so far
260 Conn_RecvMsg( CONN_ID Idx )
262 assert( Idx > NONE );
263 return My_Connections[Idx].msg_in;
268 * return number of (uncompressed) bytes received on this
272 Conn_RecvBytes( CONN_ID Idx )
274 assert( Idx > NONE );
275 return My_Connections[Idx].bytes_in;
276 } /* Conn_RecvBytes */
279 * Return the remote IP address of this connection as string.
282 Conn_IPA(CONN_ID Idx)
285 return ng_ipaddr_tostr(&My_Connections[Idx].addr);
290 Conn_ResetWCounter( void )
293 } /* Conn_ResetWCounter */
297 Conn_WCounter( void )
300 } /* Conn_WCounter */