简体   繁体   English

名为管道,ERROR_MORE_DATA和CancelIoEx的重叠消息

[英]Overlapped message named pipe, ERROR_MORE_DATA and CancelIoEx

I am using $SUB for the first time and have come across this problem. 我第一次使用$ SUB,遇到了这个问题。 Both, client and server use overlapped operations and here is the specific situation I have a problem with. 客户端和服务器都使用重叠的操作,这是我遇到问题的特定情况。

Client 客户

C1. C1。 Connects to the server. 连接到服务器。
C2. C2。 Sends the message bigger than a pipe buffer and buffer passed to overlapped read operation in the server. 发送大于管道缓冲区的消息,并将缓冲区传递给服务器中的重叠读取操作。
C3. C3。 Successfully cancels the send operation. 成功取消发送操作。

Server 服务器

S1. S1。 Creates and waits for the client. 创建并等待客户端。
S2. S2。 When the client is connected, it reads the message. 连接客户端后,它将读取消息。
S21. S21。 Because message doesn't fit into the buffer(ERROR_MORE_DATA), it is read part by part. 由于消息不适合缓冲区(ERROR_MORE_DATA),因此将逐部分读取消息。

It seems to me that there is no way to tell when is the whole message, as an isolated unit, canceled. 在我看来,没有办法确定何时将整个消息作为一个孤立的单元取消。 In particular, if client cancels the send operation, server does not receive the whole message, just a part of it, and consequent read operation returns with ERROR_IO_PENDING (in my case), which means there is no data to be read and read operation has been queued. 特别是,如果客户端取消了发送操作,则服务器不会接收到整个消息,而只是部分接收消息,随后的读取操作将返回ERROR_IO_PENDING(在我的情况下),这意味着没有要读取的数据,读取操作具有被排队。 I would expect to have some kind of means telling the reader that the message has been canceled, so that reader can act upon it. 我希望可以通过某种方式告诉读者该消息已被取消,以便读者可以对其采取行动。

However, relevant documentation is scatter over MSDN, so I may as well be missing something. 但是,相关文档散布在MSDN上,因此我可能还缺少一些东西。 I would really appreciate if anyone can shed some light on it. 如果有人能对此有所启发,我将不胜感激。 Thanks. 谢谢。

You are correct, there is no way to tell. 您是正确的,没有办法说出来。

If you cancel the Writefile partway through, only part of the message will be written, so only that part will be read by the server. 如果您在途中取消了Writefile,则只会写入部分消息,因此服务器只会读取该部分。 There is no "bookkeeping" information sent about how large the message was going to be before you cancelled it - what is sent is just the raw data. 在取消消息之前,没有发送有关该消息的大小的“簿记”信息-发送的只是原始数据。

So the answer is: Don't cancel the IO, just wait for it to succeed. 因此答案是:不要取消IO,只需等待它成功即可。

If you do need to cancel IO partway through, you should probably cut the connection and start again from the beginning, just as you would for a network outage. 如果确实需要中途取消IO,则可能应该断开连接并从头开始重新启动,就像发生网络中断一样。

(You could check your OVERLAPPED structure to find out how much was actually written, and carry on from there, but if you wanted to do that you would probably just not cancel the IO in the first place.) (您可以检查OVERLAPPED结构,以了解实际写入了多少内容,然后从那里继续进行,但是如果要这样做,则可能一开始就不会取消IO。)

Why did you want to cancel the IO anyway? 您为什么仍要取消IO? What set of circumstances triggers this requirement? 哪些情况触发了此要求?

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

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