IOCP服务器WSASend的疑惑
MSDN里面的说明:
The array of WSABUF structures pointed to by the lpBuffers parameter is transient. If this operation is completed in an overlapped manner, it is the service provider's responsibility to capture these WSABUF structures before returning from this call. This enables applications to build stack-based WSABUF arrays.
Note The successful completion of a WSASend does not indicate that the data was successfully delivered.
意思是提交的数据在WSASend后就可以挪作他用或销毁,即可以象如下方式调用:
void SendData()
{
char data[100];
sprintf(data,"something to send");
WSASend(...)
};
看起来WSASend是会把数据复制一份自己保存,试了下,分配1M的缓冲区,读取一个三四百K的文本,一次性把数据WSASend出去,然后立马销毁该缓冲区,客户端是能完整收到所有数据的。
但是我疑惑的是上面MSDN里最后一句话,WSASend不保证数据成功提交,意思是不是这样调用会丢包呢?那就无法体现TCP的可靠性了。这种情况下如果GetQueuedCompletionStatus检测到发送的字节数与要发送的不一致,没办法处理了,因为发送的数据已不存在了。那MSDN又为什么说可以销毁数据呢?