lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Dear all,

I'm trying to write a ping routine inside C code that is hosted in a
lua interpreter. I want to make sure the network works before
embarking on a client/server transaction.

I've decided to craft and send ICMP packets to two hosts (one in the
provider network, the other is the server) to check for reachability.
I also check for signal strength (going out over GPRS, which can
disappear from underneath us) to be sure.

1) I can't call gethostbyname or connect unless I want to 'hang' due
to a timeout.

2) I can set an alarm signal but I can't set a flag in the signal
handler and just return because I'm returning back to the timeout

3) My application is built as a state machine, so there's no event
loop. Instead, each state decides what the next action should be, and
I use (unavoidably) keyboard polling within each state. So we can't
use the event loop as a coroutine unless we are waiting for user input
... so we won't know if we are connected or not until the user tries
to do something?

So can we try doing a setjmp() before we try to connect, and then do a
longjmp from the signal handler. Somehow, that doesn't feel very safe.
If I build intermediate C functions between my connect call and where
we enter from Lua, does that mean setjmp/longjmp will (hopefully!)
only use or touch stack that Lua doesn't care about? Or will it just
work if we longjmp right back into the C function we were called from
in Lua?

Now we want to *quickly* know whether or not we can do a transaction.
If setjmp/alarm/longjmp works, maybe it's just faster to try and do
all these checks and wrap the whole thing with that construct?

I realize this is only marginally Lua, but am hoping for some ideas here ...

-- G.