Skip to content

Conversation

yihuang
Copy link

@yihuang yihuang commented Dec 21, 2017

    local easy = curl.easy()
    easy:setopt_url('http://www.baidu.com')
    easy:setopt_writefunction(function(buf)
        print('recv', #buf)
    end)
    multi:add_handle(easy)

This code would crash, because easy handle's L is NULL, and never be set.

@coveralls
Copy link

coveralls commented Dec 21, 2017

Coverage Status

Coverage increased (+0.05%) to 60.997% when pulling a9519f1 on yihuang:patch-1 into 14a9246 on Lua-cURL:master.

@moteus
Copy link
Member

moteus commented Dec 24, 2017

Did you have test code. This code works fine for me.
Not that perform function set Lua State for multi handle and for all childs
This done because you can run this function from different thread from which you create handle.
Can checkout this comment

My test example

local curl = require "lcurl"

local multi = curl.multi()
local easy = curl.easy()

easy:setopt_url('http://www.baidu.com')
easy:setopt_writefunction(function(buf)
	print('recv', #buf)
end)
multi:add_handle(easy)

while multi:perform() > 0 do
  multi:wait()
end

Result

recv	2047
recv	3793
recv	8188
recv	585

@yihuang
Copy link
Author

yihuang commented Dec 26, 2017

I was trying to use multi api with libuv, so I don't call multi:perform(). So all my network code can be run in the same thread with game logic.

I've post the full code in this gist: https://gist.github.com/yihuang/7f8d2be038db5636dde35bde6d344865

@moteus
Copy link
Member

moteus commented Dec 26, 2017

Multi handle assign lua state before call curl api which can invoke callback.
It done because it ca be called from different coroutines.
So please checkout which function leads to problem
Also I have my own implementation fo libuv io for curl and it works without any problem
You can checkout lluv-curl library

Update

Just checked.
Multi assign Lua states in all cases you use.
add_handle, remove_handle, socket_action

I did not wrap only curl_multi_info_read but it should not invoke any callbacks. And curl_multi_remove_handle in info_read method is wrapped.

@yihuang
Copy link
Author

yihuang commented Jan 4, 2018

I was using a very old release, the version in git is ok. Thanks for your time. ;D

@yihuang yihuang closed this Jan 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants