Skip to content

Commit

Permalink
lisp.lua now sends the contents of lisp.fib file
Browse files Browse the repository at this point in the history
  • Loading branch information
capr committed Nov 16, 2015
1 parent 96cad15 commit c2e1795
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 27 deletions.
4 changes: 4 additions & 0 deletions src/program/lisper/dev-env/lisp.fib
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[4660] 00:00:00:00:aa:01 fd80:1::2
[4660] 00:00:00:00:aa:02 fd80:2::2
[4660] 00:00:00:00:aa:03 fd80:3::2
[4660] FF:FF:FF:FF:FF:FF fd80:1::2,fd80:2::2,fd80:3::2
52 changes: 25 additions & 27 deletions src/program/lisper/dev-env/lisp.lua
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
#!/usr/bin/env luajit

--LISP controller mock-up program for testing.

io.stdout:setvbuf'no'
io.stderr:setvbuf'no'

--LISP controller mock-up program for testing.

local function assert(v, ...)
if v then return v, ... end
error(tostring((...)), 2)
if v then return v, ... end
error(tostring((...)), 2)
end

local function print() end --comment this to debug

local ffi = require("ffi")
local S = require("syscall")

local CONTROL_SOCK = "/var/tmp/ctrl.socket"
local CONTROL_DATA = [[
[17185] 00:00:00:00:aa:01 fd80:2::2
[4660] 00:00:00:00:aa:02 fd80:1::2
]]

S.signal('pipe', 'ign') --I 💔 Linux

Expand All @@ -28,24 +21,29 @@ sock = sock or assert(S.socket("unix", "stream, nonblock"))
local sa = S.t.sockaddr_un(CONTROL_SOCK)
local ok, err = sock:connect(sa)
if not ok then
if err.CONNREFUSED or err.AGAIN then
S.sleep(1)
print'retrying...'
goto retry
end
assert(nil, err)
if err.CONNREFUSED or err.AGAIN then
S.sleep(1)
print'retrying...'
goto retry
end
assert(nil, err)
end
print'connected'

while true do
if assert(S.select({writefds = {sock}}, 0)).count == 1 then
print'sending...'
if not S.write(sock, CONTROL_DATA, #CONTROL_DATA) then
print'write error'
sock:close()
sock = nil
goto retry
end
end
S.sleep(1)
if assert(S.select({writefds = {sock}}, 0)).count == 1 then

local f = assert(io.open'lisp.fib')
local data = assert(f:read'*a')
f:close()

print'sending...'
if not S.write(sock, data, #data) then
print'write error'
sock:close()
sock = nil
goto retry
end
end
S.sleep(1)
end

0 comments on commit c2e1795

Please sign in to comment.