1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-25 20:02:37 +03:00

improve debug out and error handling

This commit is contained in:
Markus Sattler 2015-11-22 15:46:23 +01:00
parent e6c661e7ba
commit be91d96774
2 changed files with 21 additions and 9 deletions

View File

@ -80,11 +80,15 @@ void httpClient::begin(String host, uint16_t port, String url, bool https, Strin
* called after the payload is handeld
*/
void httpClient::end(void) {
if((!_reuse || !_canReuse) && connected()) {
DEBUG_HTTPCLIENT("[HTTP-Client][end] tcp stop \n");
_tcp->stop();
if(connected()) {
if(_reuse && _canReuse) {
DEBUG_HTTPCLIENT("[HTTP-Client][end] tcp keep open for reuse\n");
} else {
DEBUG_HTTPCLIENT("[HTTP-Client][end] tcp stop\n");
_tcp->stop();
}
} else {
DEBUG_HTTPCLIENT("[HTTP-Client][end] tcp keep open for reuse\n");
DEBUG_HTTPCLIENT("[HTTP-Client][end] tcp is closed\n");
}
}
@ -189,12 +193,16 @@ WiFiClient & httpClient::getStream(void) {
/**
* write all message body / payload to Stream
* @param stream Stream *
* @return bytes written
* @return bytes written ( negative values are error codes )
*/
int httpClient::writeToStream(Stream * stream) {
if(!stream) {
return -1;
return HTTPC_ERROR_NO_STREAM;
}
if(!connected()) {
return HTTPC_ERROR_NOT_CONNECTED;
}
// get lenght of document (is -1 when Server sends no Content-Length header)
@ -219,14 +227,17 @@ int httpClient::writeToStream(Stream * stream) {
if(len > 0) {
len -= c;
}
delay(0);
} else {
delay(1);
}
delay(1);
}
DEBUG_HTTPCLIENT("[HTTP-Client] connection closed or file end.\n");
DEBUG_HTTPCLIENT("[HTTP-Client][writeToStream] connection closed or file end (written: %d).\n", bytesWritten);
if(_size && _size != bytesWritten) {
DEBUG_HTTPCLIENT("[HTTP-Client] bytesWritten %d and size %d missmatch!.\n", bytesWritten, _size);
DEBUG_HTTPCLIENT("[HTTP-Client][writeToStream] bytesWritten %d and size %d missmatch!.\n", bytesWritten, _size);
}
end();

View File

@ -39,6 +39,7 @@
#define HTTPC_ERROR_SEND_PAYLOAD_FAILD (-3)
#define HTTPC_ERROR_NOT_CONNECTED (-4)
#define HTTPC_ERROR_CONNECTION_LOST (-5)
#define HTTPC_ERROR_NO_STREAM (-6)
class httpClient {