This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

setsockopt () failed



Greetings TI-Community,

INT32 sendbuf = 1024;
if(!setsockopt( sockUDPClient, SOL_SOCKET, SO_SNDBUF, &sendbuf, sizeof(sendbuf) )) printf("\nError setup SO_SNDBUF.");
if(!setsockopt( sockUDPClient, SOL_SOCKET, SO_RCVBUF, &sendbuf, sizeof(sendbuf) )) printf("\nError setup SO_RCVBUF.");

I realize that the default sendbuffer is limited to 256 byte. So I want to change this, but the setsockopt() call allways returns a error. What do I wrong?

Thank You
Patrick

  • Patrick,

    I never used the return value but always get read the value to check it after I set it.  Have you used the get function to see if its being set?  Here is my code, it looks just like yours :)

    	struct sockaddr_in 	myinfo;
    	struct timeval     	to;
    	int                	i;
    	int					opt;
    	SOCKET				mySocket;
    
    	mySocket = socket(AF_INET, SOCK_DGRAM, 0);
    
    	to.tv_sec  = 0;
    	to.tv_usec = 0;
    	setsockopt( mySocket, SOL_SOCKET, SO_SNDTIMEO, &to, sizeof( to ) );
    	setsockopt( mySocket, SOL_SOCKET, SO_RCVTIMEO, &to, sizeof( to ) );
    
    	i = sizeof(opt);
    
    	opt = 1;
    	setsockopt( mySocket, SOL_SOCKET, SO_BLOCKING, &opt, sizeof( opt ) );
    
    	opt = 64000;
    	setsockopt( mySocket, SOL_SOCKET, SO_SNDBUF, &opt, sizeof( opt ) );
    
    	getsockopt( mySocket, SOL_SOCKET, SO_SNDBUF, &opt, &i);

    Brandy

  • Patrick,
    Can you try the below sequence and let us know the status.

    INT32 sendbuf,recvbuf, retVal;

    /* Configure the Send buffer size */
    sendbuf = 1024;
    retVal = setsockopt(sockUDPClient, SOL_SOCKET, SO_SNDBUF, &sendbuf, sizeof(sendbuf));
    if(retVal)
    printf("\nError setup SO_SNDBUF.");

    /* Configure the Receive buffer size */
    recvbuf = 1024;
    retVal = setsockopt(sockUDPClient, SOL_SOCKET, SO_RCVBUF, &recvbuf, sizeof(recvbuf));
    if(retVal)
    printf("\nError setup SO_RCVBUF.");

  • Greetings Pubesh,

    the return value of setsockopt if succeeded is 0 (spru524h.pdf). So !0 triggered my Error. My fault.

    But if I configure this buffer sizes I got a socket failure: sendto() failed with error: 40.

    I also recognize that the recvfrom function only fill up my UDPrecv vector for 256 Bytes even if the i value is 1024 (= received Bytes)

    i = (int)recvfrom( s, (void **)&UDPrecv, 1024, 0,(PSA)&sin1, &tmp );
    if (i>0)printf("\nUDP Server received UDP with %d bytes.", i);

  • Patrick,

    You call the fdError() and find the error number, check the error status in the serrno.h file.

    If you could not solve this issue, share your code.

  • #define EMSGSIZE        40      // Message too long

    So I raised up the buffer sizes to 2048 and it worked.

    But my receive vector still get only 256 Bytes. Any sugestions?

    Thank You

    Patrick

  • Patrick,

    Glad to hear for fix the issue. 

    For receive vector: check this sequence on your code before NC_NetStart().

    // UDP Receive limit
    rc = 8192;
    CfgAddEntry( hCfg, CFGTAG_IP, CFGITEM_IP_SOCKUDPRXLIMIT,
    CFG_ADDMODE_UNIQUE, sizeof(uint), (UINT8 *)&rc, 0 );

    This may be giving issue.