Page 1 of 1

getsockopt(), setsockopt() not working. socket buffer size,..

Posted: Sat Jan 07, 2017 2:01 pm
by igotit
Hi,

In order to get the socket buffer size, My codes call the function getsockopt() .

However, the return value is always -1, and the err msg is "Protocol not available".

the codes I used,
ESP-IDF version 1;

Code: Select all

void Init_Client_mySocket(void)
{
	struct sockaddr_in serverAddress;
	memset(&serverAddress,0,sizeof(serverAddress));

	// Create a socket client 
	int sock = socket(AF_INET, SOCK_STREAM,0);// IPPROTO_TCP);
	if (sock < 0) {
		printf("socket: %d %s", sock, strerror(errno));
		goto END;
	}
	printf("socket: %d Created OK\n", sock);

	/// socket option
	int bsize=0;
	socklen_t optlen;
	optlen = sizeof(bsize);

	int retv_gso = getsockopt(sock,SOL_SOCKET,SO_RCVBUF,&bsize,&optlen);
	printf("getsockopt retv = %d. err msg=%s\n",retv_gso,strerror(errno));
	printf("rcv Buf Size = %d\n", bsize);//
...

In order to change the socket buffer size, the function setsockopt() also returns an error.

Questions.
1. How can I get the socket buffer size ?
2. How can I set the socket buffer size ?
3. What is the default socket size ?

Re: getsockopt(), setsockopt() not working. socket buffer size,..

Posted: Sun Jan 08, 2017 3:31 pm
by kolban
If we look at this comment dated from 2007 in the LWIP stack, we see that the ability to use SO_RCVBUF is disabled by default.

https://github.com/espressif/esp-idf/bl ... ELOG#L2343

It looks like it is enableable by changing a configuration setting in lwipopts.h. However, before doing that, I would suggest a study of the LWIP package in depth and determine what made the LWIP authors make the decision to disable it by default. They may have had some very sound reason for doing such that is specific to the implementation of LWIP.

A deeper question (for me) is the effect/goal you are trying to achieve. Personally, I've never had a need to even think about this option. I'd be very interested to understand from you what the perceived need is to change the value?

Re: getsockopt(), setsockopt() not working. socket buffer size,..

Posted: Mon Jan 09, 2017 12:20 am
by ESP_Angus
Hi,

Thanks for your patience with this. A menuconfig option to enable SO_RCVBUF in LWIP will be merged to github master branch in the next few days.

Angus

Re: getsockopt(), setsockopt() not working. socket buffer size,..

Posted: Mon Jan 09, 2017 12:39 pm
by igotit
Hi, kolban.

In my application (the last posting -> http://www.esp32.com/viewtopic.php?f=13&t=839 ),
I need to speed up the TCP socket throughput between two ESP32 modules.
Now I trying to adjust the socket buffer size. I guess that the maximum throughput is affected by the buffser size.
I can not find any other ways to speed up.

some examples for tunning the socket
1. http://www.onlamp.com/pub/a/onlamp/2005 ... uning.html
2. http://lwip.wikia.com/wiki/Tuning_TCP
3. http://lwip.wikia.com/wiki/Maximizing_throughput
4. http://lwip.100.n7.nabble.com/LWIP-conf ... d6963.html

p.s. thank you for ESP32 book, It's so really helpful. ^^
kolban wrote:If we look at this comment dated from 2007 in the LWIP stack, we see that the ability to use SO_RCVBUF is disabled by default.

https://github.com/espressif/esp-idf/bl ... ELOG#L2343

It looks like it is enableable by changing a configuration setting in lwipopts.h. However, before doing that, I would suggest a study of the LWIP package in depth and determine what made the LWIP authors make the decision to disable it by default. They may have had some very sound reason for doing such that is specific to the implementation of LWIP.

A deeper question (for me) is the effect/goal you are trying to achieve. Personally, I've never had a need to even think about this option. I'd be very interested to understand from you what the perceived need is to change the value?