PDA

View Full Version : QUpdSocket and setsockopt()



bob2oneil
28th October 2011, 22:07
I need to set the DSCP fields for UDP frames transmitted using a QUdpSocket. This socket will transmit to a range of IP addresses, and is not bound to a particular port.

I need to get the socket descriptor for the socket in a cross platform manner (although I can use conditional compilation)

The problem is, the socketDescriptor() API returns -1 unless the socket is connected. If I bind to any port as shown, the ::setsockopt() API continues to fail

Here is my code segment. Anybody have any ideas or tried to do similar things?



// Create thread local storage
m_udpTxSocket = new QUdpSocket();

// Bind to any socket
m_updTxSocket->bind());

// Set DSCP field of socket to high priority setting
DWORD DSCPValue = 0x07;
if (::setsockopt(m_udpTxSocket->socketDescriptor(), // Socket descriptor
IPPROTO_IP, // Socket level
IP_TOS, // Socket option (type of service)
(char *)&DSCPValue, // Option value buffer
sizeof(DWORD)))
{
FILE_LOG(logERROR) << "TDMA: failed to set transmit socket DSCP value";
}