Curl callback in multi transfer fail


  • Hello! I cannot make writefunction callback to work in multi transfer. It works in easy transfer, but fails in multi with the same code:
    This is on windows 7 x64, but luajit and all the dlls are 32-bit.

    local curl = require("libcurl")
    
    local cb = function(source, mult1, mult2, target)
        print("hello")
        return mult1 * mult2
    end
    
    local etr = curl.easy{
            url = 'http://google.com/', 
            writefunction = cb,
            }
    
    local performEasy = function()
        etr:perform()
        etr:close()
    end
    
    local performMulti = function()
        local mtr = curl.multi()
        mtr:add(etr)
        local remains
        repeat
            remains = mtr:perform()
        until remains == 0
        mtr:remove(etr)
        etr:close()
        mtr:close()
    end
    
    -- performEasy()
    performMulti()
    

    performEasy() works, but with performMulti() program quits with "PANIC: unprotected error in call to Lua API (bad callback)" in console.

    Maybe that's related to 4th argument to callback, it should be some "pointer" to "void" or something, over my head, I'm ignoring it in easy transfer, but maybe for multi that's not good. I planned to create separate callback functions for each easy transfer to bypass this argument thing, but cannot do even this. Does anybody use multi transfers with callbacks and how?


  • 3
    Posts
    450
    Views
    Log in to reply


  • Hello again! After months of pushing my limits, I "fixed" it. I think the problem is universal and not specific to any doodle above. It's maybe related to this SO question and the fix from here is to "manually turn off JIT-compilation with jit.off() for the surrounding Lua function that invokes such a message polling function (or similar)". I ended up with this:

    local curl = require("libcurl")
    jit.off(curl.multi._ret, true)
    

    Not sure how to measure performance hit, did I chose "less impact" function for this? And maybe something more clever can be done to fix this, without turning jit off for anything.



  • good post


3
Posts
450
Views
Log in to reply

Internal error.

Oops! Looks like something went wrong!