Skip to content
Permalink
Browse files
Added socket.connect for compatibility with socket.core <3.0 (fixes #208
).
  • Loading branch information
pkulchenko committed Sep 18, 2013
1 parent 80eab46 commit 689cd8c
Showing 1 changed file with 16 additions and 0 deletions.
@@ -13,6 +13,22 @@ local socket = require("socket.core")

local _M = socket

-- this is needed in case this library is used when "socket.core" is loaded,
-- but has an older version of luasocket that does not include `connect`.
if not socket.connect then
socket.connect = function (address, port, laddress, lport)
local sock, err = socket.tcp()
if not sock then return nil, err end
if laddress then
local res, err = sock:bind(laddress, lport, -1)
if not res then return nil, err end
end
local res, err = sock:connect(address, port)
if not res then return nil, err end
return sock
end
end

-----------------------------------------------------------------------------
-- Exported auxiliar functions
-----------------------------------------------------------------------------

0 comments on commit 689cd8c

Please sign in to comment.