Skip to main content
added 33 characters in body
Source Link
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)

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.

Source: Unix Socket FAQ

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 no 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!

References

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 no 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!

References

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.

Source: Unix Socket FAQ

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 no 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!

References

edited body
Source Link
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 no 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!

References

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 no 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!

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 no 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!

References

edited body
Source Link
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)

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 no 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!

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 no 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!

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 no 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!

edited body
Source Link
Faheem Mitha
  • 36.1k
  • 33
  • 129
  • 189
Loading
Source Link
slm
  • 379.7k
  • 127
  • 793
  • 897
Loading