PDA

View Full Version : QHttp - how close TCP connection



juzwa
13th August 2011, 11:42
I have QHttp in threads

When I run threads QHttp creates a connection, everthing is OK but after all in netstat I have open ports

TCP 192.168.0.122:55770 fx-in-f113:http TIME_WAIT
TCP 192.168.0.122:55771 fx-in-f100:http TIME_WAIT
TCP 192.168.0.122:55772 fx-in-f101:http TIME_WAIT
TCP 192.168.0.122:55773 fx-in-f102:http TIME_WAIT
TCP 192.168.0.122:55774 fx-in-f113:http TIME_WAIT
TCP 192.168.0.122:55775 fx-in-f100:http TIME_WAIT
TCP 192.168.0.122:55776 fx-in-f101:http TIME_WAIT
....
etc. (eq 100 or more open ports)


how close it

I tried use abort, close, clearpendintconnection etc like this:

QIODevice *dev = http->currentDestinationDevice();
if(dev){
dev->close();
}

state for each qhttp connection changed from 5 to 6 (from Connected to Closing), but is not Unconnected

how can I close Qhttp connection ater request?

squidge
13th August 2011, 13:26
The ports are closed - they are in TIME_WAIT. The rest is upto the OS.

juzwa
13th August 2011, 15:41
Thank you for answer

but i have another question

I read that should set flag SO_REUSEADDR (WINDOWS) for socket, to reuse this ports which are in TIME_WAIT state

example for set SO_REUSEADDR flag :


int flag = 1;
result = setsockopt( listensock, SOL_SOCKET, SO_REUSEADDR, ( char * ) &flag, sizeof (int ) );

but I can't set this option(flag) in QHttp class
I tried found wher can I set this option in other classes QNetworkAccessManager, QTcpSocket, QNetworkReply but without success

I only found info about SO_REUSEADDR flag in QUdpSocek class


How can I reuse ports in TIME_WAIT state by using QHttp class

(maybe I should use something other than QHttp, to reuse this ports?)

squidge
13th August 2011, 19:23
I'd say SO_REUSEADDR is more practical/useful for server applications (which require to bind to specific ports) and you are doing client operations.

Secondly, QHttp is obsolete and should not be used in new code. You really should use QNetworkAccessManager (but this will have the same restrictions)