Skip to content

Instantly share code, notes, and snippets.

@moteus
Last active June 23, 2017 08:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moteus/e9b667912b274df2046f875a853c5f6b to your computer and use it in GitHub Desktop.
Save moteus/e9b667912b274df2046f875a853c5f6b to your computer and use it in GitHub Desktop.
Wrapper class to use lluv socket class with pgmoon
-- socket = require "pgmoon.lluv".Socket.new()
local ut = require "lluv.utils"
local socket = require "lluv.luasocket"
local flatten = require("pgmoon.util").flatten
local function Super(class)
return function(self, m, ...)
if class.__base and class.__base[m] then
return class.__base[m](self, ...)
end
if m == '__init' then
return self
end
end
end
local Socket = ut.class(socket._TcpSocket) do
local super = Super(Socket)
function Socket:settimeout(v)
if v then v = v / 1000 end
return super(self, 'settimeout', v)
end
function Socket:getreusedtimes()
return 0
end
function Socket:send(data, ...)
return super(self, 'send', flatten(data), ...)
end
end
return {
Socket = Socket;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment