summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorshennetsind <ind@henn.et>2013-07-05 19:20:08 -0300
committershennetsind <ind@henn.et>2013-07-05 19:59:12 -0300
commitdc85ce04b774af63fd9d13d9757feb91d56c1b81 (patch)
treea7d01a4352d615b7cdc128ad030963b4db180f30 /src/common
parent0118a097c9626b3f8342dd29897392f3da4c1187 (diff)
parent3fd6437cc84cbb87f27bd43f990d468623a2a49e (diff)
downloadhercules-dc85ce04b774af63fd9d13d9757feb91d56c1b81.tar.gz
hercules-dc85ce04b774af63fd9d13d9757feb91d56c1b81.tar.bz2
hercules-dc85ce04b774af63fd9d13d9757feb91d56c1b81.tar.xz
hercules-dc85ce04b774af63fd9d13d9757feb91d56c1b81.zip
HCache | Item Packages Update
http://hercules.ws/board/topic/1389-hcache-item-packages-update/ Signed-off-by: shennetsind <ind@henn.et>
Diffstat (limited to 'src/common')
-rw-r--r--src/common/socket.c57
-rw-r--r--src/common/socket.h1
-rw-r--r--src/common/utils.c4
-rw-r--r--src/common/utils.h3
4 files changed, 61 insertions, 4 deletions
diff --git a/src/common/socket.c b/src/common/socket.c
index 15b20b16f..ea8a2cfcc 100644
--- a/src/common/socket.c
+++ b/src/common/socket.c
@@ -221,6 +221,13 @@ int naddr_ = 0; // # of ip addresses
// Larger packets cause a buffer overflow and stack corruption.
static size_t socket_max_client_packet = 24576;
+#ifdef SHOW_SERVER_STATS
+// Data I/O statistics
+static size_t socket_data_i = 0, socket_data_ci = 0, socket_data_qi = 0;
+static size_t socket_data_o = 0, socket_data_co = 0, socket_data_qo = 0;
+static time_t socket_data_last_tick = 0;
+#endif
+
// initial recv buffer size (this will also be the max. size)
// biggest known packet: S 0153 <len>.w <emblem data>.?B -> 24x24 256 color .bmp (0153 + len.w + 1618/1654/1756 bytes)
#define RFIFO_SIZE (2*1024)
@@ -357,6 +364,14 @@ int recv_to_fifo(int fd)
session[fd]->rdata_size += len;
session[fd]->rdata_tick = last_tick;
+#ifdef SHOW_SERVER_STATS
+ socket_data_i += len;
+ socket_data_qi += len;
+ if (!session[fd]->flag.server)
+ {
+ socket_data_ci += len;
+ }
+#endif
return 0;
}
@@ -376,6 +391,9 @@ int send_from_fifo(int fd)
{//An exception has occured
if( sErrno != S_EWOULDBLOCK ) {
//ShowDebug("send_from_fifo: %s, ending connection #%d\n", error_msg(), fd);
+#ifdef SHOW_SERVER_STATS
+ socket_data_qo -= session[fd]->wdata_size;
+#endif
session[fd]->wdata_size = 0; //Clear the send queue as we can't send anymore. [Skotlex]
set_eof(fd);
}
@@ -390,6 +408,14 @@ int send_from_fifo(int fd)
memmove(session[fd]->wdata, session[fd]->wdata + len, session[fd]->wdata_size - len);
session[fd]->wdata_size -= len;
+#ifdef SHOW_SERVER_STATS
+ socket_data_o += len;
+ socket_data_qo -= len;
+ if (!session[fd]->flag.server)
+ {
+ socket_data_co += len;
+ }
+#endif
}
return 0;
@@ -566,6 +592,7 @@ static int create_session(int fd, RecvFunc func_recv, SendFunc func_send, ParseF
session[fd]->func_send = func_send;
session[fd]->func_parse = func_parse;
session[fd]->rdata_tick = last_tick;
+ session[fd]->session_data = NULL;
return 0;
}
@@ -573,9 +600,14 @@ static void delete_session(int fd)
{
if( session_isValid(fd) )
{
+#ifdef SHOW_SERVER_STATS
+ socket_data_qi -= session[fd]->rdata_size - session[fd]->rdata_pos;
+ socket_data_qo -= session[fd]->wdata_size;
+#endif
aFree(session[fd]->rdata);
aFree(session[fd]->wdata);
- aFree(session[fd]->session_data);
+ if( session[fd]->session_data )
+ aFree(session[fd]->session_data);
aFree(session[fd]);
session[fd] = NULL;
}
@@ -641,6 +673,9 @@ int RFIFOSKIP(int fd, size_t len)
}
s->rdata_pos = s->rdata_pos + len;
+#ifdef SHOW_SERVER_STATS
+ socket_data_qi -= len;
+#endif
return 0;
}
@@ -694,6 +729,9 @@ int WFIFOSET(int fd, size_t len)
}
s->wdata_size += len;
+#ifdef SHOW_SERVER_STATS
+ socket_data_qo += len;
+#endif
//If the interserver has 200% of its normal size full, flush the data.
if( s->flag.server && s->wdata_size >= 2*FIFOSIZE_SERVERLINK )
flush_fifo(fd);
@@ -820,6 +858,23 @@ int do_sockets(int next)
RFIFOFLUSH(i);
}
+#ifdef SHOW_SERVER_STATS
+ if (last_tick != socket_data_last_tick)
+ {
+ char buf[1024];
+
+ sprintf(buf, "In: %.03f kB/s (%.03f kB/s, Q: %.03f kB) | Out: %.03f kB/s (%.03f kB/s, Q: %.03f kB) | RAM: %.03f MB", socket_data_i/1024., socket_data_ci/1024., socket_data_qi/1024., socket_data_o/1024., socket_data_co/1024., socket_data_qo/1024., iMalloc->usage()/1024.);
+#ifdef _WIN32
+ SetConsoleTitle(buf);
+#else
+ ShowMessage("\033[s\033[1;1H\033[2K%s\033[u", buf);
+#endif
+ socket_data_last_tick = last_tick;
+ socket_data_i = socket_data_ci = 0;
+ socket_data_o = socket_data_co = 0;
+ }
+#endif
+
return 0;
}
diff --git a/src/common/socket.h b/src/common/socket.h
index 82f8b84c3..0870c9d4e 100644
--- a/src/common/socket.h
+++ b/src/common/socket.h
@@ -6,6 +6,7 @@
#define _SOCKET_H_
#include "../common/cbasetypes.h"
+#include "../config/core.h"
#ifdef WIN32
#include "../common/winapi.h"
diff --git a/src/common/utils.c b/src/common/utils.c
index 3ea970a1b..fd332253d 100644
--- a/src/common/utils.c
+++ b/src/common/utils.c
@@ -292,7 +292,7 @@ bool HCache_check(const char *file) {
struct stat bufa, bufb;
FILE *first, *second;
char s_path[255], dT[1];
- size_t rtime;
+ time_t rtime;
if( !(first = fopen(file,"rb")) )
return false;
@@ -316,7 +316,7 @@ bool HCache_check(const char *file) {
}
fstat(fileno(first), &bufa);
- fstat(fileno(first), &bufa);
+ fstat(fileno(first), &bufb);
fclose(first);
fclose(second);
diff --git a/src/common/utils.h b/src/common/utils.h
index 7953d93e8..d245f94e2 100644
--- a/src/common/utils.h
+++ b/src/common/utils.h
@@ -7,6 +7,7 @@
#include "../common/cbasetypes.h"
#include <stdio.h> // FILE*
+#include <time.h>
// generate a hex dump of the first 'length' bytes of 'buffer'
void WriteDump(FILE* fp, const void* buffer, size_t length);
@@ -37,7 +38,7 @@ struct HCache_interface {
bool (*check) (const char *file);
FILE *(*open) (const char *file, const char *opt);
/* */
- size_t recompile_time;
+ time_t recompile_time;
bool enabled;
};