Hello Peter, On 2022-12-22 00:20, Peter wrote:
Unfortunately the socket is non-blocking so if the data is arriving too fast, some gets lost.
This is the most common mistake made with TCP socket programming: Not handling short writes properly. You also get this with blocking sockets, those also don't guarantee to send all supplied data. In practice, you always get a short write before the socket would block. If you don't want short writes, use the RAW API.
The obvious solution (make the socket blocking) would cause problems elsewhere. Is there some way to get how many bytes a write socket can accept?
Check and handle the send return value correctly.
Doing some digging around, I have found stuff like this //socket ready for writing if(FD_ISSET(new_sd, &write_flags)) { //printf("\nSocket ready for write"); FD_CLR(new_sd, &write_flags); send(new_sd, out, 255, 0); memset(&out, 0, 255); } //end if but it doesn't seem to be suitable.
This solves your real problem: Knowing when to send more data. (Assuming your send rate is not consistently too high for the receiver to keep up, and your code does sends in bursts.)
Is there some way to get a buffer_space() function, so I can extract only that many bytes (max) out of the UART buffer?
send() returns how many bytes are sent, you just have to keep the remainder and send that when the socket can accept more (see above). Greetings, Indan _______________________________________________ lwip-users mailing list lwip-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/lwip-users