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.
19 * Connection management: Global functions
31 #include "conn-func.h"
35 Conn_UpdateIdle( CONN_ID Idx )
38 My_Connections[Idx].lastprivmsg = time( NULL );
43 * Get signon time of a connection.
46 Conn_GetSignon(CONN_ID Idx)
49 return My_Connections[Idx].signon;
53 Conn_GetIdle( CONN_ID Idx )
55 /* Return Idle-Timer of a connetion */
57 return time( NULL ) - My_Connections[Idx].lastprivmsg;
62 Conn_LastPing( CONN_ID Idx )
65 return My_Connections[Idx].lastping;
70 Conn_SetPenalty( CONN_ID Idx, time_t Seconds )
72 /* set Penalty-Delay for a socket.
73 * during the penalty, the socket is ignored completely, no new
74 * data is read. This function only increases the penalty, it is
75 * not possible to decrease the penalty time.
80 assert( Seconds >= 0 );
82 t = time( NULL ) + Seconds;
83 if (t > My_Connections[Idx].delaytime)
84 My_Connections[Idx].delaytime = t;
87 Log(LOG_DEBUG, "Add penalty time on connection %d: %ld second(s).",
90 } /* Conn_SetPenalty */
94 Conn_ResetPenalty( CONN_ID Idx )
97 My_Connections[Idx].delaytime = 0;
98 } /* Conn_ResetPenalty */
102 Conn_ClearFlags( void )
106 for( i = 0; i < Pool_Size; i++ ) My_Connections[i].flag = 0;
107 } /* Conn_ClearFlags */
111 Conn_Flag( CONN_ID Idx )
113 assert( Idx > NONE );
114 return My_Connections[Idx].flag;
119 Conn_SetFlag( CONN_ID Idx, int Flag )
121 /* Connection markieren */
123 assert( Idx > NONE );
124 My_Connections[Idx].flag = Flag;
131 /* Connection-Struktur der ersten Verbindung liefern;
132 * Ist keine Verbindung vorhanden, wird NONE geliefert. */
136 for( i = 0; i < Pool_Size; i++ )
138 if( My_Connections[i].sock != NONE ) return i;
145 Conn_Next( CONN_ID Idx )
147 /* Naechste Verbindungs-Struktur liefern; existiert keine
148 * weitere, so wird NONE geliefert. */
152 assert( Idx > NONE );
154 for( i = Idx + 1; i < Pool_Size; i++ )
156 if( My_Connections[i].sock != NONE ) return i;
163 Conn_Options( CONN_ID Idx )
165 assert( Idx > NONE );
166 return My_Connections[Idx].options;
171 * Set connection option.
174 Conn_SetOption(CONN_ID Idx, int Option)
177 Conn_OPTION_ADD(&My_Connections[Idx], Option);
178 } /* 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);
218 * return number of messages sent on this connection so far
221 Conn_SendMsg( CONN_ID Idx )
224 assert( Idx > NONE );
225 return My_Connections[Idx].msg_out;
230 * return number of (uncompressed) bytes sent
231 * on this connection so far
234 Conn_SendBytes( CONN_ID Idx )
236 assert( Idx > NONE );
237 return My_Connections[Idx].bytes_out;
238 } /* Conn_SendBytes */
242 * return number of bytes pending in read buffer
245 Conn_RecvQ( CONN_ID Idx )
247 assert( Idx > NONE );
249 if( My_Connections[Idx].options & CONN_ZIP )
250 return array_bytes(&My_Connections[Idx].zip.rbuf);
253 return array_bytes(&My_Connections[Idx].rbuf);
258 * return number of messages received on this connection so far
261 Conn_RecvMsg( CONN_ID Idx )
263 assert( Idx > NONE );
264 return My_Connections[Idx].msg_in;
269 * return number of (uncompressed) bytes received on this
273 Conn_RecvBytes( CONN_ID Idx )
275 assert( Idx > NONE );
276 return My_Connections[Idx].bytes_in;
277 } /* Conn_RecvBytes */
280 * Return the remote IP address of this connection as string.
283 Conn_IPA(CONN_ID Idx)
286 return ng_ipaddr_tostr(&My_Connections[Idx].addr);
291 Conn_ResetWCounter( void )
294 } /* Conn_ResetWCounter */
298 Conn_WCounter( void )
301 } /* Conn_WCounter */