diff options
author | Christian Pointner <equinox@spreadspace.org> | 2010-11-10 00:56:11 +0000 |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2010-11-10 00:56:11 +0000 |
commit | ef197f527bf1d2ff1c88aacd114786f5384c3d45 (patch) | |
tree | 23362036b5a7ce03d676385354d4176595711bcc | |
parent | variables name refactored (diff) |
fixed module_list cleanup
debug_shell: handling of partial writes should work now
git-svn-id: https://svn.spreadspace.org/gcsd/trunk@22 ac14a137-c7f1-4531-abe0-07747231d213
-rw-r--r-- | src/module_list.lua | 5 | ||||
-rw-r--r-- | src/modules/debug_shell.lua | 22 |
2 files changed, 20 insertions, 7 deletions
diff --git a/src/module_list.lua b/src/module_list.lua index aa644ee..0ad0d35 100644 --- a/src/module_list.lua +++ b/src/module_list.lua @@ -43,17 +43,17 @@ function module_list:init(opt) --- TODO: load configured modules (use own module loader) local old_path = package.path package.path = "./modules/?.lua" + dummy = require ("dummy") if(opt.debug) then debug_shell = require ("debug_shell") end package.path = old_path - table.insert(self.modules, dummy:new({})) - table.insert(self.modules, debug_shell:new({["host"]="127.0.0.1", ["port"]="9001"})) if(opt.debug) then table.insert(self.modules, debug_shell:new({["host"]="127.0.0.1", ["port"]="9000"})) + table.insert(self.modules, debug_shell:new({["host"]="127.0.0.1", ["port"]="9001"})) end end @@ -89,4 +89,5 @@ function module_list:cleanup() log.printf(log.INFO, "removing module: " .. module.name) module:cleanup() end + self.modules = {} end diff --git a/src/modules/debug_shell.lua b/src/modules/debug_shell.lua index 0cdf191..a84a793 100644 --- a/src/modules/debug_shell.lua +++ b/src/modules/debug_shell.lua @@ -97,7 +97,7 @@ function debug_shell:new(config) client_sock.in_buffer = "" client_sock.out_buffer = "" function client_sock:read() - local ret = 0 + local ret = defines.OK local data, err, partial = self.sock:receive('*l') if(data == nil) then if(err == 'closed') then @@ -120,10 +120,22 @@ function debug_shell:new(config) return ret end function client_sock:write() - -- TODO: test return value and handle partial writes - self.sock:send(self.out_buffer) - self.out_buffer = "" - return defines.OK + local ret = defines.OK + local len, err, partiallen = self.sock:send(self.out_buffer) + if(len == nil) then + if(err == 'closed') then + log.printf(log.INFO, inst.name .. ": connection closed by peer") + ret = defines.KILL_CLIENT + elseif(err == 'timeout') then + self.out_buffer = string.sub(self.out_buffer, partiallen+1) + else + log.printf(log.INFO, inst.name .. ": connection error: %s", err) + ret = defines.KILL_CLIENT + end + else + self.out_buffer = string.sub(self.out_buffer, len+1) + end + return ret end local client = {} |