Virtualize options setting on TCP server socket
Currently, socket options setting is hardcoded in QTcpServer::listen() function after the engine initialization and before a binding to the address. This disallows a socket tuning in further QTcpServer inheritance. Add a private virtual configureCreatedSocket() method that gives an ability to set the socket options before listening. Change-Id: Ice9b477e64f21daee96c0ec6d27a8408f9e1aa93 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>bb10
parent
70d4b35b93
commit
a03c633e4f
|
|
@ -158,6 +158,23 @@ QNetworkProxy QTcpServerPrivate::resolveProxy(const QHostAddress &address, quint
|
|||
}
|
||||
#endif
|
||||
|
||||
/*! \internal
|
||||
*/
|
||||
void QTcpServerPrivate::configureCreatedSocket()
|
||||
{
|
||||
#if defined(Q_OS_UNIX)
|
||||
// Under Unix, we want to be able to bind to the port, even if a socket on
|
||||
// the same address-port is in TIME_WAIT. Under Windows this is possible
|
||||
// anyway -- furthermore, the meaning of reusable on Windows is different:
|
||||
// it means that you can use the same address-port for multiple listening
|
||||
// sockets.
|
||||
// Don't abort though if we can't set that option. For example the socks
|
||||
// engine doesn't support that option, but that shouldn't prevent us from
|
||||
// trying to bind/listen.
|
||||
socketEngine->setOption(QAbstractSocketEngine::AddressReusable, 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*! \internal
|
||||
*/
|
||||
void QTcpServerPrivate::readNotification()
|
||||
|
|
@ -275,17 +292,7 @@ bool QTcpServer::listen(const QHostAddress &address, quint16 port)
|
|||
if (addr.protocol() == QAbstractSocket::AnyIPProtocol && proto == QAbstractSocket::IPv4Protocol)
|
||||
addr = QHostAddress::AnyIPv4;
|
||||
|
||||
#if defined(Q_OS_UNIX)
|
||||
// Under Unix, we want to be able to bind to the port, even if a socket on
|
||||
// the same address-port is in TIME_WAIT. Under Windows this is possible
|
||||
// anyway -- furthermore, the meaning of reusable on Windows is different:
|
||||
// it means that you can use the same address-port for multiple listening
|
||||
// sockets.
|
||||
// Don't abort though if we can't set that option. For example the socks
|
||||
// engine doesn't support that option, but that shouldn't prevent us from
|
||||
// trying to bind/listen.
|
||||
d->socketEngine->setOption(QAbstractSocketEngine::AddressReusable, 1);
|
||||
#endif
|
||||
d->configureCreatedSocket();
|
||||
|
||||
if (!d->socketEngine->bind(addr, port)) {
|
||||
d->serverSocketError = d->socketEngine->error();
|
||||
|
|
|
|||
|
|
@ -80,6 +80,8 @@ public:
|
|||
QNetworkProxy resolveProxy(const QHostAddress &address, quint16 port);
|
||||
#endif
|
||||
|
||||
virtual void configureCreatedSocket();
|
||||
|
||||
// from QAbstractSocketEngineReceiver
|
||||
void readNotification() Q_DECL_OVERRIDE;
|
||||
void closeNotification() Q_DECL_OVERRIDE { readNotification(); }
|
||||
|
|
|
|||
Loading…
Reference in New Issue