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)..
- A qLocalServer (on the Server) create a socket, bind it to a known location and listen for incoming connections..
- A qLocalSocket (on the client) connect to the known location. On the server connection is accepted.
- Server can send data to the socket using
writemethod (of the
qLocalSocketinstance returned by
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).
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.