-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Commit
This is all @dirkx , whose PR unfortunately got borked when we were trying to update it to the new format. As @dirkx said: When sending POST responses of well over a K - _write() may not sent it all. Make sure we do -- but cap the individual writes - as somehow large 2-3k blobs seem to cause instability (on my 12F units). Supercedes #2528
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -677,9 +677,20 @@ int HTTPClient::sendRequest(const char * type, const uint8_t * payload, size_t s | |
} | ||
|
||
// send Payload if needed | ||
if(payload && size > 0) { | ||
if(_client->write(&payload[0], size) != size) { | ||
return returnError(HTTPC_ERROR_SEND_PAYLOAD_FAILED); | ||
if (payload && size > 0) { | ||
size_t byteswritten = 0; | ||
const uint8_t *p = payload; | ||
while (byteswritten < size) { | ||
int written; | ||
int towrite = std::min((int)size, (int)HTTP_TCP_BUFFER_SIZE); | ||
written = _client->write(p, towrite); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
d-a-v
Collaborator
|
||
if (written < 0) { | ||
return returnError(HTTPC_ERROR_SEND_PAYLOAD_FAILED); | ||
} else if (written == 0) { | ||
return returnError(HTTPC_ERROR_CONNECTION_LOST); | ||
} | ||
byteswritten += written; | ||
size -= written; | ||
} | ||
} | ||
|
||
|
2 comments
on commit 8f6e0dd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just stumbled upon another bug:
it should read
while (size > 0) {
instead of
while (byteswritten < size) {
as size is decrementing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This problem was already found and fixed with
#7051
shouldn't it be write(p + bytesWritten, towrite); or am I missing something?
p pointer seems to never be updated in the loop