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 * Update "idle timestamp", the time of the last visible user action
35 * (e. g. like sending messages, joining or leaving channels).
37 * @param Idx Connection index.
40 Conn_UpdateIdle(CONN_ID Idx)
43 My_Connections[Idx].lastprivmsg = time(NULL);
47 * Update "ping timestamp", the time of the last outgoing PING request.
49 * @param Idx Connection index.
52 Conn_UpdatePing(CONN_ID Idx)
55 My_Connections[Idx].lastping = time(NULL);
59 * Get signon time of a connection.
62 Conn_GetSignon(CONN_ID Idx)
65 return My_Connections[Idx].signon;
69 Conn_GetIdle( CONN_ID Idx )
71 /* Return Idle-Timer of a connetion */
73 return time( NULL ) - My_Connections[Idx].lastprivmsg;
78 Conn_LastPing( CONN_ID Idx )
81 return My_Connections[Idx].lastping;
86 * Add "penalty time" for a connection.
88 * During the "penalty time" the socket is ignored completely, no new data
89 * is read. This function only increases the penalty, it is not possible to
90 * decrease the penalty time.
92 * @param Idex Connection index.
93 * @param Seconds Seconds to add.
94 * @see Conn_ResetPenalty
97 Conn_SetPenalty(CONN_ID Idx, time_t Seconds)
102 assert(Seconds >= 0);
105 if (My_Connections[Idx].delaytime < t)
106 My_Connections[Idx].delaytime = t;
108 My_Connections[Idx].delaytime += Seconds;
112 "Add penalty time on connection %d: %ld second%s, total %ld second%s.",
113 Idx, (long)Seconds, Seconds != 1 ? "s" : "",
114 My_Connections[Idx].delaytime - t,
115 My_Connections[Idx].delaytime - t != 1 ? "s" : "");
117 } /* Conn_SetPenalty */
121 Conn_ClearFlags( void )
125 for( i = 0; i < Pool_Size; i++ ) My_Connections[i].flag = 0;
126 } /* Conn_ClearFlags */
130 Conn_Flag( CONN_ID Idx )
132 assert( Idx > NONE );
133 return My_Connections[Idx].flag;
138 Conn_SetFlag( CONN_ID Idx, int Flag )
140 assert( Idx > NONE );
141 My_Connections[Idx].flag = Flag;
150 for( i = 0; i < Pool_Size; i++ )
152 if( My_Connections[i].sock != NONE ) return i;
159 Conn_Next( CONN_ID Idx )
163 assert( Idx > NONE );
165 for( i = Idx + 1; i < Pool_Size; i++ )
167 if( My_Connections[i].sock != NONE ) return i;
174 Conn_Options( CONN_ID Idx )
176 assert( Idx > NONE );
177 return My_Connections[Idx].options;
182 * Set connection option.
185 Conn_SetOption(CONN_ID Idx, int Option)
188 Conn_OPTION_ADD(&My_Connections[Idx], Option);
189 } /* Conn_SetOption */
193 * Get the start time of the connection.
194 * The result is the start time in seconds since 1970-01-01, as reported
195 * by the C function time(NULL).
198 Conn_StartTime( CONN_ID Idx )
204 /* Search client structure for this link ... */
205 c = Conn_GetClient(Idx);
207 return Client_StartTime(c);
210 } /* Conn_StartTime */
213 * return number of bytes queued for writing
216 Conn_SendQ( CONN_ID Idx )
218 assert( Idx > NONE );
220 if( My_Connections[Idx].options & CONN_ZIP )
221 return array_bytes(&My_Connections[Idx].zip.wbuf);
224 return array_bytes(&My_Connections[Idx].wbuf);
229 * return number of messages sent on this connection so far
232 Conn_SendMsg( CONN_ID Idx )
235 assert( Idx > NONE );
236 return My_Connections[Idx].msg_out;
241 * return number of (uncompressed) bytes sent
242 * on this connection so far
245 Conn_SendBytes( CONN_ID Idx )
247 assert( Idx > NONE );
248 return My_Connections[Idx].bytes_out;
249 } /* Conn_SendBytes */
253 * return number of bytes pending in read buffer
256 Conn_RecvQ( CONN_ID Idx )
258 assert( Idx > NONE );
260 if( My_Connections[Idx].options & CONN_ZIP )
261 return array_bytes(&My_Connections[Idx].zip.rbuf);
264 return array_bytes(&My_Connections[Idx].rbuf);
269 * return number of messages received on this connection so far
272 Conn_RecvMsg( CONN_ID Idx )
274 assert( Idx > NONE );
275 return My_Connections[Idx].msg_in;
280 * return number of (uncompressed) bytes received on this
284 Conn_RecvBytes( CONN_ID Idx )
286 assert( Idx > NONE );
287 return My_Connections[Idx].bytes_in;
288 } /* Conn_RecvBytes */
291 * Return the remote IP address of this connection as string.
294 Conn_IPA(CONN_ID Idx)
297 return ng_ipaddr_tostr(&My_Connections[Idx].addr);
302 Conn_ResetWCounter( void )
305 } /* Conn_ResetWCounter */
309 Conn_WCounter( void )
312 } /* Conn_WCounter */