lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] Can one find out how much data can be sent (lwip_write) to


From: Peter
Subject: [lwip-users] Can one find out how much data can be sent (lwip_write) to a NON blocking socket without loss of data?
Date: Wed, 21 Dec 2022 23:20:02 +0000

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.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]