Mercurial > prosody-hg
comparison net/server_event.lua @ 7422:41be97f8158f
Merge 0.10->trunk
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Wed, 04 May 2016 16:58:25 +0200 |
| parents | f1ff321178d4 3fc5560557a5 |
| children | 861a747e441b |
comparison
equal
deleted
inserted
replaced
| 7418:e9f7043b86b5 | 7422:41be97f8158f |
|---|---|
| 28 ACCEPT_DELAY = 10, -- seconds to wait until the next attempt of a full server to accept | 28 ACCEPT_DELAY = 10, -- seconds to wait until the next attempt of a full server to accept |
| 29 READ_TIMEOUT = 60 * 60 * 6, -- timeout in seconds for read data from socket | 29 READ_TIMEOUT = 60 * 60 * 6, -- timeout in seconds for read data from socket |
| 30 WRITE_TIMEOUT = 180, -- timeout in seconds for write data on socket | 30 WRITE_TIMEOUT = 180, -- timeout in seconds for write data on socket |
| 31 CONNECT_TIMEOUT = 20, -- timeout in seconds for connection attempts | 31 CONNECT_TIMEOUT = 20, -- timeout in seconds for connection attempts |
| 32 CLEAR_DELAY = 5, -- seconds to wait for clearing interface list (and calling ondisconnect listeners) | 32 CLEAR_DELAY = 5, -- seconds to wait for clearing interface list (and calling ondisconnect listeners) |
| 33 READ_RETRY_DELAY = 1e-06, -- if, after reading, there is still data in buffer, wait this long and continue reading | |
| 33 DEBUG = true, -- show debug messages | 34 DEBUG = true, -- show debug messages |
| 34 } | 35 } |
| 35 | 36 |
| 36 local pairs = pairs | 37 local pairs = pairs |
| 37 local select = select | 38 local select = select |
| 557 if interface.noreading or interface.fatalerror then -- leave this event | 558 if interface.noreading or interface.fatalerror then -- leave this event |
| 558 --vdebug( "leaving this event because:", tostring(interface.noreading or interface.fatalerror) ) | 559 --vdebug( "leaving this event because:", tostring(interface.noreading or interface.fatalerror) ) |
| 559 interface.eventread = nil | 560 interface.eventread = nil |
| 560 return -1 | 561 return -1 |
| 561 end | 562 end |
| 562 if EV_TIMEOUT == event and interface:onreadtimeout() ~= true then | 563 if EV_TIMEOUT == event and not interface.conn:dirty() and interface:onreadtimeout() ~= true then |
| 563 return -1 -- took too long to get some data from client -> disconnect | 564 return -1 -- took too long to get some data from client -> disconnect |
| 564 end | 565 end |
| 565 if interface._usingssl then -- handle luasec | 566 if interface._usingssl then -- handle luasec |
| 566 if interface.eventwritetimeout then -- ok, in the past writecallback was regged | 567 if interface.eventwritetimeout then -- ok, in the past writecallback was regged |
| 567 local ret = interface.writecallback( ) -- call it | 568 local ret = interface.writecallback( ) -- call it |
| 586 if "wantwrite" == err then -- need to read on write event | 587 if "wantwrite" == err then -- need to read on write event |
| 587 if not interface.eventwrite then -- register new write event if needed | 588 if not interface.eventwrite then -- register new write event if needed |
| 588 interface.eventwrite = addevent( base, interface.conn, EV_WRITE, interface.writecallback, cfg.WRITE_TIMEOUT ) | 589 interface.eventwrite = addevent( base, interface.conn, EV_WRITE, interface.writecallback, cfg.WRITE_TIMEOUT ) |
| 589 end | 590 end |
| 590 interface.eventreadtimeout = addevent( base, nil, EV_TIMEOUT, | 591 interface.eventreadtimeout = addevent( base, nil, EV_TIMEOUT, |
| 591 function( ) | 592 function( ) interface:_close() end, cfg.READ_TIMEOUT) |
| 592 interface:_close() | |
| 593 end, cfg.READ_TIMEOUT | |
| 594 ) | |
| 595 debug( "wantwrite during read attempt, reg it in writecallback but dont know what really happens next..." ) | 593 debug( "wantwrite during read attempt, reg it in writecallback but dont know what really happens next..." ) |
| 596 -- to be honest i dont know what happens next, if it is allowed to first read, the write etc... | 594 -- to be honest i dont know what happens next, if it is allowed to first read, the write etc... |
| 597 else -- connection was closed or fatal error | 595 else -- connection was closed or fatal error |
| 598 interface.fatalerror = err | 596 interface.fatalerror = err |
| 599 debug( "connection failed in read event:", interface.fatalerror ) | 597 debug( "connection failed in read event:", interface.fatalerror ) |
| 605 interface.onincoming( interface, buffer, err ) -- send new data to listener | 603 interface.onincoming( interface, buffer, err ) -- send new data to listener |
| 606 end | 604 end |
| 607 if interface.noreading then | 605 if interface.noreading then |
| 608 interface.eventread = nil; | 606 interface.eventread = nil; |
| 609 return -1; | 607 return -1; |
| 608 end | |
| 609 if interface.conn:dirty() then -- still data left in buffer | |
| 610 return EV_TIMEOUT, cfg.READ_RETRY_DELAY; | |
| 610 end | 611 end |
| 611 return EV_READ, cfg.READ_TIMEOUT | 612 return EV_READ, cfg.READ_TIMEOUT |
| 612 end | 613 end |
| 613 | 614 |
| 614 client:settimeout( 0 ) -- set non blocking | 615 client:settimeout( 0 ) -- set non blocking |
