summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Changelog-Trunk.txt2
-rw-r--r--src/common/socket.c4
-rw-r--r--src/common/socket.h9
3 files changed, 12 insertions, 3 deletions
diff --git a/Changelog-Trunk.txt b/Changelog-Trunk.txt
index a801106cf..27b20fd7f 100644
--- a/Changelog-Trunk.txt
+++ b/Changelog-Trunk.txt
@@ -3,6 +3,8 @@ Date Added
AS OF SVN REV. 5091, WE ARE NOW USING TRUNK. ALL UNTESTED BUGFIXES/FEATURES GO INTO TRUNK.
IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
+2006/09/21
+ * Improved a bit RFIFOFLUSH as suggested by Harbin. [Skotlex]
2006/09/20
* A mob's HP is set temporarily to 0 before invoking it's on-death script,
prevents said scripts being able to "rekill" the mob indefinitely (if stuff
diff --git a/src/common/socket.c b/src/common/socket.c
index b5eda7b27..014ef9272 100644
--- a/src/common/socket.c
+++ b/src/common/socket.c
@@ -857,7 +857,7 @@ int do_parsepacket(void)
sd = session[i];
if(!sd)
continue;
- if ((sd->rdata_tick != 0) && DIFF_TICK(last_tick,sd->rdata_tick) > stall_time) {
+ if (sd->rdata_tick && DIFF_TICK(last_tick,sd->rdata_tick) > stall_time) {
ShowInfo ("Session #%d timed out\n", i);
sd->eof = 1;
}
@@ -876,7 +876,7 @@ int do_parsepacket(void)
continue;
}
}
- RFIFOHEAD(i);
+ RFIFOHEAD(i);
RFIFOFLUSH(i);
}
return 0;
diff --git a/src/common/socket.h b/src/common/socket.h
index 502529419..2774b9c7f 100644
--- a/src/common/socket.h
+++ b/src/common/socket.h
@@ -38,7 +38,14 @@ extern time_t stall_time;
#define RFIFOW(fd,pos) (*(unsigned short*)RFIFOP(fd,pos))
#define RFIFOL(fd,pos) (*(unsigned long*)RFIFOP(fd,pos))
#define RFIFOREST(fd) (session[fd]->rdata_size-session[fd]->rdata_pos)
-#define RFIFOFLUSH(fd) (memmove(session[fd]->rdata,RFIFOP(fd,0),RFIFOREST(fd)),session[fd]->rdata_size=RFIFOREST(fd),session[fd]->rdata_pos=0)
+#define RFIFOFLUSH(fd) \
+ if(session[fd]->rdata_size == session[fd]->rdata_pos) \
+ { session[fd]->rdata_size = session[fd]->rdata_pos = 0; } else { \
+ session[fd]->rdata_size -= session[fd]->rdata_pos; \
+ memmove(session[fd]->rdata, session[fd]->rdata+session[fd]->rdata_pos, session[fd]->rdata_size); \
+ session[fd]->rdata_pos=0; \
+ }
+
//#define RFIFOSKIP(fd,len) ((session[fd]->rdata_size-session[fd]->rdata_pos-(len)<0) ? (fprintf(stderr,"too many skip\n"),exit(1)) : (session[fd]->rdata_pos+=(len)))
#define RBUFP(p,pos) (((unsigned char*)(p))+(pos))