summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorflaviojs <flaviojs@54d463be-8e91-2dee-dedb-b68131a5f0ec>2011-09-05 16:18:27 +0000
committerflaviojs <flaviojs@54d463be-8e91-2dee-dedb-b68131a5f0ec>2011-09-05 16:18:27 +0000
commitc00559560fb847f205b1c8103c9f5a6515aa7bca (patch)
tree1c85a7db3db6b5ce58293b8ff976d04b550b429c /src/common
parent9451fcffdc20b9f3195c82bdb74806698f1509bc (diff)
downloadhercules-c00559560fb847f205b1c8103c9f5a6515aa7bca.tar.gz
hercules-c00559560fb847f205b1c8103c9f5a6515aa7bca.tar.bz2
hercules-c00559560fb847f205b1c8103c9f5a6515aa7bca.tar.xz
hercules-c00559560fb847f205b1c8103c9f5a6515aa7bca.zip
* Add consistency checks to the shortlist.
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@14953 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/common')
-rw-r--r--src/common/socket.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/common/socket.c b/src/common/socket.c
index 81e5a7bd2..e0f6d9877 100644
--- a/src/common/socket.c
+++ b/src/common/socket.c
@@ -1353,6 +1353,12 @@ void send_shortlist_add_fd(int fd)
if( (send_shortlist_set[i]>>bit)&1 )
return;// already in the list
+ if( send_shortlist_count >= ARRAYLENGTH(send_shortlist_array) )
+ {
+ ShowDebug("send_shortlist_add_fd: shortlist is full, ignoring... (fd=%d shortlist.count=%d shortlist.length=%d)\n", fd, send_shortlist_count, ARRAYLENGTH(send_shortlist_array));
+ return;
+ }
+
// set the bit
send_shortlist_set[i] |= 1<<bit;
// Add to the end of the shortlist array.
@@ -1367,7 +1373,14 @@ void send_shortlist_do_sends()
while( i < send_shortlist_count )
{
int fd = send_shortlist_array[i];
+ int idx = fd/32;
+ int bit = fd%32;
+ if( ((send_shortlist_set[idx]>>bit)&1) == 0 )
+ {
+ ShowDebug("send_shortlist_do_sends: fd is not set, why is it in the shortlist? (fd=%d)\n", fd);
+ }
+ else
// If this session still exists, perform send operations on it and
// check for the eof state.
if( session[fd] )
@@ -1391,8 +1404,10 @@ void send_shortlist_do_sends()
}
// Remove fd from shortlist, move the last fd to the current position
- send_shortlist_array[i] = send_shortlist_array[--send_shortlist_count];
- send_shortlist_set[fd/32]&=~(1<<(fd%32));
+ --send_shortlist_count;
+ send_shortlist_array[i] = send_shortlist_array[send_shortlist_count];
+ send_shortlist_array[send_shortlist_count] = 0;
+ send_shortlist_set[idx]&=~(1<<bit);
}
}
#endif