gpt4 book ai didi

c++ - 即使缓冲区被未决操作覆盖,WriteFile 也成功

转载 作者:太空宇宙 更新时间:2023-11-04 05:58:18 25 4
gpt4 key购买 nike

在我的程序中(发布到此 question ),我在客户端进行了以下更改:

wretry:   
cbToWrite = _stprintf(chBuf[0], TEXT("Message %d from Client"), retrycount - numberofsend + 1);
cbToWrite *= sizeof(TCHAR);

fSuccess = WriteFile(hPipe, chBuf[0], cbToWrite,
&cbWritten, &woverlapped[retrycount-numberofsend]);

这样,现在每次写入都将使用相同的缓冲区。

在这种情况下,WriteFile 每次返回 ERROR_IO_PENDING 时都处于挂起状态。因为缓冲区的内容每次都会被覆盖,所以服务器应该收到写入缓冲区的最后一条消息。但是服务器正在毫无问题地接收消息。

这是否意味着消息首先被复制到某个内部缓冲区中?我可以销毁缓冲区并期望将消息传送到服务器吗?

最佳答案

再次引用MSDN:

lpBuffer [in] A pointer to the buffer containing the data to be written to the file or device. This buffer must remain valid for the duration of the write operation. The caller must not use this buffer until the write operation is completed.

因此,如果您在写入操作进行时弄乱了缓冲区,那么您的消息似乎无法保证安全到达。你绝对不应该破坏缓冲区

关于c++ - 即使缓冲区被未决操作覆盖,WriteFile 也成功,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23102845/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com