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"
33 * Update "idle timestamp", the time of the last visible user action
34 * (e. g. like sending messages, joining or leaving channels).
36 * @param Idx Connection index.
39 Conn_UpdateIdle(CONN_ID Idx)
42 My_Connections[Idx].lastprivmsg = time(NULL);
46 * Update "ping timestamp", the time of the last outgoing PING request.
48 * @param Idx Connection index.
51 Conn_UpdatePing(CONN_ID Idx)
54 My_Connections[Idx].lastping = time(NULL);
58 * Get signon time of a connection.
61 Conn_GetSignon(CONN_ID Idx)
64 return My_Connections[Idx].signon;
68 Conn_GetIdle( CONN_ID Idx )
70 /* Return Idle-Timer of a connetion */
72 return time( NULL ) - My_Connections[Idx].lastprivmsg;
76 Conn_LastPing( CONN_ID Idx )
79 return My_Connections[Idx].lastping;
83 * Add "penalty time" for a connection.
85 * During the "penalty time" the socket is ignored completely, no new data
86 * is read. This function only increases the penalty, it is not possible to
87 * decrease the penalty time.
89 * @param Idex Connection index.
90 * @param Seconds Seconds to add.
91 * @see Conn_ResetPenalty
94 Conn_SetPenalty(CONN_ID Idx, time_t Seconds)
102 if (My_Connections[Idx].delaytime < t)
103 My_Connections[Idx].delaytime = t;
105 My_Connections[Idx].delaytime += Seconds;
109 "Add penalty time on connection %d: %ld second%s, total %ld second%s.",
110 Idx, (long)Seconds, Seconds != 1 ? "s" : "",
111 My_Connections[Idx].delaytime - t,
112 My_Connections[Idx].delaytime - t != 1 ? "s" : "");
114 } /* Conn_SetPenalty */
117 Conn_ClearFlags( void )
121 for( i = 0; i < Pool_Size; i++ ) My_Connections[i].flag = 0;
122 } /* Conn_ClearFlags */
125 Conn_Flag( CONN_ID Idx )
127 assert( Idx > NONE );
128 return My_Connections[Idx].flag;
132 Conn_SetFlag( CONN_ID Idx, int Flag )
134 assert( Idx > NONE );
135 My_Connections[Idx].flag = Flag;
143 for( i = 0; i < Pool_Size; i++ )
145 if( My_Connections[i].sock != NONE ) return i;
151 Conn_Next( CONN_ID Idx )
155 assert( Idx > NONE );
157 for( i = Idx + 1; i < Pool_Size; i++ )
159 if( My_Connections[i].sock != NONE ) return i;
165 Conn_Options( CONN_ID Idx )
167 assert( Idx > NONE );
168 return My_Connections[Idx].options;
172 * Set connection option.
175 Conn_SetOption(CONN_ID Idx, int Option)
178 Conn_OPTION_ADD(&My_Connections[Idx], Option);
179 } /* Conn_SetOption */
182 * Get the start time of the connection.
183 * The result is the start time in seconds since 1970-01-01, as reported
184 * by the C function time(NULL).
187 Conn_StartTime( CONN_ID Idx )
193 /* Search client structure for this link ... */
194 c = Conn_GetClient(Idx);
196 return Client_StartTime(c);
199 } /* Conn_StartTime */
202 * return number of bytes queued for writing
205 Conn_SendQ( CONN_ID Idx )
207 assert( Idx > NONE );
209 if( My_Connections[Idx].options & CONN_ZIP )
210 return array_bytes(&My_Connections[Idx].zip.wbuf);
213 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;
228 * return number of (uncompressed) bytes sent
229 * on this connection so far
232 Conn_SendBytes( CONN_ID Idx )
234 assert( Idx > NONE );
235 return My_Connections[Idx].bytes_out;
236 } /* Conn_SendBytes */
239 * return number of bytes pending in read buffer
242 Conn_RecvQ( CONN_ID Idx )
244 assert( Idx > NONE );
246 if( My_Connections[Idx].options & CONN_ZIP )
247 return array_bytes(&My_Connections[Idx].zip.rbuf);
250 return array_bytes(&My_Connections[Idx].rbuf);
254 * return number of messages received on this connection so far
257 Conn_RecvMsg( CONN_ID Idx )
259 assert( Idx > NONE );
260 return My_Connections[Idx].msg_in;
264 * return number of (uncompressed) bytes received on this
268 Conn_RecvBytes( CONN_ID Idx )
270 assert( Idx > NONE );
271 return My_Connections[Idx].bytes_in;
272 } /* Conn_RecvBytes */
275 * Return the remote IP address of this connection as string.
278 Conn_IPA(CONN_ID Idx)
281 return ng_ipaddr_tostr(&My_Connections[Idx].addr);
285 Conn_ResetWCounter( void )
288 } /* Conn_ResetWCounter */
291 Conn_WCounter( void )
294 } /* Conn_WCounter */