mdk*_*mdk 5 c sockets networking ioctl tcp
到目前为止,我的谷歌搜索和检查出 msdn 表明 Microsoft Windows 没有提供任何等效的 TIOCOUTQ / SIOCOUTQ 来查找套接字发送缓冲区中未发送的数据量。如果一些好的 hack 发现了其他东西,并且可以在这里发布,那将非常有用。它将允许我的以下代码成为跨平台
int net_get_unsent (const int sockfd, unsigned long &sock_bytes_unsent )
{
/* Queries how much data sent on sockfd,
* may not have yet been recieved by the reciever
*
* returns more than 1 if there's unsent data,
* and fills in the amount of unsent data in sock_bytes_unsent
*
* returns 0 if all the data has been sent
*
* returns < 0 if there was a socket I/O error
* */
int err = 0;
int wsaerr = 0;
if (sockfd <= 0)
return -1;
#ifdef WINDOWS
err = ioctlsocket(sockfd, SIOCOUTQ , &sock_bytes_unsent);
#else
err = ioctl(sockfd, TIOCOUTQ, &sock_bytes_unsent);
#endif
if (err < 0) {
#ifdef WINDOWS
wsaerr = WSAGetLastError();
#else
wsaerr = errno;
#endif
printf("failed to get unsent data error:%d", wsaerr );
sock_bytes_unsent = 0;
return -1 * wsaerr;
} else if (sock_bytes_unsent > 0 ) {
printf( "unsent data: %lu bytes", sock_bytes_unsent );
return 1;
}
return err;
}
Run Code Online (Sandbox Code Playgroud)
据我所知,Windows 中没有这样的调用。(很遗憾,因为它效果很好!)
但是,我发现以下链接非常有用,可以帮助您解决问题。这些概念适用于任何操作系统,显然除了“还能做什么?”中提到的 SIOCOUTQ 部分。部分。