qLocalServer write blocked (full buffer), how to discard data?

I'm trying to understand how local sockets (Unix domain socket) works, specifically how to use them with QT. It is my understanding that Unix domain socket is always reliable and no data is lost. Looking at these examples these are the steps (making it simple), considering a Server (producer) and a Client (consumer)..

  1. A qLocalServer (on the Server) create a socket, bind it to a known location and listen for incoming connections..
  2. A qLocalSocket (on the client) connect to the known location. On the server connection is accepted.
  3. Server can send data to the socket using write method (of the qLocalSocket instance returned by qLocalServer->nextPendingConnection())

When the socket buffer is full, any write by the server is blocked as soon as the client read from the socket and free the socket buffer. This is the part I don't understand: suppose the socket buffer is full and the server keeps writing .. where all these data are stored and how to control the data structure holding these data? Is there any way to discard these data? Imagine a server that produce data 20 times/second and a client that consume 1 time/second, I want to drop all data in bewtween (better real time data than ALL the data in my use case).

1 answer

  • answered 2022-01-19 20:05 mzimmers

    There's nothing unique about the Qt socket classes (for the purposes of this question).

    When the socket buffer is full, any write by the server is blocked as soon as the client read from the socket and free the socket buffer.

    No - the write is blocked until the client performs a read, freeing up some of the buffer. (Perhaps this is what you meant and we just have a minor language barrier.)

    Once the server writes to the socket, the data can't be "un-written" so how best to handle this depends on your application, and whether you have more control over the programming of the server or the client.

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum