libbnetapi: BUrlRequest now outputs to BDataIO
Previously, BUrlRequest returns data received via a callback that can't return any value. This approach have several issues: - It's not possible to signify failures to the request. - Users have to implement custom listeners just to handle the common case of outputting to a buffer/file/etc. - The received data has to be serialized into BMessage when BUrlProtocolDispatchingListener is employed. This can cause a noticible slowdown in real-world scenarios as evident by #10748. With this change, BUrlRequest will output directly into a BDataIO, which exposes a richer API for request handlers to work with (for example a BitTorrent client can request a BPositionIO for non-linear data delivery), as well as simplifying common cases for users. The adaptation only requires one additional API: BHttpRequest::SetStopOnError(). This API simply instructs the HTTP request handler to cancel the request if an HTTP error is occurred. Change-Id: I4160884d77bff0e7678e0a623e2587987704443a Reviewed-on: https://review.haiku-os.org/c/haiku/+/3084 Reviewed-by: Adrien Destugues <[email protected]>
This commit is contained in:
committed by
Niels Sascha Reedijk
parent
3e27f8d5a7
commit
78b1442051
@@ -113,16 +113,18 @@
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn virtual void BUrlProtocolListener::DataReceived(BUrlRequest* caller,
|
||||
const char* data, off_t position, size_t size)
|
||||
\brief Called each time a block of data is received.
|
||||
\fn virtual void BUrlProtocolListener::BytesWritten(BUrlRequest* caller,
|
||||
size_t size)
|
||||
\brief Called each time a block of data is written.
|
||||
|
||||
This callback is called whenever a block of data is written to the
|
||||
BDataIO associated with the request. If no BDataIO is associated, the
|
||||
callback will not be invoked.
|
||||
|
||||
\b Frequency: Zero or more
|
||||
|
||||
\param caller The BUrlRequest that invoked this callback.
|
||||
\param data Pointer to the data block in memory.
|
||||
\param position Offset of the data in the stream.
|
||||
\param size Size of the data block.
|
||||
\param size Size of the written data block.
|
||||
*/
|
||||
|
||||
/*!
|
||||
@@ -130,15 +132,17 @@
|
||||
off_t bytesReceived, off_t bytesTotal)
|
||||
\brief Called each time a block of data is downloaded.
|
||||
|
||||
This callback will usually be called after DataReceived().
|
||||
This callback might still be invoked even when no BDataIO is associated
|
||||
with the request, as data can still be downloaded and discarded so that the
|
||||
request can be completed and the socket can be reused.
|
||||
|
||||
\b Frequency: Once or more
|
||||
\b Frequency: Zero or more
|
||||
|
||||
\param caller The BUrlRequest that invoked this callback.
|
||||
\param bytesReceived Number of data bytes received. This is the number of
|
||||
bytes received prior to any processing and can be smaller than the
|
||||
size of the data block sent to DataReceived() as the transport might
|
||||
be compressed.
|
||||
size of the data block written to the output BDataIO as the transport
|
||||
might be compressed.
|
||||
\param bytesTotal Total number of data bytes expected. \c 0 will be passed
|
||||
if the total number of data bytes is not available.
|
||||
*/
|
||||
|
||||
@@ -27,10 +27,12 @@
|
||||
|
||||
/*!
|
||||
\fn static BUrlRequest* BUrlProtocolRoster::MakeRequest(const BUrl& url,
|
||||
BUrlProtocolListener* listener = NULL, BUrlContext* context = NULL)
|
||||
BDataIO* output, BUrlProtocolListener* listener = NULL,
|
||||
BUrlContext* context = NULL)
|
||||
\brief Create a BUrlRequest that can handle the given BUrl
|
||||
|
||||
\param url The URL to create a request for
|
||||
\param output The BDataIO to output to
|
||||
\param listener The BUrlProtocolListener to be registered with the created
|
||||
BUrlRequest, can be \c NULL
|
||||
\param context The BUrlContext to be registered with the created
|
||||
|
||||
Reference in New Issue
Block a user