Is WSASend with IOCP ordered?

2019-08-05 06:12发布

问题:

I would like to create a IOCP application to received TCP data, Once received, I will have to processing the data and write out the bytes partially. Understand that WSASend with IOCP can do the job. But I am worrying whether WSASend to the queue and does GetQueuedCompletionStatus synchronizely?. For Example:-

void processing_from_other_thread(...) {
...
DWORD state = still_doing1;
WSASend( ..,..,.., &state, .. );

DWORD state = still_doing2;
WSASend( ..,..,.., &state, .. );

DWORD state = still_doing3;
WSASend( ..,..,.., &state, .. );

DWORD state = Done;
PostCompletionQueue(....);
}

From the context above, will GetQueuedCompletionStatus getting them orderly?

GetQueuedCompletionStatus();
return still_doing1
GetQueuedCompletionStatus();
return still_doing2
GetQueuedCompletionStatus();
return still_doing3
GetQueuedCompletionStatus();
return Done
Continue

I just want to make sure the future design is correctly, I am afraid they are not orderly, For example, Return still_doing2 completed before still_doing1. The data sent might affected to client side.

回答1:

Under IOCP I/O model, the application is responsible for organizing incoming and outgoing data. In other words, the process posts different I/O related messages to IOCP, but there is no guaranteed IOCP sends and/or receives data in that exact order.

This is a key part of asynchronous I/O.



标签: c iocp