diff --git a/src/AsyncHTTPRequest.cpp b/src/AsyncHTTPRequest.cpp index 1591555..c62b3f9 100644 --- a/src/AsyncHTTPRequest.cpp +++ b/src/AsyncHTTPRequest.cpp @@ -61,7 +61,7 @@ private: AsyncHTTPRequest::AsyncHTTPRequest(): _readyState(ReadyState::Idle), _HTTPcode(0), _chunked(false), _debug(DEBUG_IOTA_HTTP_SET) , _timeout(DEFAULT_RX_TIMEOUT), _lastActivity(0), _requestStartTime(0), _requestEndTime(0), _URL(nullptr) , _connectedHost(nullptr), _connectedPort(-1), _client(nullptr), _contentLength(0), _contentRead(0) - , _readyStateChangeCB(nullptr), _readyStateChangeCBarg(nullptr), _onDataCB(nullptr), _onDataCBarg(nullptr) + , _readyStateChangeCB(nullptr), _readyStateChangeCBarg{}, _onDataCB(nullptr), _onDataCBarg(nullptr) , _request(nullptr), _response(nullptr), _chunks(nullptr), _headers(nullptr) { #ifdef ESP32 @@ -161,14 +161,14 @@ bool AsyncHTTPRequest::open(const char* method, const char* URL) return _connect(); } //************************************************************************************************************** -void AsyncHTTPRequest::onReadyStateChange(readyStateChangeCB cb, void* arg) +void AsyncHTTPRequest::onReadyStateChange(readyStateChangeCB cb, callback_arg_t arg) { _readyStateChangeCB = cb; _readyStateChangeCBarg = arg; } //************************************************************************************************************** -void AsyncHTTPRequest::onReadyStateChangeArg(void* arg) +void AsyncHTTPRequest::onReadyStateChangeArg(callback_arg_t arg) { _readyStateChangeCBarg = arg; } diff --git a/src/AsyncHTTPRequest.h b/src/AsyncHTTPRequest.h index 58a1f06..ff527f5 100644 --- a/src/AsyncHTTPRequest.h +++ b/src/AsyncHTTPRequest.h @@ -91,6 +91,8 @@ enum class ReadyState class AsyncHTTPRequest { + using callback_arg_t = void*; + struct header { header* next; @@ -135,7 +137,7 @@ class AsyncHTTPRequest } }; - using readyStateChangeCB = std::function; + using readyStateChangeCB = std::function; using onDataCB = std::function; public: @@ -149,8 +151,8 @@ class AsyncHTTPRequest bool debug() const; // is debug on or off? bool open(const char* method, const char* URL); // Initiate a request - void onReadyStateChange(readyStateChangeCB, void* arg = 0); // Optional event handler for ready state change - void onReadyStateChangeArg(void* arg = 0); // set event handlers arg + void onReadyStateChange(readyStateChangeCB, callback_arg_t arg = 0); // Optional event handler for ready state change + void onReadyStateChangeArg(callback_arg_t arg = 0); // set event handlers arg // or you can simply poll readyState() void setTimeout(int seconds); // overide default timeout (seconds) @@ -217,7 +219,7 @@ class AsyncHTTPRequest size_t _contentLength; // content-length header value or sum of chunk headers size_t _contentRead; // number of bytes retrieved by user since last open() readyStateChangeCB _readyStateChangeCB; // optional callback for readyState change - void* _readyStateChangeCBarg; // associated user argument + callback_arg_t _readyStateChangeCBarg; // associated user argument onDataCB _onDataCB; // optional callback when data received void* _onDataCBarg; // associated user argument