cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: [PATCH] A CURLINFO_XFER_STATE perhaps?

From: Rich Gray <rgray_at_plustechnologies.com>
Date: Wed, 07 Aug 2013 12:46:15 -0400

Daniel Stenberg wrote:
> Without considering the code for the moment, let's play with a modified
> imaginary setup (adopting some of Rich's ideas too):
>
> #define CURLXFER_INIT 0x00 /* nothing really happened yet */
> #define CURLXFER_NAMERES 0x10 /* name resolving */
> #define CURLXFER_CONNECT 0x20 /* TCP (or similar) connect */
> #define CURLXFER_SECCONNECT 0x24 /* SSL/SSH crypto-oriented handshake */
> #define CURLXFER_PROTOCONNECT 0x28 /* protocol specific connect */
> #define CURLXFER_PROXYCONNECT 0x2c /* proxy CONNECT procedure */
> #define CURLXFER_WAITDO 0x30 /* waiting to issue request */
> #define CURLXFER_DO 0x34 /* issuing request */
> #define CURLXFER_TRANSFER 0x40 /* transfer */
> #define CURLXFER_TOOFAST 0x44 /* toggled transfer due to rate limiting,
> basically a variation of *TRANSFER */
> #define CURLXFER_DONE 0xf0 /* transfer complete */

So _PROTOCONNECT would be where non-secure logins, etc. would be?

> This allows for some grouping like:
>
> #define CURLXFER_RANGE_INIT(x) (!((x)&0xf0))
> #define CURLXFER_RANGE_NAME(x) ((x)&0x10)
> #define CURLXFER_RANGE_CONNECT(x) ((x)&0x20)
> #define CURLXFER_RANGE_DO(x) ((x)&0x30)
> #define CURLXFER_RANGE_XFER(x) ((x)&0x40)
> #define CURLXFER_RANGE_DONE(x) ((x)&0xf0)
>
> ... and there's actually room for adding new states inbetween somewhere in a
> future, if we'd ever come to that!

Would it be worth making this switch() friendly??

     #define CURLXFER_PHASE(x) ((x)&0xf0) /* or ((x)>>4) ? */

     #define CURLXFER_PHASE_INIT CURLXFER_PHASE(CURLXFER_INIT)
     #define CURLXFER_PHASE_NAME CURLXFER_PHASE(CURLXFER_NAMERES)
     #define CURLXFER_PHASE_CONNECT CURLXFER_PHASE(CURLXFER_CONNECT)
     #define CURLXFER_PHASE_DO CURLXFER_PHASE(CURLXFER_DO)
     #define CURLXFER_PHASE_XFER CURLXFER_PHASE(CURLXFER_TRANSFER)
     #define CURLXFER_PHASE_DONE CURLXFER_PHASE(CURLXFER_DONE)

     switch(CURL_XFER_PHASE(foo->state)) {

        case CURLXFER_PHASE_INIT: ...
        case CURLXFER_PHASE_NAME: ...
        ...

This also allows relational testing :

     if (CURLXFER_PHASE(foo->state) < CURLXFER_PHASE_XFER)) ...

> It would be very useful to get opinions on this from someone who actually
> has an application or other ideas of how to use this in a real world
> application!

Which would not be me at this time, I'm just kibitzing. :/

- Rich
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2013-08-07