Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I get error 10042( WSAENOPROTOOPT) as return value from setsockopt below.
I want to turnoff the Nagle algorithm in order to send the request out as fast
as possible.
Any idea on how to get this option to work?
BTW this code does build, the formatting makes it appear problematic.
Thanks
ak
C++
//---------------------------------------------
// Create a udp socket for sending reRequests
//
udpRequestsocket_  = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if ( udpRequestsocket_ == INVALID_SOCKET)
{
    WSACleanup();
    return 1;
}
int flag = 1;
int result = setsockopt(udpRequestsocket_,            /* socket affected */
                        IPPROTO_TCP,                  /* set option at TCP level */
                        TCP_NODELAY,                  /* name of option */
                        (char *)flag,                 /* the cast is historical  cruft */
                        sizeof(int));                /* length of option value */
if (result)
{
    sprintf_s(logBuf, sizeof(logBuf), "ERR: error:%d setting setsockopt for      updRequestsocket_", WSAGetLastError());
    MyLog(logBuf);
}
Posted
Updated 21-Jun-11 8:11am
v4
Comments
Manfred Rudolf Bihy 21-Jun-11 14:08pm    
Edit: added code <pre> tags.

1 solution

First you construct a UDP socket and then try to set a TCP option. Don't you kind of think that error would have to be anticipated? Nagle Algorithm[^] is for TCP and has nothing to do with UDP. See here for the options available for UDP: http://msdn.microsoft.com/en-us/library/ms738603(v=vs.85).aspx[^].

Regards,

--MRB
 
Share this answer
 
v3
Comments
Alan Kurlansky 21-Jun-11 15:28pm    
You are correct. I did anticipate the error. However, since I didn't find in my searches anything explicitly ruling it out, I gave it a shot. I followed your link, and it seems to me that either the Nagle algorithm does not apply to unicast datagram transmissions or there's no way to get at it to control it.
Manfred Rudolf Bihy 22-Jun-11 5:18am    
I don't really know what you think you're talking about. UDP has nothing to do with Nagle Algorithm. That's why I posted the link about that algorithm. It's for the TCP stack only. Nagle is also called "slow start" and please read about it, read again and then read some more on the differences of TPC/IP and UDP/IP.
BTW Unaccepting this correct answer and not voting for it is not going quite well with me. This kind of behaviour is not acceptable.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900