Software /
code /
prosody
Comparison
net/server_event.lua @ 5010:2f8f388de516
net.server_event: Don't emit empty packets, check for errors first. (fixes #287)
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 25 Jul 2012 20:33:20 +0200 |
parent | 4984:724848dfde36 |
child | 5018:eb8211b65e96 |
comparison
equal
deleted
inserted
replaced
5009:b27ba2c83dd4 | 5010:2f8f388de516 |
---|---|
595 interface.eventreadtimeout = nil | 595 interface.eventreadtimeout = nil |
596 end | 596 end |
597 end | 597 end |
598 local buffer, err, part = interface.conn:receive( interface._pattern ) -- receive buffer with "pattern" | 598 local buffer, err, part = interface.conn:receive( interface._pattern ) -- receive buffer with "pattern" |
599 --vdebug( "read data:", tostring(buffer), "error:", tostring(err), "part:", tostring(part) ) | 599 --vdebug( "read data:", tostring(buffer), "error:", tostring(err), "part:", tostring(part) ) |
600 buffer = buffer or part or "" | 600 buffer = buffer or part |
601 local len = string_len( buffer ) | 601 if buffer and #buffer > cfg.MAX_READ_LENGTH then -- check buffer length |
602 if len > cfg.MAX_READ_LENGTH then -- check buffer length | |
603 interface.fatalerror = "receive buffer exceeded" | 602 interface.fatalerror = "receive buffer exceeded" |
604 debug( "fatal error:", interface.fatalerror ) | 603 debug( "fatal error:", interface.fatalerror ) |
605 interface:_close() | 604 interface:_close() |
606 interface.eventread = nil | 605 interface.eventread = nil |
607 return -1 | 606 return -1 |
608 end | 607 end |
609 interface.onincoming( interface, buffer, err ) -- send new data to listener | |
610 if err and ( err ~= "timeout" and err ~= "wantread" ) then | 608 if err and ( err ~= "timeout" and err ~= "wantread" ) then |
611 if "wantwrite" == err then -- need to read on write event | 609 if "wantwrite" == err then -- need to read on write event |
612 if not interface.eventwrite then -- register new write event if needed | 610 if not interface.eventwrite then -- register new write event if needed |
613 interface.eventwrite = addevent( base, interface.conn, EV_WRITE, interface.writecallback, cfg.WRITE_TIMEOUT ) | 611 interface.eventwrite = addevent( base, interface.conn, EV_WRITE, interface.writecallback, cfg.WRITE_TIMEOUT ) |
614 end | 612 end |
624 debug( "connection failed in read event:", interface.fatalerror ) | 622 debug( "connection failed in read event:", interface.fatalerror ) |
625 interface:_close() | 623 interface:_close() |
626 interface.eventread = nil | 624 interface.eventread = nil |
627 return -1 | 625 return -1 |
628 end | 626 end |
627 else | |
628 interface.onincoming( interface, buffer, err ) -- send new data to listener | |
629 end | 629 end |
630 if interface.noreading then | 630 if interface.noreading then |
631 interface.eventread = nil; | 631 interface.eventread = nil; |
632 return -1; | 632 return -1; |
633 end | 633 end |