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

View File

@ -1,27 +1,15 @@
package li.cil.oc.server.component package li.cil.oc.server.component
import java.io.BufferedWriter import java.io.{BufferedWriter, FileNotFoundException, IOException, InputStream, OutputStreamWriter}
import java.io.FileNotFoundException
import java.io.IOException
import java.io.InputStream
import java.io.OutputStreamWriter
import java.net._ import java.net._
import java.nio.ByteBuffer import java.nio.ByteBuffer
import java.nio.channels.SocketChannel import java.nio.channels.SocketChannel
import java.util.concurrent.Callable import java.util.concurrent.{Callable, ConcurrentLinkedQueue, ExecutionException, Future}
import java.util.concurrent.ConcurrentLinkedQueue
import java.util.concurrent.ExecutionException
import java.util.concurrent.Future
import li.cil.oc.OpenComputers import li.cil.oc.{OpenComputers, Settings, api}
import li.cil.oc.Settings import li.cil.oc.api.machine.{Arguments, Callback, Context}
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.api.network._ 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.api.prefab.AbstractValue
import li.cil.oc.util.ExtendedNBT._ import li.cil.oc.util.ExtendedNBT._
import li.cil.oc.util.ThreadPoolFactory 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 (owner.isEmpty) throw new IOException("connection lost")
if (isAddressResolved) channel.finishConnect() try {
else if (address.isCancelled) { if (isAddressResolved) channel.finishConnect()
// I don't think this can ever happen, Justin Case. else if (address.isCancelled) {
channel.close() // I don't think this can ever happen, Justin Case.
throw new IOException("bad connection descriptor") 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
} }
isAddressResolved = true else if (address.isDone) {
false // 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 // 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)) throw new IOException(Option(e.getMessage).getOrElse(e.toString))
} }
} }
} }
} }