简体   繁体   中英

Query send buffer usage on a socket in linux

Is it possible to query how many bytes are in a socket's send buffer in linux? I'd like to be able to query SO_SNDBUF with getsockopt to get the buffer size and then [insert technique here] to get the actual usage, which will let me know how much I'm filling up the buffer.

That's not what SO_SNDBUF does. SO_SNDBUF sets or gets the maximum socket send buffer in bytes (quoting socket(7) ). You could probably use the SIOCOUTQ or TIOCOUTQ ioctls if you're using tcp or udp .

However, it's highly unlikely this is the right approach . Have you considered using a select-like mechanism to notify you when a socket is writable ? Combined with nonblocking behavior it could be the ticket to a clean approach.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM