78b1442051
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 <pulkomandy@gmail.com>
70 lines
1.9 KiB
C++
70 lines
1.9 KiB
C++
/*
|
|
* Copyright 2010 Haiku Inc. All rights reserved.
|
|
* Distributed under the terms of the MIT License.
|
|
*/
|
|
#ifndef _B_URL_SYNCHRONOUS_REQUEST_H_
|
|
#define _B_URL_SYNCHRONOUS_REQUEST_H_
|
|
|
|
|
|
#include <UrlRequest.h>
|
|
#include <UrlProtocolListener.h>
|
|
|
|
|
|
#ifndef LIBNETAPI_DEPRECATED
|
|
namespace BPrivate {
|
|
|
|
namespace Network {
|
|
#endif
|
|
|
|
class BUrlSynchronousRequest : public BUrlRequest, public BUrlProtocolListener {
|
|
public:
|
|
BUrlSynchronousRequest(BUrlRequest& asynchronousRequest);
|
|
virtual ~BUrlSynchronousRequest() { };
|
|
|
|
// Synchronous wait
|
|
virtual status_t Perform();
|
|
virtual status_t WaitUntilCompletion();
|
|
|
|
// Protocol hooks
|
|
virtual void ConnectionOpened(BUrlRequest* caller);
|
|
virtual void HostnameResolved(BUrlRequest* caller,
|
|
const char* ip);
|
|
virtual void ResponseStarted(BUrlRequest* caller);
|
|
#ifdef LIBNETAPI_DEPRECATED
|
|
virtual void HeadersReceived(BUrlRequest* caller,
|
|
const BUrlResult& result);
|
|
virtual void DataReceived(BUrlRequest* caller,
|
|
const char* data, off_t position,
|
|
ssize_t size);
|
|
virtual void DownloadProgress(BUrlRequest* caller,
|
|
ssize_t bytesReceived, ssize_t bytesTotal);
|
|
virtual void UploadProgress(BUrlRequest* caller,
|
|
ssize_t bytesSent, ssize_t bytesTotal);
|
|
#else
|
|
virtual void HeadersReceived(BUrlRequest* caller);
|
|
virtual void BytesWritten(BUrlRequest* caller,
|
|
size_t bytesWritten);
|
|
virtual void DownloadProgress(BUrlRequest* caller,
|
|
off_t bytesReceived, off_t bytesTotal);
|
|
virtual void UploadProgress(BUrlRequest* caller,
|
|
off_t bytesSent, off_t bytesTotal);
|
|
#endif
|
|
|
|
virtual void RequestCompleted(BUrlRequest* caller,
|
|
bool success);
|
|
|
|
|
|
protected:
|
|
bool fRequestComplete;
|
|
BUrlRequest& fWrappedRequest;
|
|
};
|
|
|
|
|
|
#ifndef LIBNETAPI_DEPRECATED
|
|
} // namespace Network
|
|
|
|
} // namespace BPrivate
|
|
#endif
|
|
|
|
#endif // _B_URL_SYNCHRONOUS_REQUEST_H_
|