Question

I use http based file upload in my c++ code (runs on linux/android). I use async tcp socket for writing file data. My issue is that my progress bar reflects what have been written to the socket, not what was actually sent out on the wire. Problem becomes obvious with slow links where it takes tens of seconds (sometimes over a minute) between 100% sent progress notification and send complete message.

I don't modify SO_SNDBUF, in my case it's 35KB (queried by getsockopt). How can I fix progress notification to correctly reflect current transfer status? Is there a way to query size of data that's still remains in the buffer? Is there a way to get TCP notification about transfer progress (as confirmed by remote socket)?

Was it helpful?

Solution

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 !

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top