[Interest] Strange socket problem. QTcpSocket. Windows/Linux

Thiago Macieira thiago.macieira at intel.com
Wed Jan 29 19:19:04 CET 2014


On quarta-feira, 29 de janeiro de 2014 09:48:44, Guido Seifert wrote:
> > Can you say what is happening at the TCP level? Are the packets being
> > sent? Do they have the PSH flag set? Does the TV send back ACK packets?
> 
> To tell you the truth, I don't know. This is normally a bit too low-level
> for me. More or less I moved on, because even if I had seen a problem
> within the TCP packets, I still would have been unable to fix it. If you
> are interested, I would start wireshark again and check for the PSH flag
> and ACK packets. But not before this weekend. I don't think it is a problem
> in my code or in Qt, else the E series should be affected, too.

Well, the point is that we'd be able to rule it as a TCP stack problem or not. 
If it isn't a stack problem, then it's something that either Qt or you are 
doing, which might have feasible solutions.

> > Is the problem that it should be replying with data over the TCP
> > connection, but isn't?
> 
> Yes. When I do a QTcpSocket::write(const QByteArray & byteArray) the correct
> number of bytes written is returned.

That number is not relevant. QTcpSocket is fully buffered, so it always accepts 
as many bytes as you've given it. That number is only telling you that those 
bytes got buffered properly.

Do you get bytesWritten(qint64) emitted with a total count equalling that 
number of bytes? Alternatively, if you loop as

	while (socket->bytesToWrite() && socket->waitForBytesWritten())
		;

Do you eventually get to bytesToWrite() == 0? Or does it time out trying to 
write?

Since the OS TCP stack is *also* buffered, that only means the bytes got copied 
from userspace to the kernel (though, unlike QTcpSocket, the kernel buffers are 
not unlimited). If you get to bytesToWrite() == 0, the question is whether the 
other side is receiving them. You can find that out by running ss or netstat:

E.g.:
 $ netstat -nt
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0    112 10.24.4.51:47745        10.7.211.16:1080        
ESTABLISHED

The above is showing that my machine has 112 bytes in the send-queue yet to 
send the remote. Does the number go to zero? Or does it remain?

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20140129/21730759/attachment.sig>


More information about the Interest mailing list