Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I tell if a socket buffer is full?

Tags:

c

sockets

How can I tell if a read socket buffer is full or a write socket buffer is empty?

Is there a way I can get the status of a socket buffer without a system call?

UPDATE: How about this: I'd like to get a callback or signal when either the read socket buffer is full or the write socket buffer is empty. This way I can stop processing to allow more I/O to occur on the wire, since being I/O bound is always an issue when sending data on the wire.

The select() call is how you check if the read buffer has something in it. Not when it is full (I think).

like image 848
Crazy Chenz Avatar asked Nov 26 '09 11:11

Crazy Chenz


People also ask

How do I test a socket buffer?

If you want see your buffer size in terminal, you can take a look at: /proc/sys/net/ipv4/tcp_rmem (for read) /proc/sys/net/ipv4/tcp_wmem (for write)

What happens if buffer is full?

A buffer overflow occurs when a program or process attempts to write more data to a fixed-length block of memory, or buffer, than the buffer is allocated to hold. Buffers contain a defined amount of data; any extra data will overwrite data values in memory addresses adjacent to the destination buffer.

What is Max buffer size of TCP socket?

The default buffer size is 8 KB. The maximum size is 8 MB (8096 KB). The optimal buffer size depends on several network environment factors including types of switches and systems, acknowledgment timing, error rates and network topology, memory size, and data transfer size.

What should receive buffer size be?

The size of the receive buffer, in bytes. The default value is 8192 bytes.


1 Answers

Poll the file descriptor with select and a zero timeout - if select says it's writeable, the send buffer isn't full.

(Oh... without a system call. No, there isn't.)

Addendum:

In response to your updated question, you can use two ioctls on the TCP socket: SIOCINQ returns the amount of unread data in the recieve buffer, and SIOCOUTQ returns the amount of unsent data in the send queue. I don't believe there's any asynchronous event notification for these though, which will leave you having to poll.

like image 149
caf Avatar answered Sep 24 '22 09:09

caf