diff options
Diffstat (limited to 'nopsyncd/tcpserver.lua')
-rwxr-xr-x | nopsyncd/tcpserver.lua | 31 |
1 files changed, 8 insertions, 23 deletions
diff --git a/nopsyncd/tcpserver.lua b/nopsyncd/tcpserver.lua index 7530ff2..dd6f18b 100755 --- a/nopsyncd/tcpserver.lua +++ b/nopsyncd/tcpserver.lua @@ -20,7 +20,6 @@ -- require "socket" -playlog = require "playlog" function init_server() local server = assert(socket.tcp()) @@ -75,25 +74,16 @@ function clients_get_writeables() return fds end -function clients_senddata() - -- TODO: fetch data from SQL and send it out to all clients - +function clients_senddata(timestamp) for _, client in ipairs(clients) do - client.buffer = client.buffer .. "hello world\n" + client.buffer = client.buffer .. timestamp .. "\n" end end function main_loop() local pipefd = pipe.getreadfd() - local ret, err = playlog:init() - if ret == nil then - io.stderr:write("creation of playlog failed: " .. err .. "\n") - os.exit(1) - end - server = init_server() - while true do local readables, writeables, err = socket.select({ pipefd , server , unpack(clients) } , clients_get_writeables()) if err then @@ -102,26 +92,22 @@ function main_loop() else for _, input in ipairs(readables) do if input == pipefd then - local ret = pipe.consume() - if ret == 1 then - print("pipe was signaled") - clients_senddata() - else - return ret + local timestamp = pipe.consume() + if timestamp == nil then + return 2 end + print("pipe was signaled with timestamp: " .. timestamp) + clients_senddata(timestamp) elseif input == server then local client = assert(server:accept()) add_client(client) else if input.hdl then -- receive is insanely stupid, therefore we must always read one byte only - local tmp, err, part = input.hdl:receive(1) + local _, err = input.hdl:receive(1) if err then remove_client(input) end - - -- TODO: receive timestamp of last received entry - -- send out (enqueue in buffer) all entrys since this timestamp end end end @@ -133,7 +119,6 @@ function main_loop() end end - playlog:close() server:close() cleanup_clients() |