Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.openwrt.org/project/libubox.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXiongfei Guo <xfguo@credosemi.com>2014-06-20 14:31:19 +0400
committerJohn Crispin <blogic@openwrt.org>2014-06-24 17:30:30 +0400
commit02ca59334743aff65a24cba16c9343412c2c0550 (patch)
tree3138fdc600b26d68bbc42cc798cdbbfd7cad8128 /examples
parent79b56268b46ea2eaf7f79af7a64c57e2be37636a (diff)
Support delete a fd event.
When you call the fd_add, it will return an object with `delete` method. So you can delete that event if you want. Signed-off-by: Xiongfei(Alex) Guo <xfguo@credosemi.com>
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/uloop-example.lua17
1 files changed, 14 insertions, 3 deletions
diff --git a/examples/uloop-example.lua b/examples/uloop-example.lua
index ba34ec5..9b0684e 100755
--- a/examples/uloop-example.lua
+++ b/examples/uloop-example.lua
@@ -46,20 +46,31 @@ uloop.timer(
end, 2000
)
-uloop.fd_add(udp, function(ufd, events)
+udp_ev = uloop.fd_add(udp, function(ufd, events)
local words, msg_or_ip, port_or_nil = ufd:receivefrom()
print('Recv UDP packet from '..msg_or_ip..':'..port_or_nil..' : '..words)
+ if words == "Stop!" then
+ udp_ev:delete()
+ end
end, uloop.ULOOP_READ)
+udp_count = 0
udp_send_timer = uloop.timer(
function()
local s = socket.udp()
- local words = 'Hello!'
+ local words
+ if udp_count > 3 then
+ words = "Stop!"
+ udp_send_timer:cancel()
+ else
+ words = 'Hello!'
+ udp_send_timer:set(1000)
+ end
print('Send UDP packet to 127.0.0.1:8080 :'..words)
s:sendto(words, '127.0.0.1', 8080)
s:close()
- udp_send_timer:set(1000)
+ udp_count = udp_count + 1
end, 3000
)