diff --git a/src/apis/computer.lua b/src/apis/computer.lua index 27b2d64..9a58266 100644 --- a/src/apis/computer.lua +++ b/src/apis/computer.lua @@ -1,12 +1,12 @@ local env = ... local sok,socket = pcall(require,"socket") -local gettime if sok then gettime = socket.gettime else gettime = os.time end +timeoffset = 0 local tmpaddr = "tmp-address" @@ -21,7 +21,7 @@ env.computer = {} function env.computer.realTime() --TODO --cprint("computer.realTime") -- Spammy - return gettime() + return gettime()-timeoffset end function env.computer.uptime() --TODO diff --git a/src/component/internet.lua b/src/component/internet.lua index 77ab19e..b60a7b7 100644 --- a/src/component/internet.lua +++ b/src/component/internet.lua @@ -122,11 +122,11 @@ function obj.request(url, postData) -- Starts an HTTP request. If this returns t end -- TODO: This works ... but is slow. -- TODO: Infact so slow, it can trigger the machine's sethook, so we have to work around that. - local hookf,hookm,hookc = debug.gethook() - local co = coroutine.running() - debug.sethook(co) + local starttime = gettime() local page, err, headers, status = http.request(url, postData) - debug.sethook(co,hookf,hookm,hookc) + local offset = gettime() - starttime + timeoffset = timeoffset + offset + cprint("(request.hack) Going back in time: " .. offset .. "s") if not page then cprint("(request) request failed",err) end diff --git a/src/main.lua b/src/main.lua index ad3a4e9..340c33a 100644 --- a/src/main.lua +++ b/src/main.lua @@ -271,6 +271,7 @@ boot_machine() local resume_thread function resume_thread(...) + timeoffset = 0 if coroutine.status(machine.thread) ~= "dead" then cprint("resume",...) local results = { coroutine.resume(machine.thread, ...) }