mirror of
https://github.com/osmarks/ngircd.git
synced 2024-12-14 02:40:27 +00:00
Removed (theoretically) division by zero; reformated some code.
This commit is contained in:
parent
f1f94f07e1
commit
5ce6bf28d1
@ -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.197 2006/07/23 15:22:56 alex Exp $";
|
static char UNUSED id[] = "$Id: conn.c,v 1.198 2006/07/23 23:05:20 alex Exp $";
|
||||||
|
|
||||||
#include "imp.h"
|
#include "imp.h"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
@ -701,11 +701,16 @@ 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 ) txt = LogMsg;
|
if (LogMsg)
|
||||||
else txt = FwdMsg;
|
txt = LogMsg;
|
||||||
if( ! txt ) txt = "Reason unknown";
|
else
|
||||||
|
txt = FwdMsg;
|
||||||
|
if (! txt)
|
||||||
|
txt = "Reason unknown";
|
||||||
|
|
||||||
Log( LOG_INFO, "Shutting down connection %d (%s) with %s:%d ...", Idx, LogMsg ? LogMsg : FwdMsg, My_Connections[Idx].host, ntohs( My_Connections[Idx].addr.sin_port ));
|
Log(LOG_INFO, "Shutting down connection %d (%s) with %s:%d ...", Idx,
|
||||||
|
LogMsg ? LogMsg : FwdMsg, My_Connections[Idx].host,
|
||||||
|
ntohs(My_Connections[Idx].addr.sin_port));
|
||||||
|
|
||||||
/* Search client, if any */
|
/* Search client, if any */
|
||||||
c = Conn_GetClient( Idx );
|
c = Conn_GetClient( Idx );
|
||||||
@ -741,17 +746,20 @@ Conn_Close( CONN_ID Idx, char *LogMsg, char *FwdMsg, bool InformClient )
|
|||||||
c = Conn_GetClient( Idx );
|
c = Conn_GetClient( Idx );
|
||||||
|
|
||||||
/* Shut down socket */
|
/* Shut down socket */
|
||||||
if( ! io_close( My_Connections[Idx].sock ))
|
if (! io_close(My_Connections[Idx].sock)) {
|
||||||
{
|
|
||||||
/* Oops, we can't close the socket!? This is ... ugly! */
|
/* Oops, we can't close the socket!? This is ... ugly! */
|
||||||
Log( LOG_CRIT, "Error closing connection %d (socket %d) with %s:%d - %s! (ignored)", Idx, My_Connections[Idx].sock, My_Connections[Idx].host, ntohs( My_Connections[Idx].addr.sin_port), strerror( errno ));
|
Log(LOG_CRIT,
|
||||||
|
"Error closing connection %d (socket %d) with %s:%d - %s! (ignored)",
|
||||||
|
Idx, My_Connections[Idx].sock, My_Connections[Idx].host,
|
||||||
|
ntohs(My_Connections[Idx].addr.sin_port), strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Mark socket as invalid: */
|
/* Mark socket as invalid: */
|
||||||
My_Connections[Idx].sock = NONE;
|
My_Connections[Idx].sock = NONE;
|
||||||
|
|
||||||
/* If there is still a client, unregister it now */
|
/* If there is still a client, unregister it now */
|
||||||
if( c ) Client_Destroy( c, LogMsg, FwdMsg, true );
|
if (c)
|
||||||
|
Client_Destroy(c, LogMsg, FwdMsg, true);
|
||||||
|
|
||||||
/* Calculate statistics and log information */
|
/* Calculate statistics and log information */
|
||||||
in_k = (double)My_Connections[Idx].bytes_in / 1024;
|
in_k = (double)My_Connections[Idx].bytes_in / 1024;
|
||||||
@ -760,20 +768,35 @@ Conn_Close( CONN_ID Idx, char *LogMsg, char *FwdMsg, bool InformClient )
|
|||||||
if (Conn_OPTION_ISSET( &My_Connections[Idx], CONN_ZIP)) {
|
if (Conn_OPTION_ISSET( &My_Connections[Idx], CONN_ZIP)) {
|
||||||
in_z_k = (double)My_Connections[Idx].zip.bytes_in / 1024;
|
in_z_k = (double)My_Connections[Idx].zip.bytes_in / 1024;
|
||||||
out_z_k = (double)My_Connections[Idx].zip.bytes_out / 1024;
|
out_z_k = (double)My_Connections[Idx].zip.bytes_out / 1024;
|
||||||
|
/* Make sure that no division by zero can occur during
|
||||||
|
* the calculation of in_p and out_p: in_z_k and out_z_k
|
||||||
|
* are non-zero, that's guaranteed by the protocol until
|
||||||
|
* compression can be enabled. */
|
||||||
|
if (! in_z_k)
|
||||||
|
in_z_k = in_k;
|
||||||
|
if (! out_z_k)
|
||||||
|
out_z_k = out_k;
|
||||||
in_p = (int)(( in_k * 100 ) / in_z_k );
|
in_p = (int)(( in_k * 100 ) / in_z_k );
|
||||||
out_p = (int)(( out_k * 100 ) / out_z_k );
|
out_p = (int)(( out_k * 100 ) / out_z_k );
|
||||||
Log( LOG_INFO, "Connection %d with %s:%d closed (in: %.1fk/%.1fk/%d%%, out: %.1fk/%.1fk/%d%%).", Idx, My_Connections[Idx].host, ntohs( My_Connections[Idx].addr.sin_port ), in_k, in_z_k, in_p, out_k, out_z_k, out_p );
|
Log(LOG_INFO,
|
||||||
|
"Connection %d with %s:%d closed (in: %.1fk/%.1fk/%d%%, out: %.1fk/%.1fk/%d%%).",
|
||||||
|
Idx, My_Connections[Idx].host,
|
||||||
|
ntohs(My_Connections[Idx].addr.sin_port),
|
||||||
|
in_k, in_z_k, in_p, out_k, out_z_k, out_p);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
Log( LOG_INFO, "Connection %d with %s:%d closed (in: %.1fk, out: %.1fk).", Idx, My_Connections[Idx].host, ntohs( My_Connections[Idx].addr.sin_port ), in_k, out_k );
|
Log(LOG_INFO,
|
||||||
|
"Connection %d with %s:%d closed (in: %.1fk, out: %.1fk).",
|
||||||
|
Idx, My_Connections[Idx].host,
|
||||||
|
ntohs(My_Connections[Idx].addr.sin_port),
|
||||||
|
in_k, out_k);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* cancel running resolver */
|
/* cancel running resolver */
|
||||||
if (Resolve_INPROGRESS(&My_Connections[Idx].res_stat)) {
|
if (Resolve_INPROGRESS(&My_Connections[Idx].res_stat))
|
||||||
Resolve_Shutdown(&My_Connections[Idx].res_stat);
|
Resolve_Shutdown(&My_Connections[Idx].res_stat);
|
||||||
}
|
|
||||||
|
|
||||||
/* Servers: Modify time of next connect attempt? */
|
/* Servers: Modify time of next connect attempt? */
|
||||||
Conf_UnsetServer( Idx );
|
Conf_UnsetServer( Idx );
|
||||||
@ -790,6 +813,7 @@ Conn_Close( CONN_ID Idx, char *LogMsg, char *FwdMsg, bool InformClient )
|
|||||||
|
|
||||||
array_free(&My_Connections[Idx].rbuf);
|
array_free(&My_Connections[Idx].rbuf);
|
||||||
array_free(&My_Connections[Idx].wbuf);
|
array_free(&My_Connections[Idx].wbuf);
|
||||||
|
|
||||||
/* Clean up connection structure (=free it) */
|
/* Clean up connection structure (=free it) */
|
||||||
Init_Conn_Struct( Idx );
|
Init_Conn_Struct( Idx );
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user