From 3705fb3e9cbe2adf9ae620fd9cce3b25839a11b3 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sat, 18 Dec 2010 21:12:44 +0000 Subject: command timeout works now git-svn-id: https://svn.spreadspace.org/gcsd/trunk@66 ac14a137-c7f1-4531-abe0-07747231d213 --- src/command_queue.lua | 15 +++++++++++++-- src/main_loop.lua | 10 +++++----- src/modules/debug_shell.lua | 2 +- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/command_queue.lua b/src/command_queue.lua index a1aa383..2bb34c6 100644 --- a/src/command_queue.lua +++ b/src/command_queue.lua @@ -45,8 +45,10 @@ function command_queue:enqueue(command, expected_response, timeout) new_cmd.command = command new_cmd.sent = false new_cmd.expected_response = expected_response - new_cmd.timeout = timeout - + if(timeout) then + new_cmd.timeout = timer.new(timeout) + end + table.insert(self.commands, new_cmd) end @@ -69,6 +71,9 @@ function command_queue:command_sent() if(self.current == nil) then return end self.current.sent = true + if(self.current.timeout) then + self.current.expiration_time = timer.add(timer.now(), self.current.timeout) + end if(self.current.expected_response) then return self.current.expected_response end @@ -78,6 +83,12 @@ end function command_queue:check_timeout() if(self.current == nil or not self.current.sent) then return end + if(not self.current.expiration_time) then return end + + if(timer.cmp(timer.now(), self.current.expiration_time) == 1) then + log.printf(log.NOTICE, "command timed out") + self:command_completed() + end end function command_queue:command_completed() diff --git a/src/main_loop.lua b/src/main_loop.lua index f7fe740..28bd1af 100644 --- a/src/main_loop.lua +++ b/src/main_loop.lua @@ -137,13 +137,13 @@ function main_loop(opt) client_list:unregister(writer.client_instance) end end - if(command_queue:command_pending()) then - local command = command_queue:get_next_command() - log.printf(log.DEBUG, "sending pending command: %s", command) - module_list.output:start_command(command) - end end command_queue:check_timeout() + if(command_queue:command_pending()) then + local command = command_queue:get_next_command() + log.printf(log.DEBUG, "sending pending command: %s", command) + module_list.output:start_command(command) + end end if(return_value == 2) then return_value = 0 end diff --git a/src/modules/debug_shell.lua b/src/modules/debug_shell.lua index 1a28acd..b431cd3 100644 --- a/src/modules/debug_shell.lua +++ b/src/modules/debug_shell.lua @@ -242,7 +242,7 @@ function debug_shell:exec_cmd(socket) if(not param or param == '') then socket.out_buffer = socket.out_buffer .. "Error: please specify a command\n" else socket.out_buffer = socket.out_buffer .. "enqueing command: " .. param .. "\n" - command_queue:enqueue(param, nil, nil) + command_queue:enqueue(param, "", 10000) end else socket.out_buffer = socket.out_buffer .. "unknown command\n" -- cgit v1.2.3