-
Notifications
You must be signed in to change notification settings - Fork 2
/
socketfile.lua
44 lines (39 loc) · 1.27 KB
/
socketfile.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
local argcheck = require 'argcheck'
local transfer = require 'socketfile.transfer'
local SocketFile = torch.class('torch.SocketFile', 'torch.File')
SocketFile.__init = argcheck{
{name="self", type="torch.SocketFile"},
{name="hostname", type="string"},
{name="port", type="number"},
{name="filename", type="string"},
{name="mode", type="string", default="r"},
{name="quiet", type="boolean", default=false},
{name="ipv6", type="boolean", default=false},
call =
function(self, hostname, port, filename, mode, quiet, ipv6)
local SocketFileServer = require "socketfile.socketfileserver"
self.__hostname = hostname
self.__port = port
self.__ipv6 = ipv6
self.__id = SocketFileServer.command(
"open", hostname, port, ipv6, nil, filename, mode, quiet
)
if rawget(_G, 'newproxy') then -- lua 5.1?
self.__gc = newproxy(true)
getmetatable(self.__gc).__gc =
function()
if self.__id then
self:close()
end
end
end
end
}
-- lua 5.2
function SocketFile:__gc()
if self.__id then
self:close()
end
end
-- methods are filled up by socketfileserver.lua
return SocketFile