Consistently handle allocation failures. Some functions are changed to
return bool or int instead of void to allow returning an error.
Also fix a buffer size miscalculation in lua/uloop and use _exit() instead
of exit() on errors after forking.
Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
fd and timeout lua object has a __gc method in its metatable. After the object
is freed and the another new object use the same reference in __uloop_cb and
__uloop_fds, the new object will be freed by the old __gc of the old object
when garbag collecting.
Signed-off-by: Xiongfei(Alex) Guo <xfguo@credosemi.com>
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>
Use uloop.fd_add like this:
local socket = require "socket"
udp = socket.udp()
uloop.fd_add(
udp, -- socket
function( -- callback function
ufd, -- socket object when register the fd
events -- uloop events. eg. uloop.ULOOP_READ .
)
local words, msg_or_ip, port_or_nil = ufd:receivefrom()
print('Recv UDP packet from '..msg_or_ip..':'..port_or_nil..' : '..words)
end,
uloop.ULOOP_READ -- event you want to listen
)
The `examples/uloop-example.lua` show an example of this work.
Signed-off-by: Xiongfei(Alex) Guo <xfguo@credosemi.com>