Comparison

net/server_event.lua @ 6818:ae9d1289a868

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 6817:07f43c7aa059
child 6819:ffb2b5e31456
comparison
equal deleted inserted replaced
6817:07f43c7aa059 6818:ae9d1289a868
740 interface:_start_connection(sslctx) 740 interface:_start_connection(sslctx)
741 return interface, client 741 return interface, client
742 --function handleclient( client, ip, port, server, pattern, listener, _, sslctx ) -- creates an client interface 742 --function handleclient( client, ip, port, server, pattern, listener, _, sslctx ) -- creates an client interface
743 end 743 end
744 744
745 function addclient( addr, serverport, listener, pattern, sslctx ) 745 function addclient( addr, serverport, listener, pattern, sslctx, typ )
746 if sslctx and not has_luasec then 746 if sslctx and not has_luasec then
747 debug "need luasec, but not available" 747 debug "need luasec, but not available"
748 return nil, "luasec not found" 748 return nil, "luasec not found"
749 end 749 end
750 local client, err = socket.tcp() -- creating new socket 750 if not typ then
751 typ = "tcp"
752 end
753 local create = socket[typ]
754 if type( create ) ~= "function" then
755 return nil, "invalid socket type"
756 end
757 local client, err = create() -- creating new socket
751 if not client then 758 if not client then
752 debug( "cannot create socket:", err ) 759 debug( "cannot create socket:", err )
753 return nil, err 760 return nil, err
754 end 761 end
755 client:settimeout( 0 ) -- set nonblocking 762 client:settimeout( 0 ) -- set nonblocking