use strlcat return value; don't call time() repeatedly. [from HEAD]

This commit is contained in:
Florian Westphal
2006-03-18 22:30:45 +00:00
parent 3179bd3090
commit c35b810b90
+14 -8
View File
@@ -16,7 +16,7 @@
#include "portab.h" #include "portab.h"
static char UNUSED id[] = "$Id: conn.c,v 1.155.2.3 2005/10/11 19:28:47 alex Exp $"; static char UNUSED id[] = "$Id: conn.c,v 1.155.2.4 2006/03/18 22:30:45 fw Exp $";
#include "imp.h" #include "imp.h"
#include <assert.h> #include <assert.h>
@@ -93,7 +93,7 @@ LOCAL void Init_Conn_Struct PARAMS(( CONN_ID Idx ));
LOCAL bool Init_Socket PARAMS(( int Sock )); LOCAL bool Init_Socket PARAMS(( int Sock ));
LOCAL void New_Server PARAMS(( int Server, CONN_ID Idx )); LOCAL void New_Server PARAMS(( int Server, CONN_ID Idx ));
LOCAL void Read_Resolver_Result PARAMS(( int r_fd )); LOCAL void Read_Resolver_Result PARAMS(( int r_fd ));
LOCAL void Simple_Message PARAMS(( int Sock, char *Msg )); LOCAL void Simple_Message PARAMS(( int Sock, const char *Msg ));
LOCAL int Count_Connections PARAMS(( struct sockaddr_in addr )); LOCAL int Count_Connections PARAMS(( struct sockaddr_in addr ));
LOCAL fd_set My_Listeners; LOCAL fd_set My_Listeners;
@@ -538,6 +538,7 @@ va_dcl
#endif #endif
{ {
char buffer[COMMAND_LEN]; char buffer[COMMAND_LEN];
size_t len;
bool ok; bool ok;
va_list ap; va_list ap;
@@ -583,8 +584,9 @@ va_dcl
Log(LOG_DEBUG, " -> connection %d: '%s'.", Idx, buffer); Log(LOG_DEBUG, " -> connection %d: '%s'.", Idx, buffer);
#endif #endif
strlcat( buffer, "\r\n", sizeof( buffer )); len = strlcat( buffer, "\r\n", sizeof( buffer ));
ok = Conn_Write( Idx, buffer, strlen( buffer )); assert(len < COMMAND_LEN);
ok = Conn_Write(Idx, buffer, len);
My_Connections[Idx].msg_out++; My_Connections[Idx].msg_out++;
va_end( ap ); va_end( ap );
@@ -1186,15 +1188,17 @@ Handle_Buffer( CONN_ID Idx )
char *ptr; char *ptr;
int len, delta; int len, delta;
bool action, result; bool action, result;
time_t starttime;
#ifdef ZLIB #ifdef ZLIB
bool old_z; bool old_z;
#endif #endif
starttime = time(NULL);
result = false; result = false;
do do
{ {
/* Check penalty */ /* Check penalty */
if( My_Connections[Idx].delaytime > time( NULL )) return result; if( My_Connections[Idx].delaytime > starttime) return result;
#ifdef ZLIB #ifdef ZLIB
/* ggf. noch unkomprimiete Daten weiter entpacken */ /* ggf. noch unkomprimiete Daten weiter entpacken */
@@ -1691,9 +1695,10 @@ try_resolve:
LOCAL void LOCAL void
Simple_Message( int Sock, char *Msg ) Simple_Message( int Sock, const char *Msg )
{ {
char buf[COMMAND_LEN]; char buf[COMMAND_LEN];
size_t len;
/* Write "simple" message to socket, without using compression /* Write "simple" message to socket, without using compression
* or even the connection write buffers. Used e.g. for error * or even the connection write buffers. Used e.g. for error
* messages by New_Connection(). */ * messages by New_Connection(). */
@@ -1701,8 +1706,9 @@ Simple_Message( int Sock, char *Msg )
assert( Msg != NULL ); assert( Msg != NULL );
strlcpy( buf, Msg, sizeof buf - 2); strlcpy( buf, Msg, sizeof buf - 2);
strlcat( buf, "\r\n", sizeof buf); len = strlcat( buf, "\r\n", sizeof buf);
(void)write( Sock, buf, strlen( buf ) ); assert(len < COMMAND_LEN);
(void)write(Sock, buf, len);
} /* Simple_Error */ } /* Simple_Error */