1
0
mirror of https://github.com/osmarks/ngircd.git synced 2025-02-15 00:30:16 +00:00

make needlesly global function Conn_Write static. (from HEAD)

This commit is contained in:
Florian Westphal 2007-05-09 13:21:38 +00:00
parent 001c3bb1b4
commit cddc7e719d
2 changed files with 25 additions and 22 deletions

View File

@ -17,7 +17,7 @@
#include "portab.h" #include "portab.h"
#include "io.h" #include "io.h"
static char UNUSED id[] = "$Id: conn.c,v 1.198.2.4 2007/05/02 12:22:44 fw Exp $"; static char UNUSED id[] = "$Id: conn.c,v 1.198.2.5 2007/05/09 13:21:38 fw Exp $";
#include "imp.h" #include "imp.h"
#include <assert.h> #include <assert.h>
@ -83,6 +83,7 @@ static char UNUSED id[] = "$Id: conn.c,v 1.198.2.4 2007/05/02 12:22:44 fw Exp $"
static bool Handle_Write PARAMS(( CONN_ID Idx )); static bool Handle_Write PARAMS(( CONN_ID Idx ));
static bool Conn_Write PARAMS(( CONN_ID Idx, char *Data, size_t Len ));
static int New_Connection PARAMS(( int Sock )); static int New_Connection PARAMS(( int Sock ));
static CONN_ID Socket2Index PARAMS(( int Sock )); static CONN_ID Socket2Index PARAMS(( int Sock ));
static void Read_Request PARAMS(( CONN_ID Idx )); static void Read_Request PARAMS(( CONN_ID Idx ));
@ -607,36 +608,40 @@ va_dcl
} /* Conn_WriteStr */ } /* Conn_WriteStr */
GLOBAL bool /**
* Append Data to outbound write buf.
* @param Idx Index fo the connection.
* @param Data pointer to data
* @param Len length of Data
* @return true on success, false otherwise.
*/
static bool
Conn_Write( CONN_ID Idx, char *Data, size_t Len ) Conn_Write( CONN_ID Idx, char *Data, size_t Len )
{ {
/* Daten in Socket schreiben. Bei "fatalen" Fehlern wird
* der Client disconnectiert und false geliefert. */
assert( Idx > NONE ); assert( Idx > NONE );
assert( Data != NULL ); assert( Data != NULL );
assert( Len > 0 ); assert( Len > 0 );
/* Ist der entsprechende Socket ueberhaupt noch offen? In einem /* Is the socket still open? A previous call to Conn_Write()
* "Handler-Durchlauf" kann es passieren, dass dem nicht mehr so * may have closed the connection due to a fatal error.
* ist, wenn einer von mehreren Conn_Write()'s fehlgeschlagen ist. * In this case it is sufficient to return an error */
* In diesem Fall wird hier einfach ein Fehler geliefert. */
if( My_Connections[Idx].sock <= NONE ) { if( My_Connections[Idx].sock <= NONE ) {
LogDebug("Skipped write on closed socket (connection %d).", Idx ); LogDebug("Skipped write on closed socket (connection %d).", Idx );
return false; return false;
} }
/* Pruefen, ob im Schreibpuffer genuegend Platz ist. Ziel ist es, /* check if outbound buffer has enough space for data.
* moeglichts viel im Puffer zu haben und _nicht_ gleich alles auf den * the idea is to keep data buffered before sending, e.g. to improve
* Socket zu schreiben (u.a. wg. Komprimierung). */ * compression */
if( array_bytes(&My_Connections[Idx].wbuf) >= WRITEBUFFER_LEN) { if( array_bytes(&My_Connections[Idx].wbuf) >= WRITEBUFFER_LEN) {
/* Der Puffer ist dummerweise voll. Jetzt versuchen, den Puffer /* Buffer is full, flush. Handle_Write deals with low-level errors, if any. */
* zu schreiben, wenn das nicht klappt, haben wir ein Problem ... */
if( ! Handle_Write( Idx )) return false; if( ! Handle_Write( Idx )) return false;
/* check again: if our writebuf is twice als large as the initial limit: Kill connection */ /* check again: if our writebuf is twice als large as the initial limit: Kill connection */
if( array_bytes(&My_Connections[Idx].wbuf) >= (WRITEBUFFER_LEN*2)) { if( array_bytes(&My_Connections[Idx].wbuf) >= (WRITEBUFFER_LEN*2)) {
Log( LOG_NOTICE, "Write buffer overflow (connection %d)!", Idx ); Log(LOG_NOTICE, "Write buffer overflow (connection %d, size %lu byte)!", Idx,
(unsigned long) array_bytes(&My_Connections[Idx].wbuf));
Conn_Close( Idx, "Write buffer overflow!", NULL, false ); Conn_Close( Idx, "Write buffer overflow!", NULL, false );
return false; return false;
} }
@ -644,13 +649,13 @@ Conn_Write( CONN_ID Idx, char *Data, size_t Len )
#ifdef ZLIB #ifdef ZLIB
if ( Conn_OPTION_ISSET( &My_Connections[Idx], CONN_ZIP )) { if ( Conn_OPTION_ISSET( &My_Connections[Idx], CONN_ZIP )) {
/* Daten komprimieren und in Puffer kopieren */ /* compress and move data to write buffer */
if( ! Zip_Buffer( Idx, Data, Len )) return false; if( ! Zip_Buffer( Idx, Data, Len )) return false;
} }
else else
#endif #endif
{ {
/* Daten in Puffer kopieren */ /* copy data to write buffer */
if (!array_catb( &My_Connections[Idx].wbuf, Data, Len )) if (!array_catb( &My_Connections[Idx].wbuf, Data, Len ))
return false; return false;
@ -692,7 +697,7 @@ Conn_Close( CONN_ID Idx, char *LogMsg, char *FwdMsg, bool InformClient )
/* Mark link as "closing" */ /* Mark link as "closing" */
Conn_OPTION_ADD( &My_Connections[Idx], CONN_ISCLOSING ); Conn_OPTION_ADD( &My_Connections[Idx], CONN_ISCLOSING );
if (LogMsg) if (LogMsg)
txt = LogMsg; txt = LogMsg;
else else
@ -720,7 +725,6 @@ Conn_Close( CONN_ID Idx, char *LogMsg, char *FwdMsg, bool InformClient )
(double)My_Connections[Idx].bytes_out / 1024); (double)My_Connections[Idx].bytes_out / 1024);
} }
#endif #endif
/* Send ERROR to client (see RFC!) */ /* Send ERROR to client (see RFC!) */
if (FwdMsg) if (FwdMsg)
Conn_WriteStr(Idx, "ERROR :%s", FwdMsg); Conn_WriteStr(Idx, "ERROR :%s", FwdMsg);
@ -1631,9 +1635,9 @@ Conn_GetClient( CONN_ID Idx )
assert( Idx >= 0 ); assert( Idx >= 0 );
c = array_get(&My_ConnArray, sizeof (CONNECTION), (size_t)Idx); c = array_get(&My_ConnArray, sizeof (CONNECTION), (size_t)Idx);
assert(c != NULL); assert(c != NULL);
return c ? c->client : NULL; return c ? c->client : NULL;
} }

