The tcp_write() function will fail and return ERR_MEM if the length of the data exceeds the current send buffer size (as defined by the CYGNUM_LWIP_TCP_SND_BUF CDL configuration option) or if the length of the queue of outgoing segment is larger than the upper limit defined by the CYGNUM_LWIP_TCP_SND_QUEUELEN CDL configuration option. The number of bytes available in the output queue can be retrieved with the tcp_sndbuf() function:u16_t tcp_sndbuf (struct tcp_pcb *pcb );The proper way to use this function is to call the function with at most tcp_sndbuf() bytes of data. If the function returns ERR_MEM, the application should wait until some of the currently enqueued data has been successfully received by the other host and try again. This can be achieved with a callback function previously provided to tcp_sent().