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>
64 lines
1.2 KiB
C++
64 lines
1.2 KiB
C++
/*
|
|
* Copyright 2014 Haiku Inc. All rights reserved.
|
|
* Distributed under the terms of the MIT License.
|
|
*/
|
|
#ifndef _B_NET_REQUEST_H_
|
|
#define _B_NET_REQUEST_H_
|
|
|
|
|
|
#include <NetBuffer.h>
|
|
#include <NetworkAddress.h>
|
|
#include <UrlRequest.h>
|
|
|
|
|
|
class BAbstractSocket;
|
|
|
|
|
|
#ifndef LIBNETAPI_DEPRECATED
|
|
namespace BPrivate {
|
|
|
|
namespace Network {
|
|
#endif
|
|
|
|
class BNetworkRequest: public BUrlRequest
|
|
{
|
|
public:
|
|
#ifdef LIBNETAPI_DEPRECATED
|
|
BNetworkRequest(const BUrl& url,
|
|
BUrlProtocolListener* listener,
|
|
BUrlContext* context,
|
|
const char* threadName,
|
|
const char* protocolName);
|
|
#else
|
|
BNetworkRequest(const BUrl& url,
|
|
BDataIO* output,
|
|
BUrlProtocolListener* listener,
|
|
BUrlContext* context,
|
|
const char* threadName,
|
|
const char* protocolName);
|
|
#endif
|
|
|
|
virtual status_t Stop();
|
|
virtual void SetTimeout(bigtime_t timeout);
|
|
|
|
protected:
|
|
bool _ResolveHostName(BString host, uint16_t port);
|
|
|
|
void _ProtocolSetup();
|
|
status_t _GetLine(BString& destString);
|
|
|
|
protected:
|
|
BAbstractSocket* fSocket;
|
|
BNetworkAddress fRemoteAddr;
|
|
|
|
BNetBuffer fInputBuffer;
|
|
};
|
|
|
|
#ifndef LIBNETAPI_DEPRECATED
|
|
} // namespace Network
|
|
|
|
} // namespace BPrivate
|
|
#endif
|
|
|
|
#endif
|