简体   繁体   English

发送数据时异步tcp套接字和进度

[英]async tcp socket and progress when sending data

I use http based file upload in my c++ code (runs on linux/android). 我在我的C ++代码中使用基于http的文件上传(在linux / android上运行)。 I use async tcp socket for writing file data. 我使用异步tcp套接字写入文件数据。 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. 对于慢速链接,问题变得很明显,在100%发送进度通知和发送完整消息之间需要数十秒(有时是一分钟)。

I don't modify SO_SNDBUF, in my case it's 35KB (queried by getsockopt). 我不修改SO_SNDBUF,在我的情况下为35KB(由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)? 有没有一种方法可以获取有关传输进度的TCP通知(由远程套接字确认)?

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. 您将无法知道此缓冲区的当前大小,因为它位于内核区域中,并且没有已知的/已记录的ioctl来告知其大小。 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 估算整个传输期间的数据速率,以便最后计算此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. 编辑:在对《 TCP/IP Architecture, Design & Implementation in Linux中的TCP/IP Architecture, Design & Implementation in Linux 》一书进行了研究之后,我已经看到了用于TCP套接字监视的NETLINK_TCPDIAG选项。 Netlink sockets is an IPC method between kernel and user land. Netlink套接字是内核和用户域之间的IPC方法。 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. 不幸的是,对于NETLINK_TCPDIAG选项,没有详细信息……我只知道您必须创建一个这样的套接字: int fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_TCPDIAG)和原始套接字创建需要root特权。

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 ! 之后,您唯一的朋友似乎是linux/net/ipv4/tcp_diag.chttp://www.cs.fsu.edu/~baker/devices/lxr/http/ident?v=2.6.11.8;i= NETLINK_TCPDIAG )... Google上没有关于这种协议的任何信息...祝您好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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