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
28 #include "conn-func.h"
31 * Update "idle timestamp", the time of the last visible user action
32 * (e. g. like sending messages, joining or leaving channels).
34 * @param Idx Connection index.
37 Conn_UpdateIdle(CONN_ID Idx)
40 My_Connections[Idx].lastprivmsg = time(NULL);
44 * Update "ping timestamp", the time of the last outgoing PING request.
46 * @param Idx Connection index.
49 Conn_UpdatePing(CONN_ID Idx)
52 My_Connections[Idx].lastping = time(NULL);
56 * Get signon time of a connection.
59 Conn_GetSignon(CONN_ID Idx)
62 return My_Connections[Idx].signon;
66 Conn_GetIdle( CONN_ID Idx )
68 /* Return Idle-Timer of a connetion */
70 return time( NULL ) - My_Connections[Idx].lastprivmsg;
74 Conn_LastPing( CONN_ID Idx )
77 return My_Connections[Idx].lastping;
81 * Add "penalty time" for a connection.
83 * During the "penalty time" the socket is ignored completely, no new data
84 * is read. This function only increases the penalty, it is not possible to
85 * decrease the penalty time.
87 * @param Idex Connection index.
88 * @param Seconds Seconds to add.
89 * @see Conn_ResetPenalty
92 Conn_SetPenalty(CONN_ID Idx, time_t Seconds)
100 if (My_Connections[Idx].delaytime < t)
101 My_Connections[Idx].delaytime = t;
103 My_Connections[Idx].delaytime += Seconds;
107 "Add penalty time on connection %d: %ld second%s, total %ld second%s.",
108 Idx, (long)Seconds, Seconds != 1 ? "s" : "",
109 My_Connections[Idx].delaytime - t,
110 My_Connections[Idx].delaytime - t != 1 ? "s" : "");
112 } /* Conn_SetPenalty */
115 Conn_ClearFlags( void )
119 for( i = 0; i < Pool_Size; i++ ) My_Connections[i].flag = 0;
120 } /* Conn_ClearFlags */
123 Conn_Flag( CONN_ID Idx )
125 assert( Idx > NONE );
126 return My_Connections[Idx].flag;
130 Conn_SetFlag( CONN_ID Idx, int Flag )
132 assert( Idx > NONE );
133 My_Connections[Idx].flag = Flag;
141 for( i = 0; i < Pool_Size; i++ )
143 if( My_Connections[i].sock != NONE ) return i;
149 Conn_Next( CONN_ID Idx )
153 assert( Idx > NONE );
155 for( i = Idx + 1; i < Pool_Size; i++ )
157 if( My_Connections[i].sock != NONE ) return i;
163 Conn_Options( CONN_ID Idx )
165 assert( Idx > NONE );
166 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 */
180 * Get the start time of the connection.
181 * The result is the start time in seconds since 1970-01-01, as reported
182 * by the C function time(NULL).
185 Conn_StartTime( CONN_ID Idx )
191 /* Search client structure for this link ... */
192 c = Conn_GetClient(Idx);
194 return Client_StartTime(c);
197 } /* Conn_StartTime */
200 * return number of bytes queued for writing
203 Conn_SendQ( CONN_ID Idx )
205 assert( Idx > NONE );
207 if( My_Connections[Idx].options & CONN_ZIP )
208 return array_bytes(&My_Connections[Idx].zip.wbuf);
211 return array_bytes(&My_Connections[Idx].wbuf);
215 * return number of messages sent on this connection so far
218 Conn_SendMsg( CONN_ID Idx )
221 assert( Idx > NONE );
222 return My_Connections[Idx].msg_out;
226 * return number of (uncompressed) bytes sent
227 * on this connection so far
230 Conn_SendBytes( CONN_ID Idx )
232 assert( Idx > NONE );
233 return My_Connections[Idx].bytes_out;
234 } /* Conn_SendBytes */
237 * return number of bytes pending in read buffer
240 Conn_RecvQ( CONN_ID Idx )
242 assert( Idx > NONE );
244 if( My_Connections[Idx].options & CONN_ZIP )
245 return array_bytes(&My_Connections[Idx].zip.rbuf);
248 return array_bytes(&My_Connections[Idx].rbuf);
252 * return number of messages received on this connection so far
255 Conn_RecvMsg( CONN_ID Idx )
257 assert( Idx > NONE );
258 return My_Connections[Idx].msg_in;
262 * return number of (uncompressed) bytes received on this
266 Conn_RecvBytes( CONN_ID Idx )
268 assert( Idx > NONE );
269 return My_Connections[Idx].bytes_in;
270 } /* Conn_RecvBytes */
273 * Return the remote IP address of this connection as string.
276 Conn_IPA(CONN_ID Idx)
279 return ng_ipaddr_tostr(&My_Connections[Idx].addr);
283 Conn_ResetWCounter( void )
286 } /* Conn_ResetWCounter */
289 Conn_WCounter( void )
292 } /* Conn_WCounter */