Software /
code /
prosody
Comparison
net/server_event.lua @ 5965:99d55f12a26f
net.server_{select,event}: addclient: Add argument for overriding socket type
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 23 Dec 2013 17:55:41 +0100 |
parent | 5963:3bd90108cc3c |
child | 5966:958ad646c0f2 |
comparison
equal
deleted
inserted
replaced
5964:ad04170d6533 | 5965:99d55f12a26f |
---|---|
734 interface:_start_connection(sslctx) | 734 interface:_start_connection(sslctx) |
735 return interface, client | 735 return interface, client |
736 --function handleclient( client, ip, port, server, pattern, listener, _, sslctx ) -- creates an client interface | 736 --function handleclient( client, ip, port, server, pattern, listener, _, sslctx ) -- creates an client interface |
737 end | 737 end |
738 | 738 |
739 function addclient( addr, serverport, listener, pattern, sslctx ) | 739 function addclient( addr, serverport, listener, pattern, sslctx, typ ) |
740 if sslctx and not has_luasec then | 740 if sslctx and not has_luasec then |
741 debug "need luasec, but not available" | 741 debug "need luasec, but not available" |
742 return nil, "luasec not found" | 742 return nil, "luasec not found" |
743 end | 743 end |
744 local client, err = socket.tcp() -- creating new socket | 744 if not typ then |
745 typ = "tcp" | |
746 end | |
747 local create = socket[typ] | |
748 if type( create ) ~= "function" then | |
749 return nil, "invalid socket type" | |
750 end | |
751 local client, err = create() -- creating new socket | |
745 if not client then | 752 if not client then |
746 debug( "cannot create socket:", err ) | 753 debug( "cannot create socket:", err ) |
747 return nil, err | 754 return nil, err |
748 end | 755 end |
749 client:settimeout( 0 ) -- set nonblocking | 756 client:settimeout( 0 ) -- set nonblocking |
750 local res, err = client:connect( addr, serverport ) -- connect | 757 local res, err = client:connect( addr, serverport ) -- connect |
751 if res or ( err == "timeout" ) then | 758 if res or ( err == "timeout" ) then |
752 local ip, port = client:getsockname( ) | 759 if client.getsockname then |
753 local interface = wrapclient( client, ip, serverport, listener, pattern, sslctx ) | 760 addr = client:getsockname( ) |
761 end | |
762 local interface = wrapclient( client, addr, serverport, listener, pattern, sslctx ) | |
754 debug( "new connection id:", interface.id ) | 763 debug( "new connection id:", interface.id ) |
755 return interface, err | 764 return interface, err |
756 else | 765 else |
757 debug( "new connection failed:", err ) | 766 debug( "new connection failed:", err ) |
758 return nil, err | 767 return nil, err |