summaryrefslogtreecommitdiff
path: root/src/common/socket.c
diff options
context:
space:
mode:
authorFlavioJS <FlavioJS@54d463be-8e91-2dee-dedb-b68131a5f0ec>2006-12-28 19:42:59 +0000
committerFlavioJS <FlavioJS@54d463be-8e91-2dee-dedb-b68131a5f0ec>2006-12-28 19:42:59 +0000
commit3583c98573c0f94546d149786333f9cc7043ff77 (patch)
tree3e73c89c72764203a75f48029405331d81bfc7c6 /src/common/socket.c
parentb27d8f616c4b97e1a35c2f0f347832e316de1c59 (diff)
downloadhercules-3583c98573c0f94546d149786333f9cc7043ff77.tar.gz
hercules-3583c98573c0f94546d149786333f9cc7043ff77.tar.bz2
hercules-3583c98573c0f94546d149786333f9cc7043ff77.tar.xz
hercules-3583c98573c0f94546d149786333f9cc7043ff77.zip
- Reapplied Skotlex's socket.c changes from r9587 and r9582. :S (sorry)
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@9589 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/common/socket.c')
-rw-r--r--src/common/socket.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/src/common/socket.c b/src/common/socket.c
index 81411808e..c9e282997 100644
--- a/src/common/socket.c
+++ b/src/common/socket.c
@@ -633,7 +633,13 @@ int do_sendrecv(int next)
for(i = 1; i < fd_max; i++)
{
if(!session[i])
+ {
+ if (FD_ISSET(i, &readfds)) {
+ ShowError("Deleting non-cleared session %d\n", i);
+ FD_CLR(i, &readfds);
+ }
continue;
+ }
//check the validity of the socket. Does what the last thing did
//just alot faster [Meruru]
@@ -641,14 +647,19 @@ int do_sendrecv(int next)
if(getsockname(i,(struct sockaddr*)&addr_check,&size)<0)
if(s_errno == S_ENOTSOCK)
{
+ ShowError("Deleting invalid session %d\n", i);
+ //So the code can react accordingly
+ session[i]->eof = 1;
+ if(session[i]->func_parse)
+ session[i]->func_parse(i);
free_session_mem(i); //free the bad session
continue;
}
-
- FD_SET(i,&readfds);
+
+ if (!FD_ISSET(i, &readfds))
+ FD_SET(i,&readfds);
ret = i;
}
-
fd_max = ret;
}
@@ -664,8 +675,10 @@ int do_sendrecv(int next)
session[rfd.fd_array[i]]->func_recv)
session[rfd.fd_array[i]]->func_recv(rfd.fd_array[i]);
}
- for(i=0;i<(int)efd.fd_count;i++)
+ for(i=0;i<(int)efd.fd_count;i++) {
+ ShowDebug("do_sendrecv: Connection error on Session %d.\n", efd.fd_array[i]);
set_eof(efd.fd_array[i]);
+ }
for (i = 1; i < fd_max; i++)
{
@@ -679,7 +692,7 @@ int do_sendrecv(int next)
if(session[i]->wdata_size && session[i]->func_send)
session[i]->func_send(i);
- if(session[i] && session[i]->eof) //The session check is for when the connection ended in func_parse
+ if(session[i]->eof) //func_send can't free a session, this is safe.
{ //Finally, even if there is no data to parse, connections signalled eof should be closed, so we call parse_func [Skotlex]
if (session[i]->func_parse)
session[i]->func_parse(i); //This should close the session inmediately.
@@ -699,7 +712,6 @@ int do_sendrecv(int next)
continue;
}
-
if(FD_ISSET(i,&rfd)){
//ShowMessage("read:%d\n",i);
if(session[i]->func_recv)
@@ -711,7 +723,7 @@ int do_sendrecv(int next)
if(session[i]->wdata_size && session[i]->func_send)
session[i]->func_send(i);
- if(session[i] && session[i]->eof) //The session check is for when the connection ended in func_parse
+ if(session[i]->eof)
{ //Finally, even if there is no data to parse, connections signalled eof should be closed, so we call parse_func [Skotlex]
if (session[i]->func_parse)
session[i]->func_parse(i); //This should close the session inmediately.