summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authoramber <amber@54d463be-8e91-2dee-dedb-b68131a5f0ec>2005-01-06 15:02:42 +0000
committeramber <amber@54d463be-8e91-2dee-dedb-b68131a5f0ec>2005-01-06 15:02:42 +0000
commit28cb9b9d074dbefa1e5de9805ff172f7dbd39da4 (patch)
tree97e50481ade2a54e0232cc68f8645a7a3184264e /src/common
parent57d0506ec4a06a8330a0f344e77ff9dba1bede5c (diff)
downloadhercules-28cb9b9d074dbefa1e5de9805ff172f7dbd39da4.tar.gz
hercules-28cb9b9d074dbefa1e5de9805ff172f7dbd39da4.tar.bz2
hercules-28cb9b9d074dbefa1e5de9805ff172f7dbd39da4.tar.xz
hercules-28cb9b9d074dbefa1e5de9805ff172f7dbd39da4.zip
update
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/branches/stable@924 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/common')
-rw-r--r--src/common/core.c2
-rw-r--r--src/common/socket.c14
-rw-r--r--src/common/socket.h6
3 files changed, 19 insertions, 3 deletions
diff --git a/src/common/core.c b/src/common/core.c
index 2e0029ea1..493aab850 100644
--- a/src/common/core.c
+++ b/src/common/core.c
@@ -169,6 +169,8 @@ int main(int argc,char **argv)
display_title();
+ tick_ = time(0);
+
do_init(argc,argv);
while(runflag){
next=do_timer(gettick_nocache());
diff --git a/src/common/socket.c b/src/common/socket.c
index 5d7d0775e..764d4d821 100644
--- a/src/common/socket.c
+++ b/src/common/socket.c
@@ -37,6 +37,8 @@
fd_set readfds;
int fd_max;
+time_t tick_;
+time_t stall_time_ = 60;
int rfifo_size = 65536;
int wfifo_size = 65536;
@@ -106,6 +108,7 @@ static int recv_to_fifo(int fd)
//{ int i; printf("recv %d : ",fd); for(i=0;i<len;i++){ printf("%02x ",RFIFOB(fd,session[fd]->rdata_size+i)); } printf("\n");}
if(len>0){
session[fd]->rdata_size+=len;
+ session[fd]->rdata_tick = tick_;
} else if(len<=0){
// value of connection is not necessary the same
// printf("set eof : connection #%d\n", fd);
@@ -209,6 +212,7 @@ static int connect_client(int listen_fd)
session[fd]->func_send = send_from_fifo;
session[fd]->func_parse = default_func_parse;
session[fd]->client_addr = client_address;
+ session[fd]->rdata_tick = tick_;
//printf("new_session : %d %d\n",fd,session[fd]->eof);
return fd;
@@ -347,6 +351,7 @@ int make_connection(long ip,int port)
session[fd]->func_recv = recv_to_fifo;
session[fd]->func_send = send_from_fifo;
session[fd]->func_parse = default_func_parse;
+ session[fd]->rdata_tick = tick_;
return fd;
}
@@ -407,7 +412,10 @@ int do_sendrecv(int next)
struct timeval timeout;
int ret,i;
- rfd=readfds;
+ tick_ = time(0);
+
+ memcpy(&rfd, &readfds, sizeof(rfd));
+
FD_ZERO(&wfd);
for(i=0;i<fd_max;i++){
if(!session[i] && FD_ISSET(i,&readfds)){
@@ -431,13 +439,11 @@ int do_sendrecv(int next)
if(FD_ISSET(i,&wfd)){
//printf("write:%d\n",i);
if(session[i]->func_send)
- //send_from_fifo(i);
session[i]->func_send(i);
}
if(FD_ISSET(i,&rfd)){
//printf("read:%d\n",i);
if(session[i]->func_recv)
- //recv_to_fifo(i);
session[i]->func_recv(i);
}
}
@@ -450,6 +456,8 @@ int do_parsepacket(void)
for(i=0;i<fd_max;i++){
if(!session[i])
continue;
+ if ((session[i]->rdata_tick != 0) && ((tick_ - session[i]->rdata_tick) > stall_time_))
+ session[i]->eof = 1;
if(session[i]->rdata_size==0 && session[i]->eof==0)
continue;
if(session[i]->func_parse){
diff --git a/src/common/socket.h b/src/common/socket.h
index e5e065f33..172712d26 100644
--- a/src/common/socket.h
+++ b/src/common/socket.h
@@ -12,8 +12,13 @@
#include <sys/socket.h>
#include <netinet/in.h>
#endif
+#include <time.h>
+
#include "malloc.h"
+extern time_t tick_;
+extern time_t stall_time_;
+
// define declaration
#define RFIFOP(fd,pos) (session[fd]->rdata+session[fd]->rdata_pos+(pos))
@@ -55,6 +60,7 @@ struct socket_data{
unsigned char *rdata,*wdata;
int max_rdata,max_wdata;
int rdata_size,wdata_size;
+ time_t rdata_tick;
int rdata_pos;
struct sockaddr_in client_addr;
int (*func_recv)(int);