Hi,
I'm working on an implementation using non-blocking sockets via select(). As it is not possible to change the transmit buffer size via SO_SNDBUF socket option (only SO_RCVBUFF can be enabled in menuconfig), am I correct to assume that the option CONFIG_TCP_SND_BUF_DEFAULT (under lwip/tcp) always correctly reflects the amount of bytes that a send() will accept when FD_ISSET(sock, &write_set) returns true after a call to select() ? Does this also apply to sockets created using SOCK_DGRAM?
Secondly, the option is named nn_DEFAULT; what is a non-default value and how would that be set since SO_SNDBUF is non-functional?
Non-blocking sockets, select() and transmit buffer size
Re: Non-blocking sockets, select() and transmit buffer size
Hi permal,
For TCP, there is a non-standard IDF extension which allows you to call call setsockopt(TCP_SNDBUF) with an int-sized parameter which is the send buffer size as a multiple of the TCP_MSS value (rather than in bytes.) ie the send buffer size in bytes is the parameter value multiplied by TCP_MSS. This lets you set per-socket send buffer sizes, which override the default TCP send buffer size value which is set via CONFIG_TCP_SND_BUF_DEFAULT.permal wrote:As it is not possible to change the transmit buffer size via SO_SNDBUF socket option (only SO_RCVBUFF can be enabled in menuconfig), am I correct to assume that the option CONFIG_TCP_SND_BUF_DEFAULT (under lwip/tcp)
POSIX select() doesn't make any great guarantees in this department, only that the socket will accept "some" bytes. For TCP send(), the guarantee you have is that if FD_ISSET(sock, &write_set) is true then the result of send(sock, something, somelen) will be at least 1, but you can always be left with bytes to send the next time around.always correctly reflects the amount of bytes that a send() will accept when FD_ISSET(sock, &write_set) returns true after a call to select() ?
For UDP, sendto() will try to allocate a packet buffer to hold the full UDP packet of the size requested (up to 64KB) and will return with errno=ENOMEM if this fails. Otherwise, provided FD_ISSET(sock, &write_set) is set then the sendto() will succeed. But you should check for this failure. Generally if the ESP32 is not low on free memory then you won't see ENOMEM here.Does this also apply to sockets created using SOCK_DGRAM?
Re: Non-blocking sockets, select() and transmit buffer size
Great answer. Thanks!
Re: Non-blocking sockets, select() and transmit buffer size
For TCP, there is a non-standard IDF extension which allows you to call call setsockopt(TCP_SNDBUF) with an int-sized parameter which is the send buffer size as a multiple of the TCP_MSS value (rather than in bytes.) ie the send buffer size in bytes is the parameter value multiplied by TCP_MSS. This lets you set per-socket send buffer sizes, which override the default TCP send buffer size value which is set via CONFIG_TCP_SND_BUF_DEFAULT.
With the current IDF version TCP_SNDBUF isn't found by the compiler anymore, and looking into sockets.c I don't find anything either.
Has it been replaced by a different constant or has the entire functionality been removed?
Who is online
Users browsing this forum: Bing [Bot], Google [Bot], Majestic-12 [Bot] and 239 guests