some IOCP questions
Q1. How to determine if client is sending data or not?
Can i use there FD_READ? by creating Event?
Q2. How to send structure packet with IOCP?
[Edited by - TiitHns on February 9, 2008 3:16:59 PM]
You will know that the client has sent data that you have received when your IOCP thread receives a completion event for the queued read request.
You can send a structure just like any other data; pass a pointer to it and a size to the overlapped write request.
You can send a structure just like any other data; pass a pointer to it and a size to the overlapped write request.
I believe the hEvent is not used with IO Completion Ports.
MSDN says it is used to signal when the operation has completed. Since you are using IOCP, you have a different mechanism for that signal.
A trick to help you is to create your own structure or class that holds an OVERLAPPED structure as it's first member. This allows you to figure out what IO has completed.
Happy coding.
MSDN says it is used to signal when the operation has completed. Since you are using IOCP, you have a different mechanism for that signal.
A trick to help you is to create your own structure or class that holds an OVERLAPPED structure as it's first member. This allows you to figure out what IO has completed.
typedef struct tagIONotifyData{ OVERLAPPED structOverlapped; LPVOID pUserData;} IO_NOTIFY_DATA, *PIO_NOTIFY_DATA;
Happy coding.
Am i stupid or what i can understand everything else except the thing how they switch cases with operation type. I cant understand where they get operation type from socket.
BOOL bIORet = GetQueuedCompletionStatus(
hCompletionPort,
&dwIoSize,
(LPDWORD) &lpClientContext,
&lpOverlapped, INFINITE);
switch(smth->op_code){
case RECV:
case SEND:
}
BOOL bIORet = GetQueuedCompletionStatus(
hCompletionPort,
&dwIoSize,
(LPDWORD) &lpClientContext,
&lpOverlapped, INFINITE);
switch(smth->op_code){
case RECV:
case SEND:
}
Like LordShade said:
struct Something { OVERLAPPED overlapped; int op_code; HFILE socket; void *buffer; size_t size; ... whatever else ...};Something *foo = new Something;memset(foo, 0, sizeof(foo));foo->overlapped = ...;foo->op_code = WRITE;foo->socket = mySocket; // must have been opened with OVERLAPPED statusfoo->buffer = myBuffer;foo->size = mySize;WriteFile(foo->socket, foo->buffer, foo->size, 0, &foo->overlapped);DWORD clientContext;Something *something;GetQueuedCompletionStatus(hPort, &dwIoSize, &clientContext, (OVERLAPPED *)&something, INFINITE);switch (something->op_code) {}
Yes that i understand but i dont get how it goes to READ case, there op_code should be set automatically.
Pumped into another question. When sending messages with WSASend(), do i have to post data into IOCP first and then use WSASend. Or i can just use WSASend. Then that leaves for IOCP thread only read operation.
You just use WSASend(). It posts the overlapped IO request into a queue which is serviced by your thread.
And you'll know that it's a write rather than a read because you'll set the operation type to write in your derived OVERLAPPED struct if you need to.
And you'll know that it's a write rather than a read because you'll set the operation type to write in your derived OVERLAPPED struct if you need to.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement