curl-library
Re: Problems w/ pausing & unpausing HTTP connections
Date: Wed, 14 Mar 2018 20:04:57 -0600
> On Mar 13, 2018, at 4:18 PM, Daniel Stenberg <daniel_at_haxx.se> wrote:
>
> On Mon, 12 Mar 2018, Philip Prindeville wrote:
>
>> Problem is that weird things seem to happen if you’re able to unpause your Curl handle in the timer callback, then that causes the write callback to fire immediately (before the timer callback has even completed).
>
> This behavior is documented in the curl_easy_pause man page:
>
> When this function is called to unpause reading, the chance is high that you
> will get your write callback called before this function returns.
>
Attaching a couple of files.
First is a tweaking of new-hiperfifo.c to do:
* use member struct event’s instead of pointers to alloc’d struct events;
* simplify the cases for the mcode_or_die() function via macros;
* make multi_timer_cb() actually do what the block comment says it should;
* accept a “stop” command on the FIFO to shut down the service;
* use cleaner notation for unused variables than the (void) hack;
* allow following redirections (304’s);
it’s not directly related to the above issue, but I then cut & pasted my “new and improved” version of hiperfifo.c into a new file which I then munged into a test case.
The test case:
* removes the FIFO stuff, expecting URL’s as command-line arguments instead;
* append received data in write_cb() to a buffer which is part of the ConnInfo structure;
* write_cb() pauses the stream if there’s inadequate room at the end of the buffer;
* added a periodic timer ticking at 10Hz, which tries to consume a random number of bytes (between 0-256K bytes);
* the periodic timer resumes the stream if the buffer has been completely emptied;
What I’m seeing when the stream gets resumed looks like:
…
write_cb: buffer now 1580797 bytes
REMAINING: 1
REMAINING: 1
REMAINING: 1
REMAINING: 1
REMAINING: 1
REMAINING: 1
REMAINING: 1
REMAINING: 1
REMAINING: 1
REMAINING: 1
REMAINING: 1
write_cb: need 16384 but have 16 (pausing)
socket callback: s=6 e=0x632c70 what=REMOVE
REMAINING: 1
tick: want 89343 bytes (avail 1580797)
tick: want 37962 bytes (avail 1491454)
tick: want 88300 bytes (avail 1453492)
tick: want 139049 bytes (avail 1365192)
tick: want 31949 bytes (avail 1226143)
tick: want 219322 bytes (avail 1194194)
tick: want 186283 bytes (avail 974872)
tick: want 82418 bytes (avail 788589)
tick: want 204539 bytes (avail 706171)
tick: want 174563 bytes (avail 501632)
tick: want 123206 bytes (avail 327069)
tick: want 196732 bytes (avail 203863)
tick: want 25282 bytes (avail 7131)
tick: resuming stream
write_cb: buffer now 16384 bytes
tick: want 2132 bytes (avail 16384)
…
i.e. after the stream is resumed via:
curl_easy_pause(conn->easy, CURLPAUSE_CONT);
a single additional write callback occurs appending data, but then no more…
Not entirely clear why.
Thanks,
-Philip
-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
- application/octet-stream attachment: new-hiperfifo.c
- application/octet-stream attachment: pacing.c