From fac697c2cdde2a98dbbadca2b1dc2685a58c6462 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 25 Jul 2012 20:33:20 +0200 Subject: net.server_event: Don't emit empty packets, check for errors first. (fixes #287) --- net/server_event.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/net/server_event.lua b/net/server_event.lua index de44e5fd..264d50a7 100644 --- a/net/server_event.lua +++ b/net/server_event.lua @@ -597,16 +597,14 @@ do end local buffer, err, part = interface.conn:receive( interface._pattern ) -- receive buffer with "pattern" --vdebug( "read data:", tostring(buffer), "error:", tostring(err), "part:", tostring(part) ) - buffer = buffer or part or "" - local len = string_len( buffer ) - if len > cfg.MAX_READ_LENGTH then -- check buffer length + buffer = buffer or part + if buffer and #buffer > cfg.MAX_READ_LENGTH then -- check buffer length interface.fatalerror = "receive buffer exceeded" debug( "fatal error:", interface.fatalerror ) interface:_close() interface.eventread = nil return -1 end - interface.onincoming( interface, buffer, err ) -- send new data to listener if err and ( err ~= "timeout" and err ~= "wantread" ) then if "wantwrite" == err then -- need to read on write event if not interface.eventwrite then -- register new write event if needed @@ -626,6 +624,8 @@ do interface.eventread = nil return -1 end + else + interface.onincoming( interface, buffer, err ) -- send new data to listener end if interface.noreading then interface.eventread = nil; -- cgit v1.2.3