Add ToS option to sockets.

Creates a new SocketOption called called TypeOfServiceOption that can be
used with the existing setSocketOption method to set the ToS byte in a
socket socket. This is done only for unix systems because windows
doesn't support directly setting the ToS/DSCP byte:
http://support.microsoft.com/kb/248611
http://blogs.msdn.com/b/wndp/archive/2006/07/05/657196.aspx

Change-Id: Idf9da2dd8307ac7057982fbfdf9e4e9ebe366780
Task-number: QTBUG-6221
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Peter Hartmann <peter.hartmann@nokia.com>
This commit is contained in:
Jonas M. Gastal 2011-12-20 14:42:06 -02:00 committed by Qt by Nokia
parent 86f5b78394
commit 755fe9da1d
5 changed files with 43 additions and 2 deletions

View File

@ -360,6 +360,19 @@
\value MulticastLoopbackOption Set this to 1 to enable the IP_MULTICAST_LOOP (multicast loopback) socket option.
\value TypeOfServiceOption This option is not supported on Windows. This maps to to the IP_TOS socket option. Possible values are:
\table
\header \o Value \o Description
\row \o 224 \o Network control
\row \o 192 \o Internetwork control
\row \o 160 \o CRITIC/ECP
\row \o 128 \o Flash override
\row \o 96 \o Flash
\row \o 64 \o Immediate
\row \o 32 \o Priority
\row \o 0 \o Routine
\endtable
\sa QAbstractSocket::setSocketOption(), QAbstractSocket::socketOption()
*/
@ -1805,6 +1818,10 @@ void QAbstractSocket::setSocketOption(QAbstractSocket::SocketOption option, cons
case MulticastLoopbackOption:
d_func()->socketEngine->setOption(QAbstractSocketEngine::MulticastLoopbackOption, value.toInt());
break;
case TypeOfServiceOption:
d_func()->socketEngine->setOption(QAbstractSocketEngine::TypeOfServiceOption, value.toInt());
break;
}
}
@ -1841,6 +1858,10 @@ QVariant QAbstractSocket::socketOption(QAbstractSocket::SocketOption option)
case MulticastLoopbackOption:
ret = d_func()->socketEngine->option(QAbstractSocketEngine::MulticastLoopbackOption);
break;
case TypeOfServiceOption:
ret = d_func()->socketEngine->option(QAbstractSocketEngine::TypeOfServiceOption);
break;
}
if (ret == -1)
return QVariant();

View File

@ -113,7 +113,8 @@ public:
LowDelayOption, // TCP_NODELAY
KeepAliveOption, // SO_KEEPALIVE
MulticastTtlOption, // IP_MULTICAST_TTL
MulticastLoopbackOption // IP_MULTICAST_LOOPBACK
MulticastLoopbackOption, // IP_MULTICAST_LOOPBACK
TypeOfServiceOption //IP_TOS
};
enum BindFlag {
DefaultForPlatform = 0x0,

View File

@ -99,7 +99,8 @@ public:
LowDelayOption,
KeepAliveOption,
MulticastTtlOption,
MulticastLoopbackOption
MulticastLoopbackOption,
TypeOfServiceOption
};
virtual bool initialize(QAbstractSocket::SocketType type, QAbstractSocket::NetworkLayerProtocol protocol = QAbstractSocket::IPv4Protocol) = 0;

View File

@ -251,6 +251,12 @@ int QNativeSocketEnginePrivate::option(QNativeSocketEngine::SocketOption opt) co
n = IP_MULTICAST_LOOP;
}
break;
case QNativeSocketEngine::TypeOfServiceOption:
if (socketProtocol == QAbstractSocket::IPv4Protocol) {
level = IPPROTO_IP;
n = IP_TOS;
}
break;
}
int v = -1;
@ -352,6 +358,12 @@ bool QNativeSocketEnginePrivate::setOption(QNativeSocketEngine::SocketOption opt
n = IP_MULTICAST_LOOP;
}
break;
case QNativeSocketEngine::TypeOfServiceOption:
if (socketProtocol == QAbstractSocket::IPv4Protocol) {
level = IPPROTO_IP;
n = IP_TOS;
}
break;
}
return ::setsockopt(socketDescriptor, level, n, (char *) &v, sizeof(v)) == 0;

View File

@ -422,6 +422,9 @@ int QNativeSocketEnginePrivate::option(QNativeSocketEngine::SocketOption opt) co
n = IP_MULTICAST_LOOP;
}
break;
case QNativeSocketEngine::TypeOfServiceOption:
return -1;
break;
}
int v = -1;
@ -502,6 +505,9 @@ bool QNativeSocketEnginePrivate::setOption(QNativeSocketEngine::SocketOption opt
n = IP_MULTICAST_LOOP;
}
break;
case QNativeSocketEngine::TypeOfServiceOption:
return false;
break;
}
if (::setsockopt(socketDescriptor, level, n, (char*)&v, sizeof(v)) != 0) {