HttpRequest.advanceConnections

This is made public for rudimentary event loop integration, but is still basically an internal detail. Try not to use it if you have another way.

This does a single iteration of the internal select()-based processing loop.

More...
class HttpRequest
version(arsd_http_internal_implementation)
static
int
advanceConnections
(
Duration maximumTimeout = 10.seconds
,)

Parameters

maximumTimeout Duration

the maximum time it will wait in select(). It may return much sooner than this if a connection timed out in the mean time.

automaticallyRetryOnInterruption bool

internally loop on EINTR.

Return Value

Type: int

0 = no error, work may remain so you should call advanceConnections again when you can

1 = passed maximumTimeout reached with no work done, yet requests are still in the queue. You may call advanceConnections again.

2 = no work to do, no point calling it again unless you've added new requests. Your program may exit if you have nothing to add since it means everything requested is now done.

3 = EINTR occurred on select(), you should check your interrupt flags if you set a signal handler, then call advanceConnections again if you aren't exiting. Only occurs if automaticallyRetryOnInterruption is set to false (the default when it is called externally).

any other value should be considered a non-recoverable error if you want to be forward compatible as I reserve the right to add more values later.

Detailed Description

Future directions: I want to merge the internal use of WebSocket.eventLoop with this; advanceConnections does just one run on the loop, whereas eventLoop runs it until all connections are closed. But they'd both process both pending http requests and active websockets.

After that, I want to be able to integrate in other event loops too. One might be to simply to reactor callbacks, then perhaps Windows overlapped i/o (that's just going to be tricky to retrofit into the existing select()-based code). It could then go fiber just by calling the resume function too.

The hard part is ensuring I keep this file stand-alone while offering these things.

This advanceConnections call will probably continue to work now that it is public, but it may not be wholly compatible with all the future features; you'd have to pick either the internal event loop or an external one you integrate, but not mix them.

Meta

History

This has been included in the library since almost day one, but it was private until April 13, 2021 (dub v9.5).