Might make #973 go away.

This commit is contained in:
Florian Nücke 2015-03-27 19:25:39 +01:00
parent ef6d251c30
commit fa5a6f14b0
2 changed files with 39 additions and 44 deletions

View File

@ -908,7 +908,7 @@ wrappedUserdataMeta = {
local wrappedUserdata = setmetatable({}, wrappedUserdataMeta)
local function processResult(result)
wrapUserdata(result) -- needed for metamethods.
result = wrapUserdata(result) -- needed for metamethods.
if not result[1] then -- error that should be re-thrown.
error(result[2], 0)
else -- success or already processed error.
@ -920,8 +920,9 @@ local function invoke(target, direct, ...)
local result
if direct then
local args = table.pack(...) -- for unwrapping
unwrapUserdata(args)
args = unwrapUserdata(args)
result = table.pack(target.invoke(table.unpack(args, 1, args.n)))
args = nil -- clear upvalue, avoids trying to persist it
if result.n == 0 then -- limit for direct calls reached
result = nil
end
@ -930,9 +931,10 @@ local function invoke(target, direct, ...)
if not result then
local args = table.pack(...) -- for access in closure
result = select(1, coroutine.yield(function()
unwrapUserdata(args)
args = unwrapUserdata(args)
local result = table.pack(target.invoke(table.unpack(args, 1, args.n)))
wrapUserdata(result)
args = nil -- clear upvalue, avoids trying to persist it
result = wrapUserdata(result)
return result
end))
end
@ -941,8 +943,9 @@ end
local function udinvoke(f, data, ...)
local args = table.pack(...)
unwrapUserdata(args)
args = unwrapUserdata(args)
local result = table.pack(f(data, table.unpack(args)))
args = nil -- clear upvalue, avoids trying to persist it
return processResult(result)
end
@ -1035,7 +1038,7 @@ function wrapUserdata(values)
end
return value
end
wrapRecursively(values)
return wrapRecursively(values)
end
function unwrapUserdata(values)
@ -1054,7 +1057,7 @@ function unwrapUserdata(values)
end
return value
end
unwrapRecursively(values)
return unwrapRecursively(values)
end
-------------------------------------------------------------------------------
@ -1343,13 +1346,14 @@ local function main()
debug.sethook(co, checkDeadline, "", hookInterval)
local result = table.pack(coroutine.resume(co, table.unpack(args, 1, args.n)))
args = nil -- clear upvalue, avoids trying to persist it
if not result[1] then
error(tostring(result[2]), 0)
elseif coroutine.status(co) == "dead" then
error("computer halted", 0)
else
args = table.pack(coroutine.yield(result[2])) -- system yielded value
wrapUserdata(args)
args = wrapUserdata(args)
end
end
end

View File

@ -1,27 +1,15 @@
package li.cil.oc.server.component
import java.io.BufferedWriter
import java.io.FileNotFoundException
import java.io.IOException
import java.io.InputStream
import java.io.OutputStreamWriter
import java.io.{BufferedWriter, FileNotFoundException, IOException, InputStream, OutputStreamWriter}
import java.net._
import java.nio.ByteBuffer
import java.nio.channels.SocketChannel
import java.util.concurrent.Callable
import java.util.concurrent.ConcurrentLinkedQueue
import java.util.concurrent.ExecutionException
import java.util.concurrent.Future
import java.util.concurrent.{Callable, ConcurrentLinkedQueue, ExecutionException, Future}
import li.cil.oc.OpenComputers
import li.cil.oc.Settings
import li.cil.oc.api
import li.cil.oc.api.Network
import li.cil.oc.api.machine.Arguments
import li.cil.oc.api.machine.Callback
import li.cil.oc.api.machine.Context
import li.cil.oc.{OpenComputers, Settings, api}
import li.cil.oc.api.machine.{Arguments, Callback, Context}
import li.cil.oc.api.network._
import li.cil.oc.api.prefab
import li.cil.oc.api.{Network, prefab}
import li.cil.oc.api.prefab.AbstractValue
import li.cil.oc.util.ExtendedNBT._
import li.cil.oc.util.ThreadPoolFactory
@ -239,28 +227,30 @@ object InternetCard {
})
}
private def checkConnected() = try {
private def checkConnected() = {
if (owner.isEmpty) throw new IOException("connection lost")
if (isAddressResolved) channel.finishConnect()
else if (address.isCancelled) {
// I don't think this can ever happen, Justin Case.
channel.close()
throw new IOException("bad connection descriptor")
}
else if (address.isDone) {
// Check for errors.
try address.get catch {
case e: ExecutionException => throw e.getCause
try {
if (isAddressResolved) channel.finishConnect()
else if (address.isCancelled) {
// I don't think this can ever happen, Justin Case.
channel.close()
throw new IOException("bad connection descriptor")
}
isAddressResolved = true
false
else if (address.isDone) {
// Check for errors.
try address.get catch {
case e: ExecutionException => throw e.getCause
}
isAddressResolved = true
false
}
else false
}
catch {
case t: Throwable =>
close()
false
}
else false
}
catch {
case t: Throwable =>
close()
false
}
// This has to be an explicit internal class instead of an anonymous one
@ -430,6 +420,7 @@ object InternetCard {
throw new IOException(Option(e.getMessage).getOrElse(e.toString))
}
}
}
}