[Interest] Setting socket options for QWebSocketServer

Elvis Stansvik elvstone at gmail.com
Sat May 14 00:22:16 CEST 2016


2016-05-13 23:04 GMT+02:00 Thiago Macieira <thiago.macieira at intel.com>:
> On sexta-feira, 13 de maio de 2016 20:33:53 PDT Elvis Stansvik wrote:
>> 2016-05-13 19:41 GMT+02:00 Thiago Macieira <thiago.macieira at intel.com>:
>> > You can't reuseaddr with TCP.
>>
>> Hmm, I thought that was quite common in TCP servers? To use
>> SO_REUSEADDR in order to avoid the IP/port combo remaining in the
>> TIME_WAIT state for a long time, should the server closed unexpectedly
>> with connected clients. I know it might not be the best practice.. but
>> you mean I can't?
>
> Ah, I see what you mean. That's not "reusing the address" in the sense that
> UDP does, in which two sockets can use the same address at the same time.
>
> The behaviour you want makes sense. It's just that it's an abuse of the
> SO_REUSEADDR API. And sure enough, Qt is using that loophole too:

Yep, found that snippet too. So the dirty work taken care of for me by
Qt, since QWebSocketServer uses that internally :)

Elvis

>
> 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
> }
>
> --
> Thiago Macieira - thiago.macieira (AT) intel.com
>   Software Architect - Intel Open Source Technology Center
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest



More information about the Interest mailing list