Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 27 additions & 11 deletions src/BearSSLClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,24 @@ size_t BearSSLClient::write(uint8_t b)

size_t BearSSLClient::write(const uint8_t *buf, size_t size)
{
br_sslio_write_all(&_ioc, buf, size);
br_sslio_flush(&_ioc);
size_t written = 0;

while (written < size) {
int result = br_sslio_write(&_ioc, buf, size);

if (result < 0) {
break;
}

buf += result;
written += result;
}

return size;
if (written == size && br_sslio_flush(&_ioc) < 0) {
return 0;
}

return written;
}

int BearSSLClient::available()
Expand Down Expand Up @@ -240,17 +254,16 @@ int BearSSLClient::clientRead(void *ctx, unsigned char *buf, size_t len)
return -1;
}

int r = c->read(buf, len);

if (r == -1) {
int result = c->read(buf, len);
if (result == -1) {
return 0;
}

#ifdef DEBUGSERIAL
DEBUGSERIAL.print("BearSSLClient::clientRead - ");
DEBUGSERIAL.print(r);
DEBUGSERIAL.print(result);
DEBUGSERIAL.print(" - ");
for (size_t i = 0; i < r; i++) {
for (size_t i = 0; i < result; i++) {
byte b = buf[i];

if (b < 16) {
Expand All @@ -261,7 +274,7 @@ int BearSSLClient::clientRead(void *ctx, unsigned char *buf, size_t len)
DEBUGSERIAL.println();
#endif

return r;
return result;
}

int BearSSLClient::clientWrite(void *ctx, const unsigned char *buf, size_t len)
Expand All @@ -287,7 +300,10 @@ int BearSSLClient::clientWrite(void *ctx, const unsigned char *buf, size_t len)
return -1;
}

int w = c->write(buf, len);
int result = c->write(buf, len);
if (result == 0) {
return -1;
}

return w;
return result;
}