cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Re: Problem when I use libcurl to write and libevent to listen on a socket

From: Veggie Monster <vmonmoonshine_at_gmail.com>
Date: Sat, 1 Sep 2012 10:45:52 -0600

Thank you Daniel for your reply.

> I don't think that will be possible in a convenient way.
>
I think I managed to do it. I had a problem with printing out stderr
that mislead me about missing packet.
I also remove the handle immediately after multi_socket_action writes
the GET request. I don't know what would happen if I leave the easy
handle in the multi handle list. The loop that I copied at the end of
this email might make trouble.

> Why not let libcurl do the HTTP protocol which it was designed to and then you
> can take care of the data once libcurl hands it to you?

Maybe it is a good idea, but it needs more work, handling incoming
traffic by libevent
was already implemented.

> Btw: Don't use the word 'listen' to describe what libcurl does as a client, as
> that's a term reserved for TCP servers. It makes things very confusing if you
> say libcurl listens to sockets...

Thank you for pointing it out, I'm using "read" from now on.

> libcurl will read data off the sockets, yes.
> You cannot tell it to not do that.
>
There's a specific name when a program does not do what's suggested by
API guide. It is
called "a bug". And the way to deal with it is either to change the
program or the API. Here it says if we need to do a specific action
then we need to set ev_bitmask:

http://curl.haxx.se/libcurl/c/curl_multi_socket_action.html

"When the events on a socket are known, they can be passed as an
events bitmask ev_bitmask "

However, I think there's loop at the end of "static CURLM
multi_socket" function that doesn't care about the ev_bitmask and run
any timed out action:

  /*
   * The loop following here will go on as long as there are expire-times left
   * to process in the splay and 'data' will be re-assigned for every expired
   * handle we deal with.
   */
  do {
    /* the first loop lap 'data' can be NULL */
    if(data) {
      do
        result = multi_runsingle(multi, now, data->set.one_easy);
      while(CURLM_CALL_MULTI_PERFORM == result);

      if(CURLM_OK >= result)
        /* get the socket(s) and check if the state has been changed since
           last */
        singlesocket(multi, data->set.one_easy);
    }

    /* Check if there's one (more) expired timer to deal with! This function
       extracts a matching node if there is one */

    multi->timetree = Curl_splaygetbest(now, multi->timetree, &t);
    if(t) {
      data = t->payload; /* assign this for next loop */
      (void)add_next_timeout(now, multi, t->payload);
    }

  } while(t);

Am I right? If this is correct then, either the loop should only runs
actions that are timed out and also they are complying with the
ev_bitmask, or user should be warned about its behavior in the guide.

Thanks again for your help.

Cheers,
vmon
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2012-09-01