I have code (not mine) which reads a serial port buffer, finds out how many bytes are in it, and transmits that to a socket.
Unfortunately the socket is non-blocking so if the data is arriving too fast, some gets lost. 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? For reading from a socket, there appears to be a hack where you give it a zero block length, but I can't find anything for writing to a socket. This is the basic code: if ((rx_len > 0) ) { //read rx_len bytes from the buffer and send over ethernet rx_len = serial_receive(i, buf, rx_len); if (rx_len > 0) { if (write(ethser_port[i].client_fd, buf, rx_len) <0) { //something went wrong. Close the client socket dbg_printf("EthSer Closing client idx: %d fd: %d", i, ethser_port[i].client_fd); close(ethser_port[i].client_fd); ethser_port[i].client_fd = -1; continue; //break from the for-loop early } } } where write() is a macro for lwip_write(). 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. Is there some way to get a buffer_space() function, so I can extract only that many bytes (max) out of the UART buffer? Thank you in advance. _______________________________________________ lwip-users mailing list lwip-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/lwip-users