diff --git a/sys/init/1.http.lua b/sys/init/1.http.lua deleted file mode 100644 index 4fe167f..0000000 --- a/sys/init/1.http.lua +++ /dev/null @@ -1,35 +0,0 @@ ---[[ -FIX for http.get -currently, when 2 requests are generated at same time (diff coroutines) they both -will receive the same file handle. This change will ensure each request gets the -proper response. ---]] - -local http = _G.http - -local reqs = { } - -local function wrapRequest(_url, ...) - local ok, err = http.request(...) - if ok then - while true do - local event, param1, param2, param3 = os.pullEvent() - - if event == "http_success" - and param1 == _url - and not reqs[tostring(param2)] then - - reqs[tostring(param2)] = true - return param2 - - elseif event == "http_failure" and param1 == _url then - return nil, param2, param3 - end - end - end - return nil, err -end - -http.safeGet = function(_url, _headers, _binary) - return wrapRequest(_url, _url, nil, _headers, _binary) -end diff --git a/sys/modules/opus/util.lua b/sys/modules/opus/util.lua index 058529d..3d69dcf 100644 --- a/sys/modules/opus/util.lua +++ b/sys/modules/opus/util.lua @@ -13,6 +13,35 @@ local _unpack = table.unpack local _bor = bit32.bor local _bxor = bit32.bxor +if not http.safeGet then -- really no good place to put this hack + local reqs = { } + + local function wrapRequest(_url, ...) + local ok, err = http.request(...) + if ok then + while true do + local event, param1, param2, param3 = os.pullEvent() + + if event == "http_success" + and param1 == _url + and not reqs[tostring(param2)] then + + reqs[tostring(param2)] = true + return param2 + + elseif event == "http_failure" and param1 == _url then + return nil, param2, param3 + end + end + end + return nil, err + end + + http.safeGet = function(_url, _headers, _binary) + return wrapRequest(_url, _url, nil, _headers, _binary) + end +end + local byteArrayMT byteArrayMT = { __tostring = function(a) return string.char(_unpack(a)) end,