1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-06 05:21:22 +03:00

Merge pull request #1289 from gtalusan/short_writes

handle short writes
This commit is contained in:
Ivan Grokhotkov 2015-12-23 10:15:57 +03:00
commit 1c7b81660b
2 changed files with 16 additions and 10 deletions

View File

@ -25,14 +25,10 @@
size_t StreamString::write(const uint8_t *buffer, size_t size) {
if(reserve(length() + size + 1)) {
for(size_t i = 0; i < size; i++) {
if(write(*buffer)) {
buffer++;
} else {
return i;
}
}
const uint8_t *s = buffer;
const uint8_t *end = buffer + size;
while(write(*s++) && s < end);
return s - buffer;
}
return 0;
}

View File

@ -363,7 +363,12 @@ int HTTPClient::sendRequest(const char * type, Stream * stream, size_t size) {
int c = stream->readBytes(buff, ((s > buff_size) ? buff_size : s));
// write it to Stream
bytesWritten += _tcp->write((const uint8_t *) buff, c);
int w = _tcp->write((const uint8_t *) buff, c);
if(w != c) {
DEBUG_HTTPCLIENT("[HTTP-Client][sendRequest] short write asked for %d but got %d\n", c, w);
break;
}
bytesWritten += c;
if(len > 0) {
len -= c;
@ -470,7 +475,12 @@ int HTTPClient::writeToStream(Stream * stream) {
int c = _tcp->readBytes(buff, ((size > buff_size) ? buff_size : size));
// write it to Stream
bytesWritten += stream->write(buff, c);
int w = stream->write(buff, c);
if(w != c) {
DEBUG_HTTPCLIENT("[HTTP-Client][writeToStream] short write asked for %d but got %d\n", c, w);
break;
}
bytesWritten += c;
if(len > 0) {
len -= c;