Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-96325

QTcp socket half duplex/one way Usage Support

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Reported
    • Priority: P2: Important
    • Resolution: Unresolved
    • Affects Version/s: 5.12.11
    • Fix Version/s: None
    • Component/s: Network, Network: Sockets
    • Labels:

      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);
      

       

        Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            Assignee:
            manordheim Mårten Nordheim
            Reporter:
            abbas_percin Abbas Perçin
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:

                Gerrit Reviews

                There are no open Gerrit changes