summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anylike.org>2009-12-30 00:22:26 +0000
committerChristian Pointner <equinox@anylike.org>2009-12-30 00:22:26 +0000
commitac5670a84f17416d002abca800eb277f6a7a2a65 (patch)
tree06c755560a9a245f194748b20a5c620040d71b3b
parentremoved misplaces error message (diff)
echo server cleanup
-rw-r--r--src/echo_server.lua6
-rw-r--r--src/main_loop.lua6
2 files changed, 7 insertions, 5 deletions
diff --git a/src/echo_server.lua b/src/echo_server.lua
index 33ad204..11ccded 100644
--- a/src/echo_server.lua
+++ b/src/echo_server.lua
@@ -31,7 +31,9 @@
socket = require("socket")
-function echo_server_init(host, port)
+echo_server = {}
+
+function echo_server.init(host, port)
local ip, err = socket.dns.toip(host)
if(ip == nil) then
log.printf(log.ERROR, "can't resolve %s: %s", host, err)
@@ -55,7 +57,7 @@ function echo_server_init(host, port)
return udp
end
-function echo_server_recv(udp)
+function echo_server.handle(udp)
local dgrm, from_ip, from_port = udp:receivefrom()
if(dgrm == nil) then
log.printf(log.ERROR, "receivefrom(%s,%s) failed: %s", ip, port, from_ip)
diff --git a/src/main_loop.lua b/src/main_loop.lua
index e202087..b7dd5af 100644
--- a/src/main_loop.lua
+++ b/src/main_loop.lua
@@ -36,10 +36,10 @@ function main_loop(opt)
local sig = signal.init()
local sock = {}
- sock[1] = echo_server_init("localhost", 4500)
+ sock[1] = echo_server.init("localhost", 4500)
if(sock[1] == nil) then return -1 end
- sock[2] = echo_server_init("localhost", 10000)
+ sock[2] = echo_server.init("localhost", 10000)
if(sock[2] == nil) then return -1 end
local return_value = 0
@@ -54,7 +54,7 @@ function main_loop(opt)
return_value = signal.handle()
if(return_value == 1) then break end
else
- return_value = echo_server_recv(input)
+ return_value = echo_server.handle(input)
if(return_value == 2) then break end
end
end