You won't be able to know the current size of this buffer, because it is in kernel land and there is no known / documented ioctl to tell its size. Even you could know it, it won't be portable at all, thus I don't think it is a good way to solve this problem.
You can either:
Estimate the data rate during the whole transfer, in order to calculate, at the end, the time remaining for the buffer of thise SO_SNDBUF
Use a third party library, which will include the previous computation !
EDIT: After some research in the book TCP/IP Architecture, Design & Implementation in Linux
, I've seen the NETLINK_TCPDIAG
option for TCP socket monitoring. Netlink sockets is an IPC method between kernel and user land. For the NETLINK_TCPDIAG
option, unfortunately, there is no detail ... I just know that you must create a socket like this: int fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_TCPDIAG)
and raw socket creation needs root privileges.
After that, your only friend seems to be linux/net/ipv4/tcp_diag.c
(http://www.cs.fsu.edu/~baker/devices/lxr/http/ident?v=2.6.11.8;i=NETLINK_TCPDIAG)... There is nothing on Google about this type of protocol ... Good luck !