Skip to content

Commit e303948

Browse files
improving write function to better handle memory errors and bigger buffers
1 parent e489e71 commit e303948

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

Diff for: libraries/lwIpWrapper/src/lwipClient.cpp

+11-2
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,7 @@ size_t lwipClient::write(const uint8_t* buffer, size_t size) {
266266
uint16_t bytes_to_send = 0;
267267

268268
do {
269-
bytes_to_send = min(size - (buffer - buffer_cursor), tcp_sndbuf(this->tcp_info->pcb));
270-
269+
bytes_to_send = min(size - (buffer_cursor - buffer), tcp_sndbuf(this->tcp_info->pcb));
271270
/*
272271
* TODO: Look into the following flags, especially for write of 1 byte
273272
* TCP_WRITE_FLAG_COPY (0x01) data will be copied into memory belonging to the stack
@@ -279,7 +278,17 @@ size_t lwipClient::write(const uint8_t* buffer, size_t size) {
279278
buffer_cursor += bytes_to_send;
280279
} else if(res == ERR_MEM) {
281280
// FIXME handle this: we get into this case only if the sent data cannot be put in the send queue
281+
CLwipIf::getInstance().task();
282+
// break;
283+
} else {
284+
break;
282285
}
286+
287+
// FIXME blocking call
288+
while(tcp_sndbuf(this->tcp_info->pcb) == 0 && buffer_cursor - buffer < size) {
289+
CLwipIf::getInstance().task();
290+
}
291+
283292
} while(buffer_cursor - buffer < size);
284293

285294
tcp_output(this->tcp_info->pcb);

0 commit comments

Comments
 (0)