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.
11 * Connection management: Global functions
28 #include "conn-func.h"
32 Conn_UpdateIdle( CONN_ID Idx )
35 My_Connections[Idx].lastprivmsg = time( NULL );
40 * Get signon time of a connection.
43 Conn_GetSignon(CONN_ID Idx)
46 return My_Connections[Idx].signon;
50 Conn_GetIdle( CONN_ID Idx )
52 /* Return Idle-Timer of a connetion */
54 return time( NULL ) - My_Connections[Idx].lastprivmsg;
59 Conn_LastPing( CONN_ID Idx )
62 return My_Connections[Idx].lastping;
67 Conn_SetPenalty( CONN_ID Idx, time_t Seconds )
69 /* set Penalty-Delay for a socket.
70 * during the penalty, the socket is ignored completely, no new
71 * data is read. This function only increases the penalty, it is
72 * not possible to decrease the penalty time.
77 assert( Seconds >= 0 );
79 t = time( NULL ) + Seconds;
80 if (t > My_Connections[Idx].delaytime)
81 My_Connections[Idx].delaytime = t;
84 Log(LOG_DEBUG, "Add penalty time on connection %d: %ld second(s).",
87 } /* Conn_SetPenalty */
91 Conn_ResetPenalty( CONN_ID Idx )
94 My_Connections[Idx].delaytime = 0;
95 } /* Conn_ResetPenalty */
99 Conn_ClearFlags( void )
103 for( i = 0; i < Pool_Size; i++ ) My_Connections[i].flag = 0;
104 } /* Conn_ClearFlags */
108 Conn_Flag( CONN_ID Idx )
110 assert( Idx > NONE );
111 return My_Connections[Idx].flag;
116 Conn_SetFlag( CONN_ID Idx, int Flag )
118 /* Connection markieren */
120 assert( Idx > NONE );
121 My_Connections[Idx].flag = Flag;
128 /* Connection-Struktur der ersten Verbindung liefern;
129 * Ist keine Verbindung vorhanden, wird NONE geliefert. */
133 for( i = 0; i < Pool_Size; i++ )
135 if( My_Connections[i].sock != NONE ) return i;
142 Conn_Next( CONN_ID Idx )
144 /* Naechste Verbindungs-Struktur liefern; existiert keine
145 * weitere, so wird NONE geliefert. */
149 assert( Idx > NONE );
151 for( i = Idx + 1; i < Pool_Size; i++ )
153 if( My_Connections[i].sock != NONE ) return i;
160 Conn_Options( CONN_ID Idx )
162 assert( Idx > NONE );
163 return My_Connections[Idx].options;
168 * Set connection option.
171 Conn_SetOption(CONN_ID Idx, int Option)
174 Conn_OPTION_ADD(&My_Connections[Idx], Option);
175 } /* Conn_SetOption */
179 * Get the start time of the connection.
180 * The result is the start time in seconds since 1970-01-01, as reported
181 * by the C function time(NULL).
184 Conn_StartTime( CONN_ID Idx )
190 /* Search client structure for this link ... */
191 c = Conn_GetClient(Idx);
193 return Client_StartTime(c);
196 } /* Conn_StartTime */
199 * return number of bytes queued for writing
202 Conn_SendQ( CONN_ID Idx )
204 assert( Idx > NONE );
206 if( My_Connections[Idx].options & CONN_ZIP )
207 return array_bytes(&My_Connections[Idx].zip.wbuf);
210 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;
227 * return number of (uncompressed) bytes sent
228 * on this connection so far
231 Conn_SendBytes( CONN_ID Idx )
233 assert( Idx > NONE );
234 return My_Connections[Idx].bytes_out;
235 } /* 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);
255 * return number of messages received on this connection so far
258 Conn_RecvMsg( CONN_ID Idx )
260 assert( Idx > NONE );
261 return My_Connections[Idx].msg_in;
266 * return number of (uncompressed) bytes received on this
270 Conn_RecvBytes( CONN_ID Idx )
272 assert( Idx > NONE );
273 return My_Connections[Idx].bytes_in;
274 } /* Conn_RecvBytes */
278 Conn_ResetWCounter( void )
281 } /* Conn_ResetWCounter */
285 Conn_WCounter( void )
288 } /* Conn_WCounter */