Software /
code /
prosody
Comparison
net/server_event.lua @ 6816:36367fb1ecf9
net/server_event: add_client should have same arguments no-matter the server backend
author | daurnimator <quae@daurnimator.com> |
---|---|
date | Wed, 18 Dec 2013 17:52:28 -0500 |
parent | 6782:ec172dbe9d14 |
child | 6817:07f43c7aa059 |
comparison
equal
deleted
inserted
replaced
6815:46546d57f639 | 6816:36367fb1ecf9 |
---|---|
748 interface:_start_connection(sslctx) | 748 interface:_start_connection(sslctx) |
749 return interface, client | 749 return interface, client |
750 --function handleclient( client, ip, port, server, pattern, listener, _, sslctx ) -- creates an client interface | 750 --function handleclient( client, ip, port, server, pattern, listener, _, sslctx ) -- creates an client interface |
751 end | 751 end |
752 | 752 |
753 function addclient( addr, serverport, listener, pattern, localaddr, localport, sslcfg, startssl ) | 753 function addclient( addr, serverport, listener, pattern, sslctx ) |
754 if sslctx and not ssl then | |
755 debug "need luasec, but not available" | |
756 return nil, "luasec not found" | |
757 end | |
754 local client, err = socket.tcp() -- creating new socket | 758 local client, err = socket.tcp() -- creating new socket |
755 if not client then | 759 if not client then |
756 debug( "cannot create socket:", err ) | 760 debug( "cannot create socket:", err ) |
757 return nil, err | 761 return nil, err |
758 end | 762 end |
759 client:settimeout( 0 ) -- set nonblocking | 763 client:settimeout( 0 ) -- set nonblocking |
760 if localaddr then | |
761 local res, err = client:bind( localaddr, localport, -1 ) | |
762 if not res then | |
763 debug( "cannot bind client:", err ) | |
764 return nil, err | |
765 end | |
766 end | |
767 local sslctx | |
768 if sslcfg then -- handle ssl/new context | |
769 if not has_luasec then | |
770 debug "need luasec, but not available" | |
771 return nil, "luasec not found" | |
772 end | |
773 sslctx, err = sslcfg | |
774 if err then | |
775 debug( "cannot create new ssl context:", err ) | |
776 return nil, err | |
777 end | |
778 end | |
779 local res, err = client:connect( addr, serverport ) -- connect | 764 local res, err = client:connect( addr, serverport ) -- connect |
780 if res or ( err == "timeout" ) then | 765 if res or ( err == "timeout" ) then |
781 local ip, port = client:getsockname( ) | 766 local ip, port = client:getsockname( ) |
782 local interface = wrapclient( client, ip, serverport, listener, pattern, sslctx, startssl ) | 767 local interface = wrapclient( client, ip, serverport, listener, pattern, sslctx ) |
783 interface:_start_connection( startssl ) | 768 interface:_start_connection( startssl ) |
784 debug( "new connection id:", interface.id ) | 769 debug( "new connection id:", interface.id ) |
785 return interface, err | 770 return interface, err |
786 else | 771 else |
787 debug( "new connection failed:", err ) | 772 debug( "new connection failed:", err ) |