diff options
author | FlavioJS <FlavioJS@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2009-01-21 15:18:51 +0000 |
---|---|---|
committer | FlavioJS <FlavioJS@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2009-01-21 15:18:51 +0000 |
commit | e5b1b4c350134f4304a9d3b4858f99ecf235b31f (patch) | |
tree | 248311644fa5286c4506ce22f1bce967c9b94f59 /src | |
parent | f00c469e189ae291197997166eb225658cc5efae (diff) | |
download | hercules-e5b1b4c350134f4304a9d3b4858f99ecf235b31f.tar.gz hercules-e5b1b4c350134f4304a9d3b4858f99ecf235b31f.tar.bz2 hercules-e5b1b4c350134f4304a9d3b4858f99ecf235b31f.tar.xz hercules-e5b1b4c350134f4304a9d3b4858f99ecf235b31f.zip |
* Added a limit of 1MB of pending data in the write fifo for non-server sockets. Connections that go over the limit are closed.
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@13469 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src')
-rw-r--r-- | src/common/socket.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/common/socket.c b/src/common/socket.c index 022a4ae72..11493fef4 100644 --- a/src/common/socket.c +++ b/src/common/socket.c @@ -205,6 +205,10 @@ int naddr_ = 0; // # of ip addresses // initial send buffer size (will be resized as needed) #define WFIFO_SIZE (16*1024) +// Maximum size of pending data in the write fifo. (for non-server connections) +// The connection is closed if it goes over the limit. +#define WFIFO_MAX (1*1024*1024) + struct socket_data* session[FD_SETSIZE]; #ifdef SEND_SHORTLIST @@ -625,12 +629,18 @@ int WFIFOSET(int fd, size_t len) if(s->wdata_size+len > s->max_wdata) { // actually there was a buffer overflow already uint32 ip = s->client_addr; - ShowFatalError("WFIFOSET: Write Buffer Overflow. Connection %d (%d.%d.%d.%d) has written %d bytes on a %d/%d bytes buffer.\n", fd, CONVIP(ip), len, s->wdata_size, s->max_wdata); + ShowFatalError("WFIFOSET: Write Buffer Overflow. Connection %d (%d.%d.%d.%d) has written %u bytes on a %u/%u bytes buffer.\n", fd, CONVIP(ip), (unsigned int)len, (unsigned int)s->wdata_size, (unsigned int)s->max_wdata); ShowDebug("Likely command that caused it: 0x%x\n", (*(unsigned short*)(s->wdata + s->wdata_size))); // no other chance, make a better fifo model exit(EXIT_FAILURE); } + if( !s->flag.server && s->wdata_size+len > WFIFO_MAX ) + {// reached maximum write fifo size + set_eof(fd); + return 0; + } + s->wdata_size += len; //If the interserver has 200% of its normal size full, flush the data. if( s->flag.server && s->wdata_size >= 2*FIFOSIZE_SERVERLINK ) |