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 /* Connection markieren */
142 assert( Idx > NONE );
143 My_Connections[Idx].flag = Flag;
150 /* Connection-Struktur der ersten Verbindung liefern;
151 * Ist keine Verbindung vorhanden, wird NONE geliefert. */
155 for( i = 0; i < Pool_Size; i++ )
157 if( My_Connections[i].sock != NONE ) return i;
164 Conn_Next( CONN_ID Idx )
166 /* Naechste Verbindungs-Struktur liefern; existiert keine
167 * weitere, so wird NONE geliefert. */
171 assert( Idx > NONE );
173 for( i = Idx + 1; i < Pool_Size; i++ )
175 if( My_Connections[i].sock != NONE ) return i;
182 Conn_Options( CONN_ID Idx )
184 assert( Idx > NONE );
185 return My_Connections[Idx].options;
190 * Set connection option.
193 Conn_SetOption(CONN_ID Idx, int Option)
196 Conn_OPTION_ADD(&My_Connections[Idx], Option);
197 } /* Conn_SetOption */
201 * Get the start time of the connection.
202 * The result is the start time in seconds since 1970-01-01, as reported
203 * by the C function time(NULL).
206 Conn_StartTime( CONN_ID Idx )
212 /* Search client structure for this link ... */
213 c = Conn_GetClient(Idx);
215 return Client_StartTime(c);
218 } /* Conn_StartTime */
221 * return number of bytes queued for writing
224 Conn_SendQ( CONN_ID Idx )
226 assert( Idx > NONE );
228 if( My_Connections[Idx].options & CONN_ZIP )
229 return array_bytes(&My_Connections[Idx].zip.wbuf);
232 return array_bytes(&My_Connections[Idx].wbuf);
237 * return number of messages sent on this connection so far
240 Conn_SendMsg( CONN_ID Idx )
243 assert( Idx > NONE );
244 return My_Connections[Idx].msg_out;
249 * return number of (uncompressed) bytes sent
250 * on this connection so far
253 Conn_SendBytes( CONN_ID Idx )
255 assert( Idx > NONE );
256 return My_Connections[Idx].bytes_out;
257 } /* Conn_SendBytes */
261 * return number of bytes pending in read buffer
264 Conn_RecvQ( CONN_ID Idx )
266 assert( Idx > NONE );
268 if( My_Connections[Idx].options & CONN_ZIP )
269 return array_bytes(&My_Connections[Idx].zip.rbuf);
272 return array_bytes(&My_Connections[Idx].rbuf);
277 * return number of messages received on this connection so far
280 Conn_RecvMsg( CONN_ID Idx )
282 assert( Idx > NONE );
283 return My_Connections[Idx].msg_in;
288 * return number of (uncompressed) bytes received on this
292 Conn_RecvBytes( CONN_ID Idx )
294 assert( Idx > NONE );
295 return My_Connections[Idx].bytes_in;
296 } /* Conn_RecvBytes */
299 * Return the remote IP address of this connection as string.
302 Conn_IPA(CONN_ID Idx)
305 return ng_ipaddr_tostr(&My_Connections[Idx].addr);
310 Conn_ResetWCounter( void )
313 } /* Conn_ResetWCounter */
317 Conn_WCounter( void )
320 } /* Conn_WCounter */