Software /
code /
prosody
Comparison
net/server_event.lua @ 7338:f8d37227acd7
Merge 0.10->trunk
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 05 Apr 2016 20:54:43 +0200 |
parent | 7225:a74f0b7be6bf |
parent | 7337:8ec935687bae |
child | 7341:aa94cd27df4d |
comparison
equal
deleted
inserted
replaced
7335:ab7e7d4fe9c1 | 7338:f8d37227acd7 |
---|---|
255 return self:_lock(self.nointerface, true, self.nowriting); | 255 return self:_lock(self.nointerface, true, self.nowriting); |
256 end | 256 end |
257 | 257 |
258 function interface_mt:resume() | 258 function interface_mt:resume() |
259 self:_lock(self.nointerface, false, self.nowriting); | 259 self:_lock(self.nointerface, false, self.nowriting); |
260 if self.readcallback and not self.eventread then | 260 if self.readcallback and not self.eventread then |
261 self.eventread = addevent( base, self.conn, EV_READ, self.readcallback, cfg.READ_TIMEOUT ); -- register callback | 261 self.eventread = addevent( base, self.conn, EV_READ, self.readcallback, cfg.READ_TIMEOUT ); -- register callback |
262 return true; | 262 return true; |
263 end | 263 end |
264 end | 264 end |
265 | 265 |
266 function interface_mt:counter(c) | 266 function interface_mt:counter(c) |
267 if c then | 267 if c then |
389 return -1 | 389 return -1 |
390 end | 390 end |
391 if not self.eventwrite then | 391 if not self.eventwrite then |
392 self:_lock( true, true, true ) -- lock the interface, to not disturb the handshake | 392 self:_lock( true, true, true ) -- lock the interface, to not disturb the handshake |
393 self.eventstarthandshake = addevent( base, nil, EV_TIMEOUT, self.startsslcallback, 0 ) -- add event to start handshake | 393 self.eventstarthandshake = addevent( base, nil, EV_TIMEOUT, self.startsslcallback, 0 ) -- add event to start handshake |
394 else -- wait until writebuffer is empty | 394 else |
395 -- wait until writebuffer is empty | |
395 self:_lock( true, true, false ) | 396 self:_lock( true, true, false ) |
396 debug "ssl session delayed until writebuffer is empty..." | 397 debug "ssl session delayed until writebuffer is empty..." |
397 end | 398 end |
398 self.starttls = false; | 399 self.starttls = false; |
399 return true | 400 return true |
406 return false, "setoption not implemented"; | 407 return false, "setoption not implemented"; |
407 end | 408 end |
408 | 409 |
409 function interface_mt:setlistener(listener) | 410 function interface_mt:setlistener(listener) |
410 self:ondetach(); -- Notify listener that it is no longer responsible for this connection | 411 self:ondetach(); -- Notify listener that it is no longer responsible for this connection |
411 self.onconnect, self.ondisconnect, self.onincoming, self.ontimeout, | 412 self.onconnect = listener.onconnect; |
412 self.onreadtimeout, self.onstatus, self.ondetach | 413 self.ondisconnect = listener.ondisconnect; |
413 = listener.onconnect, listener.ondisconnect, listener.onincoming, listener.ontimeout, | 414 self.onincoming = listener.onincoming; |
414 listener.onreadtimeout, listener.onstatus, listener.ondetach; | 415 self.ontimeout = listener.ontimeout; |
416 self.onreadtimeout = listener.onreadtimeout; | |
417 self.onstatus = listener.onstatus; | |
418 self.ondetach = listener.ondetach; | |
415 end | 419 end |
416 | 420 |
417 -- Stub handlers | 421 -- Stub handlers |
418 function interface_mt:onconnect() | 422 function interface_mt:onconnect() |
419 end | 423 end |
579 if "wantwrite" == err then -- need to read on write event | 583 if "wantwrite" == err then -- need to read on write event |
580 if not interface.eventwrite then -- register new write event if needed | 584 if not interface.eventwrite then -- register new write event if needed |
581 interface.eventwrite = addevent( base, interface.conn, EV_WRITE, interface.writecallback, cfg.WRITE_TIMEOUT ) | 585 interface.eventwrite = addevent( base, interface.conn, EV_WRITE, interface.writecallback, cfg.WRITE_TIMEOUT ) |
582 end | 586 end |
583 interface.eventreadtimeout = addevent( base, nil, EV_TIMEOUT, | 587 interface.eventreadtimeout = addevent( base, nil, EV_TIMEOUT, |
584 function( ) | 588 function( ) |
585 interface:_close() | 589 interface:_close() |
586 end, cfg.READ_TIMEOUT | 590 end, cfg.READ_TIMEOUT |
587 ) | 591 ) |
588 debug( "wantwrite during read attempt, reg it in writecallback but dont know what really happens next..." ) | 592 debug( "wantwrite during read attempt, reg it in writecallback but dont know what really happens next..." ) |
589 -- to be honest i dont know what happens next, if it is allowed to first read, the write etc... | 593 -- to be honest i dont know what happens next, if it is allowed to first read, the write etc... |
590 else -- connection was closed or fatal error | 594 else -- connection was closed or fatal error |
591 interface.fatalerror = err | 595 interface.fatalerror = err |
701 local function addclient( addr, serverport, listener, pattern, sslctx, typ ) | 705 local function addclient( addr, serverport, listener, pattern, sslctx, typ ) |
702 if sslctx and not has_luasec then | 706 if sslctx and not has_luasec then |
703 debug "need luasec, but not available" | 707 debug "need luasec, but not available" |
704 return nil, "luasec not found" | 708 return nil, "luasec not found" |
705 end | 709 end |
706 if getaddrinfo and not typ then | 710 if not typ then |
707 local addrinfo, err = getaddrinfo(addr) | 711 local addrinfo, err = getaddrinfo(addr) |
708 if not addrinfo then return nil, err end | 712 if not addrinfo then return nil, err end |
709 if addrinfo[1] and addrinfo[1].family == "inet6" then | 713 if addrinfo[1] and addrinfo[1].family == "inet6" then |
710 typ = "tcp6" | 714 typ = "tcp6" |
711 end | 715 else |
712 end | 716 typ = "tcp" |
713 local create = socket[typ or "tcp"] | 717 end |
718 end | |
719 local create = socket[typ] | |
714 if type( create ) ~= "function" then | 720 if type( create ) ~= "function" then |
715 return nil, "invalid socket type" | 721 return nil, "invalid socket type" |
716 end | 722 end |
717 local client, err = create() -- creating new socket | 723 local client, err = create() -- creating new socket |
718 if not client then | 724 if not client then |
719 debug( "cannot create socket:", err ) | 725 debug( "cannot create socket:", err ) |
720 return nil, err | 726 return nil, err |
721 end | 727 end |
722 client:settimeout( 0 ) -- set nonblocking | 728 client:settimeout( 0 ) -- set nonblocking |
723 local res, err = client:connect( addr, serverport ) -- connect | 729 local res, err = client:connect( addr, serverport ) -- connect |
724 if res or ( err == "timeout" or err == "Operation already in progress" ) then | 730 if res or ( err == "timeout" ) then |
725 if client.getsockname then | 731 local ip, port = client:getsockname( ) |
726 addr = client:getsockname( ) | 732 local interface = wrapclient( client, ip, serverport, listener, pattern, sslctx ) |
727 end | 733 interface:_start_connection( sslctx ) |
728 local interface = wrapclient( client, addr, serverport, listener, pattern, sslctx ) | |
729 debug( "new connection id:", interface.id ) | 734 debug( "new connection id:", interface.id ) |
730 return interface, err | 735 return interface, err |
731 else | 736 else |
732 debug( "new connection failed:", err ) | 737 debug( "new connection failed:", err ) |
733 return nil, err | 738 return nil, err |