Diff

net/server.lua @ 335:906311ff2170

Fix to prevent send retry when connection is already closed
author Matthew Wild <mwild1@gmail.com>
date Tue, 18 Nov 2008 22:16:06 +0000
parent 328:a1d25769970f
child 374:ff502dada372
line wrap: on
line diff
--- a/net/server.lua	Tue Nov 18 19:58:29 2008 +0000
+++ b/net/server.lua	Tue Nov 18 22:16:06 2008 +0000
@@ -190,7 +190,7 @@
 
 	local writequeue = { }    -- buffer for messages to send
 
-	local eol   -- end of buffer
+	local eol, fatal_send_error   -- end of buffer
 
 	local sstat, rstat = 0, 0
 
@@ -225,7 +225,7 @@
 		--return shutdown( socket, pattern )
 	end
 	handler.close = function( closed )
-		if eol then handler._dispatchdata(); end
+		if eol and not fatal_send_error then handler._dispatchdata(); end
 		close( socket )
 		writelen = ( eol and removesocket( writelist, socket, writelen ) ) or writelen
 		readlen = removesocket( readlist, socket, readlen )
@@ -296,6 +296,7 @@
 			eol = 1
 			return true
 		else    -- connection was closed during sending or fatal error
+			fatal_send_error = true;
 			out_put( "server.lua: client ", ip, ":", clientport, " error: ", err )
 			handler.close( )
 			disconnect( handler, err )
@@ -371,7 +372,7 @@
 
 	local writequeue = { }    -- buffer for messages to send
 
-	local eol   -- end of buffer
+	local eol, fatal_send_error   -- end of buffer
 
 	local sstat, rstat = 0, 0
 
@@ -406,7 +407,7 @@
 		--return shutdown( socket, pattern )
 	end
 	handler.close = function( closed )
-		if eol then handler._dispatchdata(); end
+		if eol and not fatal_send_error then handler._dispatchdata(); end
 		close( socket )
 		writelen = ( eol and removesocket( writelist, socket, writelen ) ) or writelen
 		readlen = removesocket( readlist, socket, readlen )
@@ -484,6 +485,7 @@
 			eol = 1
 			return true
 		else    -- connection was closed during sending or fatal error
+			fatal_send_error = true; -- :(
 			out_put( "server.lua: client ", ip, ":", clientport, " error: ", err )
 			handler.close( )
 			disconnect( handler, err )
@@ -582,7 +584,7 @@
 
 	local writequeue = { }    -- list for messages to send
 
-	local eol
+	local eol, fatal_send_error
 
 	local rstat, sstat = 0, 0
 
@@ -617,7 +619,7 @@
 		return shutdown( socket, pattern )
 	end
 	handler.close = function( closed )
-		if eol then handler._dispatchdata(); end
+		if eol and not fatal_send_error then handler._dispatchdata(); end
 		_ = not closed and shutdown( socket )
 		_ = not closed and close( socket )
 		writelen = ( eol and removesocket( writelist, socket, writelen ) ) or writelen
@@ -690,6 +692,7 @@
 			eol = 1
 			return true
 		else    -- connection was closed during sending or fatal error
+			fatal_send_error = true; -- :'-(
 			out_put( "server.lua: client ", ip, ":", clientport, " error: ", err )
 			handler.close( )
 			disconnect( handler, err )