Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
5.12.11
Description
There is currently no support for using QTcp socket half duplex/one way.
I'm working with QTcpServer and QTcpSocket for making a server. Other side there is a client written in C, which calls shutdown(socket, SD_SEND); after writing request, so it only expects data from server.
{{/*
- WinSock 2 extension – manifest constants for shutdown()
*/#define SD_RECEIVE 0x00}}
#define SD_SEND 0x01
#define SD_BOTH 0x02
The qTcp socket I have on the server side immediately closes the connection (QTcpSocket::disconnected signal fired) without waiting to send data. I went through the Qt documentation and the forum in detail, but couldn't find any information. I'm starting to think that Qt doesn't support half duplex connections.
In my opinion, qt tcp socket should check the content of the incoming fin message and decide whether to close the socket according to its content. Currently, the tcp socket is closing, although the incoming fin message contains only a one-way shutdown (SD_SEND).
Is my assumption true ? Is qt doesn't support half-duplex tcp usage ? Is this a bug or a feature? And are you considering a solution?
Example code on client side:
result = connect(desc, addrInfo->ai_addr, (int)addrInfo->ai_addrlen); if (result == SOCKET_ERROR) { closesocket(desc); desc = INVALID_SOCKET; } if (desc == INVALID_SOCKET) { printf("Unable to connect to server!\n"); } // Send request result = send(desc, reinterpret_cast<const char*>(request), requestLength, 0); if (result == SOCKET_ERROR) { printf("send failed with error: %d\n", WSAGetLastError()); closesocket(desc); } // shutdown the connection since no more data will be sent result = shutdown(desc, SD_SEND); if (result == SOCKET_ERROR) { printf("shutdown failed with error: %d\n", WSAGetLastError()); closesocket(desc); } // Receive until the peer closes the connection result = recv(desc, reinterpret_cast<char*>(response), responseLength, 0); if (result <= 0) { if (result == 0) { printf("Connection closed\n"); } else { printf("recv failed with error: %d\n", WSAGetLastError()); } } // cleanup closesocket(desc);