diff options
author | Christian Pointner <equinox@anylike.org> | 2009-12-27 21:57:43 +0000 |
---|---|---|
committer | Christian Pointner <equinox@anylike.org> | 2009-12-27 21:57:43 +0000 |
commit | 2f0156d73981f879bbd25197174545d26b7232d2 (patch) | |
tree | 9f659b3d0a1376da8be2d079e63bd41051207d4c /src | |
parent | added second echo server (diff) |
improved error handling
Diffstat (limited to 'src')
-rw-r--r-- | src/main_loop.lua | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/src/main_loop.lua b/src/main_loop.lua index 8f69f47..dd1289b 100644 --- a/src/main_loop.lua +++ b/src/main_loop.lua @@ -36,21 +36,27 @@ function main_loop(opt) sock[2] = echo_server_init("localhost", 10000) if(sock[2] == nil) then return -1 end - local ret = 0 - while ret == 0 do + local return_value = 0 + while return_value == 0 do local readable, _, err = socket.select({ sig , sock[1], sock[2] }, nil) - for _, input in ipairs(readable) do - if(input == sig) then - ret = signal.handle() - if(ret == 1) then break end - else - ret = echo_server_recv(input) + if(err) then + log.printf("ERROR", "select returned with error: %s", err) + return_value = -1 + else + for _, input in ipairs(readable) do + if(input == sig) then + return_value = signal.handle() + if(return_value == 1) then break end + else + return_value = echo_server_recv(input) + if(return_value == 2) then break end + end end end end - if(ret == 2) then ret = 0 end + if(return_value == 2) then return_value = 0 end signal.stop() - return ret + return return_value end |