Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. blocking read of QUDPSocket

blocking read of QUDPSocket

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 300 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    themts
    wrote on last edited by
    #1

    Hey guys,

    I'm currently porting a communication-lib to QT.
    The old lib was written in delphi and for windows only. The new one should run on windows an linux.

    Before I was directly working the with windows socket-api and I was reading from the socket by "recvfrom()".
    That way I had a quite good performance on reading at around 1kHz with as less overhead as possible.

    Now I had the idea of using QUdpSocket but I want to avoid sending messages to an event-loop.
    So the only way of reading directly in a thread seems "waitForReadyRead()" which seems not to run very consistent in windows
    "Note: This function may fail randomly on Windows. Consider using the event loop and the readyRead() signal if your software will run on Windows."

    Is there any other way or should I work directly on the socket interface again and make it cross-platform usable myself?

    THX
    mts

    1 Reply Last reply
    0
    • AxelViennaA Offline
      AxelViennaA Offline
      AxelVienna
      wrote on last edited by
      #2

      waitForReadyRead() basically holds your application until the UDP packet you are awaiting is ready to be read out of the buffer. Note that you “are sending to the event loop” already in this case. You are just blocking it in order to wait for an external condition to be met. Taking that risk may just fail in Windows (i.e. you loose the packet) but also cause misbehaviour on other platforms (you can wait forever). It can still be useful for small, technical applications which you just kill if they hang.

      Connecting your read method to the readyRead() signal is the robust way of implementation. It does not block the event loop ans reads your UDP stream in the right order.

      C++ and Python walk into a bar. C++ reuses the first glass.

      1 Reply Last reply
      3

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved