Posted 04 September 2014 - 01:49 PM
Hi all!
New member here with a rather odd ComputerCraft problem. First my question and then I'll go a bit more into detail about the problem.
Q: Is it at all possible for a call to native.call() to NOT return? (Looks like that's the case)
Backgroud
So, using CC 1.57 I'm coding a packet routing wireless network ontop of rednet that uses a set of fixed "routers" (CC computers with wireless modems) and mobile nodes (CC turtles with wireless modems). The goal is to setup a wireless network that can route data packets over distances much longer than the modem range.
All routers and turtles are located in chunks permanently loaded with ChikenChunks chunkloaders. I've changed the CC configuration so that the wireless modem range is the same regardless of altitude and weather. When a turtle is getting close to the max range for the currently used router, the turtle switches to another closer router.
The router code uses two main functions, both started with parallel.waitForAll(f1, f2). Both functions use os.pullEventRaw() with no filters to pull events.
The problem
The problem I'm having is that the router function, let's call it f2(), mainly responsible for acting on "rednet_message" events, and sending rednet messages as a result of those "rednet_message" events, sometimes stops responding to all events, not just "rednet_message" events. The other main fuction f1() is still processing its events so it looks like f2() has yielded. After much frustration and bug hunting with strategically placed trace messages, I finally tracked down the source of the problem: A call to native.call() inside the peripheral API's call() function does not return. Since the call doesn't return, the upstream call to rednet.broadcast() doesn't return and the event handling loop is stalled.
Some observations:
The call stack is as follows:
Has anyone seen any similiar issues with calls to native functions not returning? Were you able to work around the problem and if so how?
Thanks for reading! :)/>
New member here with a rather odd ComputerCraft problem. First my question and then I'll go a bit more into detail about the problem.
Q: Is it at all possible for a call to native.call() to NOT return? (Looks like that's the case)
Backgroud
So, using CC 1.57 I'm coding a packet routing wireless network ontop of rednet that uses a set of fixed "routers" (CC computers with wireless modems) and mobile nodes (CC turtles with wireless modems). The goal is to setup a wireless network that can route data packets over distances much longer than the modem range.
All routers and turtles are located in chunks permanently loaded with ChikenChunks chunkloaders. I've changed the CC configuration so that the wireless modem range is the same regardless of altitude and weather. When a turtle is getting close to the max range for the currently used router, the turtle switches to another closer router.
The router code uses two main functions, both started with parallel.waitForAll(f1, f2). Both functions use os.pullEventRaw() with no filters to pull events.
The problem
The problem I'm having is that the router function, let's call it f2(), mainly responsible for acting on "rednet_message" events, and sending rednet messages as a result of those "rednet_message" events, sometimes stops responding to all events, not just "rednet_message" events. The other main fuction f1() is still processing its events so it looks like f2() has yielded. After much frustration and bug hunting with strategically placed trace messages, I finally tracked down the source of the problem: A call to native.call() inside the peripheral API's call() function does not return. Since the call doesn't return, the upstream call to rednet.broadcast() doesn't return and the event handling loop is stalled.
Some observations:
- It doesn't matter if the the turtle's chunk is loaded by me moving along with the turtle or if the turtle places chunkloaders to keep the chunks loaded.
- The problem shows up only when the turle is moving. This could suggest chunk loading issues but keep in mind that the routers' chunks overlap neither with each other nor the turtle's chunks.
- The computers and turtle never resets or terminates unexpectedly.
-- call() in peripheral API:
function call( _sSide, _sMethod, ... )
if native.isPresent( _sSide ) then
return native.call( _sSide, _sMethod, ... ) -- <========= Never returns!
end
for n,sSide in ipairs( rs.getSides() ) do
if native.getType( sSide ) == "modem" and not native.call( sSide, "isWireless" ) then
if native.call( sSide, "isPresentRemote", _sSide ) then
return native.call( sSide, "callRemote", _sSide, _sMethod, ... )
end
end
end
return nil
end
The call stack is as follows:
rednet.broadcast(msg)
rednet.send(CHANNEL_BROADCAST, msg)
peripheral.call(sModem, "transmit", nRecipient, os.getComputerID(), sMessage)
return native.call( _sSide, _sMethod, ... ) -- <========= Never returns!
The parameters to native.call() when the call doesn't return are "back", "transmit", 65535, 18 and the string to be transmitted.
Has anyone seen any similiar issues with calls to native functions not returning? Were you able to work around the problem and if so how?
Thanks for reading! :)/>