Comparison

net/server_event.lua @ 9499:36e379f058c8

net.server: Swich method for connecting sockets with remotes LuaSocket TCP sockets have have both :connect and :setpeername, which are the exact same function, however UDP sockets only have :setpeername. Switching to :setpeername allows most of this code to be generic wrt TCP/UDP.
author Kim Alvefur <zash@zash.se>
date Fri, 12 Oct 2018 17:36:34 +0200
parent 9495:89e05b118f6e
child 9575:1fb3e7c550bf
child 11063:30d3f6f85eb8
comparison
equal deleted inserted replaced
9498:cc593002f2e2 9499:36e379f058c8
745 if not client then 745 if not client then
746 debug( "cannot create socket:", err ) 746 debug( "cannot create socket:", err )
747 return nil, err 747 return nil, err
748 end 748 end
749 client:settimeout( 0 ) -- set nonblocking 749 client:settimeout( 0 ) -- set nonblocking
750 local res, err = client:connect( addr, serverport ) -- connect 750 local res, err = client:setpeername( addr, serverport ) -- connect
751 if res or ( err == "timeout" ) then 751 if res or ( err == "timeout" ) then
752 local ip, port = client:getsockname( ) 752 local ip, port = client:getsockname( )
753 local interface = wrapclient( client, ip, serverport, listener, pattern, sslctx ) 753 local interface = wrapclient( client, ip, serverport, listener, pattern, sslctx )
754 debug( "new connection id:", interface.id ) 754 debug( "new connection id:", interface.id )
755 return interface, err 755 return interface, err