Comparison

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
comparison
equal deleted inserted replaced
334:bffd80e8c7a3 335:906311ff2170
188 188
189 --// private closures of the object //-- 189 --// private closures of the object //--
190 190
191 local writequeue = { } -- buffer for messages to send 191 local writequeue = { } -- buffer for messages to send
192 192
193 local eol -- end of buffer 193 local eol, fatal_send_error -- end of buffer
194 194
195 local sstat, rstat = 0, 0 195 local sstat, rstat = 0, 0
196 196
197 --// local import of socket methods //-- 197 --// local import of socket methods //--
198 198
223 end 223 end
224 handler.shutdown = function( pattern ) 224 handler.shutdown = function( pattern )
225 --return shutdown( socket, pattern ) 225 --return shutdown( socket, pattern )
226 end 226 end
227 handler.close = function( closed ) 227 handler.close = function( closed )
228 if eol then handler._dispatchdata(); end 228 if eol and not fatal_send_error then handler._dispatchdata(); end
229 close( socket ) 229 close( socket )
230 writelen = ( eol and removesocket( writelist, socket, writelen ) ) or writelen 230 writelen = ( eol and removesocket( writelist, socket, writelen ) ) or writelen
231 readlen = removesocket( readlist, socket, readlen ) 231 readlen = removesocket( readlist, socket, readlen )
232 socketlist[ socket ] = nil 232 socketlist[ socket ] = nil
233 out_put "server.lua: closed handler and removed socket from list" 233 out_put "server.lua: closed handler and removed socket from list"
294 buffer = string_sub( buffer, byte + 1, -1 ) -- new buffer 294 buffer = string_sub( buffer, byte + 1, -1 ) -- new buffer
295 writequeue[ 1 ] = buffer -- insert new buffer in queue 295 writequeue[ 1 ] = buffer -- insert new buffer in queue
296 eol = 1 296 eol = 1
297 return true 297 return true
298 else -- connection was closed during sending or fatal error 298 else -- connection was closed during sending or fatal error
299 fatal_send_error = true;
299 out_put( "server.lua: client ", ip, ":", clientport, " error: ", err ) 300 out_put( "server.lua: client ", ip, ":", clientport, " error: ", err )
300 handler.close( ) 301 handler.close( )
301 disconnect( handler, err ) 302 disconnect( handler, err )
302 writequeue = nil 303 writequeue = nil
303 handler = nil 304 handler = nil
369 socket:setoption("linger", { on = true, timeout = 10 }); 370 socket:setoption("linger", { on = true, timeout = 10 });
370 --// private closures of the object //-- 371 --// private closures of the object //--
371 372
372 local writequeue = { } -- buffer for messages to send 373 local writequeue = { } -- buffer for messages to send
373 374
374 local eol -- end of buffer 375 local eol, fatal_send_error -- end of buffer
375 376
376 local sstat, rstat = 0, 0 377 local sstat, rstat = 0, 0
377 378
378 --// local import of socket methods //-- 379 --// local import of socket methods //--
379 380
404 end 405 end
405 handler.shutdown = function( pattern ) 406 handler.shutdown = function( pattern )
406 --return shutdown( socket, pattern ) 407 --return shutdown( socket, pattern )
407 end 408 end
408 handler.close = function( closed ) 409 handler.close = function( closed )
409 if eol then handler._dispatchdata(); end 410 if eol and not fatal_send_error then handler._dispatchdata(); end
410 close( socket ) 411 close( socket )
411 writelen = ( eol and removesocket( writelist, socket, writelen ) ) or writelen 412 writelen = ( eol and removesocket( writelist, socket, writelen ) ) or writelen
412 readlen = removesocket( readlist, socket, readlen ) 413 readlen = removesocket( readlist, socket, readlen )
413 socketlist[ socket ] = nil 414 socketlist[ socket ] = nil
414 out_put "server.lua: closed handler and removed socket from list" 415 out_put "server.lua: closed handler and removed socket from list"
482 buffer = string_sub( buffer, byte + 1, -1 ) -- new buffer 483 buffer = string_sub( buffer, byte + 1, -1 ) -- new buffer
483 writequeue[ 1 ] = buffer -- insert new buffer in queue 484 writequeue[ 1 ] = buffer -- insert new buffer in queue
484 eol = 1 485 eol = 1
485 return true 486 return true
486 else -- connection was closed during sending or fatal error 487 else -- connection was closed during sending or fatal error
488 fatal_send_error = true; -- :(
487 out_put( "server.lua: client ", ip, ":", clientport, " error: ", err ) 489 out_put( "server.lua: client ", ip, ":", clientport, " error: ", err )
488 handler.close( ) 490 handler.close( )
489 disconnect( handler, err ) 491 disconnect( handler, err )
490 writequeue = nil 492 writequeue = nil
491 handler = nil 493 handler = nil
580 582
581 --// private closures of the object //-- 583 --// private closures of the object //--
582 584
583 local writequeue = { } -- list for messages to send 585 local writequeue = { } -- list for messages to send
584 586
585 local eol 587 local eol, fatal_send_error
586 588
587 local rstat, sstat = 0, 0 589 local rstat, sstat = 0, 0
588 590
589 --// local import of socket methods //-- 591 --// local import of socket methods //--
590 592
615 end 617 end
616 handler.shutdown = function( pattern ) 618 handler.shutdown = function( pattern )
617 return shutdown( socket, pattern ) 619 return shutdown( socket, pattern )
618 end 620 end
619 handler.close = function( closed ) 621 handler.close = function( closed )
620 if eol then handler._dispatchdata(); end 622 if eol and not fatal_send_error then handler._dispatchdata(); end
621 _ = not closed and shutdown( socket ) 623 _ = not closed and shutdown( socket )
622 _ = not closed and close( socket ) 624 _ = not closed and close( socket )
623 writelen = ( eol and removesocket( writelist, socket, writelen ) ) or writelen 625 writelen = ( eol and removesocket( writelist, socket, writelen ) ) or writelen
624 readlen = removesocket( readlist, socket, readlen ) 626 readlen = removesocket( readlist, socket, readlen )
625 socketlist[ socket ] = nil 627 socketlist[ socket ] = nil
688 buffer = string_sub( buffer, byte + 1, -1 ) -- new buffer 690 buffer = string_sub( buffer, byte + 1, -1 ) -- new buffer
689 writequeue[ 1 ] = buffer -- insert new buffer in queue 691 writequeue[ 1 ] = buffer -- insert new buffer in queue
690 eol = 1 692 eol = 1
691 return true 693 return true
692 else -- connection was closed during sending or fatal error 694 else -- connection was closed during sending or fatal error
695 fatal_send_error = true; -- :'-(
693 out_put( "server.lua: client ", ip, ":", clientport, " error: ", err ) 696 out_put( "server.lua: client ", ip, ":", clientport, " error: ", err )
694 handler.close( ) 697 handler.close( )
695 disconnect( handler, err ) 698 disconnect( handler, err )
696 writequeue = nil 699 writequeue = nil
697 handler = nil 700 handler = nil