Hello all,
I created a websocket client application with cURL 7.28.0 or before like
attached file.
# attached file is dummy code
I use multi_perform() for connecting server because the application works
progressively.
I mean it doesn't want to use blocking API like easy_perform().
It works fine until 7.28.0. But it dose not work since 7.29.0.
easy_send() returns CURL_SOCKET_BAD from Curl_getconnectinfo().
I guess because cURL changes the concept how to use easy and multi.
I hope it works fine for 7.40.0 or later.
So I have questions:
- that dummy code is correct how to use cURL API?
- there is another way to create the application?
Best regards,
thanks
===============
YAMADA Yasuharu
ACCESS CO., LTD.
[email protected]
2014-01-29 7:10 GMT+09:00 Daniel Stenberg <[email protected]>:
> On Sun, 26 Jan 2014, Frédéric Germain wrote:
>
> I actually made a github pull request there :
>> https://github.com/bagder/curl/pull/86
>>
>
> Thanks. I decided I need to wait with this until after this release just
> because it is a little too close to the release date.
>
> Additionally, when I apply this change test 571 myseriously start to fail
> for me (unless I use valgrind in the test), which tells me that somehow
> test 571 is timing dependent and this change alters the timing if in an
> ever so slight manner. It requires some research before I can push this.
>
> --
>
> / daniel.haxx.se
> -------------------------------------------------------------------
> List admin: http://cool.haxx.se/list/listinfo/curl-library
> Etiquette: http://curl.haxx.se/mail/etiquette.html
>
2014-01-26 18:09 GMT+09:00 Frédéric Germain <[email protected]>:
> Hello all, I'm new here :)
>
> I'm writing because I found a way do kind of HTTP UPGRADE requests when we
> use multi handle, but as I'm wondering if there are cleaner ways, so I'm
> writing on the mailing list so that everyone can join in.
>
> Daniel told me it can be related to the work made for HTTP2 in
> lib/http2.[ch]
>
> I actually made a github pull request there :
> https://github.com/bagder/curl/pull/86
>
> So the idea is to be able to "detach" a easy handle from the multi handle.
> When it's in detached state, we can safely use curl_easy_send and
> curl_easy_recv :
>
> 1) add a easy handle wich represent your UPGRADE http request,
> with CURLOPT_HEADERFUNCTION set
> 2) on the last last header, do the following to detach the connection
> curl_easy_pause(easy_handle, CURLPAUSE_ALL);
> curl_easy_setopt(easy_handle, CURLOPT_FORBID_REUSE, 1);
> curl_easy_setopt(easy_handle, CURLOPT_CONNECT_ONLY, 1);
> 3) using the multi port you have, you can safely poll your socket
> for data, and use curl_easy_send/curl_easy_recv to exchange
> data with the connection
>
> Just need the little patch I sent, a websocket parser like wslay at
> http://wslay.sourceforge.net/.
> And I need to write a test for that...
>
> Comments are welcome
>
> -------------------------------------------------------------------
> List admin: http://cool.haxx.se/list/listinfo/curl-library
> Etiquette: http://curl.haxx.se/mail/etiquette.html
>
--
.
CURLM* multiHandle;
CULR* handle;
websocket_init()
{
multiHandle = curl_multi_init();
curl_multi_setopt(multiHandle, CURLMOPT_MAXCONNECTS, 1L);
handle = curl_easy_init();
curl_easy_setopt(handle, CURLOPT_MAXCONNECTS, 1L);
curl_easy_setopt(handle, CURLOPT_URL, "http://example.com");
curl_easy_setopt(handle, CURLOPT_CONNECT_ONLY, 1L);
curl_multi_add_handle(multiHandle, handle);
}
websocket_connect()
{
while (curl_multi_perform(multiHandle, &runningHandles) == CURLM_CALL_MULTI_PERFORM) { }
CURLMsg* msg = curl_multi_info_read((CURLM*)m_multiHandle, &messagesInQueue);
if (!msg) {
// call again websocket_connect()
return false;
}
else {
// call websocket_send()
return true;
}
}
websocket_send(data)
{
curl_easy_send(handle, data, len, &curl_out_len);
}
websocket_recv()
{
curl_easy_recv(handle, recvData, recvDataLen, &inoutLen);
}
main()
{
websocket_init()
while (!websocket_connect()) {
// do something
}
curl_easy_setopt(handle, CURLOPT_CONNECT_ONLY, 0L);
websocket_send("GET URL HTTP/1.1\r\nUpgrade: websocket\r\nConnection: Upgrade\r\n....");
websocket_recv();
websocket_send("sending data...");
websocket_recv();
}
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html