Skip to main content
1 of 5
slm
  • 379.7k
  • 127
  • 793
  • 897

I don't believe that's how sockets work. You keep reading until it's empty, the size isn't communicated through the socket, and it's not to my knowledge displayed anywhere on the socket that's created on the filesystem /tmp/tmux-1000/default.

excerpt

### Unix Socket FAQ - 2. Questions regarding both Clients and Servers (TCP/SOCK_STREAM)

I don't think that write() can legitimately return 0. read() should return 0 on receipt of a FIN from the peer, and on all following calls.

So yes, you must expect read() to return 0.

Also if you look at how reading from a socket is often done, you're essentially in a while (true) loop, continuously reading until the connection is explicitly terminated. You have so way to know how much data is pending in the socket.

excerpt

while ( true )
    {
        unsigned char packet_data[256];
        unsigned int maximum_packet_size = sizeof( packet_data );
...

Source: SENDING AND RECEIVING PACKETS

So to answer your question, the only way to know how much data is on the socket, is to read it all!

slm
  • 379.7k
  • 127
  • 793
  • 897