Changeset

1952:4a15b176fca8

net.server: Better handling of closing sockets during send
author Matthew Wild <mwild1@gmail.com>
date Wed, 14 Oct 2009 14:09:51 +0100
parents 1951:632039101699
children 1953:64538c620450 1954:4ef18b2dcc21
files net/server.lua
diffstat 1 files changed, 9 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/net/server.lua	Wed Oct 14 14:07:50 2009 +0100
+++ b/net/server.lua	Wed Oct 14 14:09:51 2009 +0100
@@ -363,17 +363,20 @@
                 send( socket, table_concat( bufferqueue, "", 1, bufferqueuelen ), 1, bufferlen )    -- forced send
             end
         end
-        if not handler then return true; end
-        _ = shutdown and shutdown( socket )
-        socket:close( )
-        _sendlistlen = removesocket( _sendlist, socket, _sendlistlen )
-        _socketlist[ socket ] = nil
+        if socket then
+          _ = shutdown and shutdown( socket )
+          socket:close( )
+          _sendlistlen = removesocket( _sendlist, socket, _sendlistlen )
+          _socketlist[ socket ] = nil
+          socket = nil
+        else
+          out_put "server.lua: socket already closed"
+        end
         if handler then
             _writetimes[ handler ] = nil
             _closelist[ handler ] = nil
             handler = nil
         end
-        socket = nil
         mem_free( )
 	if server then
 		server.remove( )