View File

@ -8,7 +8,7 @@
* (at your option) any later version. * (at your option) any later version.
* Please read the file COPYING, README and AUTHORS for more information. * Please read the file COPYING, README and AUTHORS for more information.
* *
* $Id: conn.h,v 1.42 2006/05/10 21:24:01 alex Exp $ * $Id: conn.h,v 1.42.2.1 2007/05/09 13:21:38 fw Exp $
* *
* Connection management (header) * Connection management (header)
*/ */
@ -88,7 +88,6 @@ GLOBAL void Conn_ExitListeners PARAMS(( void ));
GLOBAL void Conn_Handler PARAMS(( void )); GLOBAL void Conn_Handler PARAMS(( void ));
GLOBAL bool Conn_Write PARAMS(( CONN_ID Idx, char *Data, size_t Len ));
GLOBAL bool Conn_WriteStr PARAMS(( CONN_ID Idx, char *Format, ... )); GLOBAL bool Conn_WriteStr PARAMS(( CONN_ID Idx, char *Format, ... ));
GLOBAL void Conn_Close PARAMS(( CONN_ID Idx, char *LogMsg, char *FwdMsg, bool InformClient )); GLOBAL void Conn_Close PARAMS(( CONN_ID Idx, char *LogMsg, char *FwdMsg, bool InformClient ));