some IOCP questions

Started by
16 comments, last by hplus0603 16 years, 1 month ago
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]
http://www.daily-it.com
Advertisement
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.
enum Bool { True, False, FileNotFound };
What purpose has OVERLAPPED->hEvent? Does it tell me what action i should take?
http://www.daily-it.com
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.

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:

}
http://www.daily-it.com
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) {}

enum Bool { True, False, FileNotFound };
Yes that i understand but i dont get how it goes to READ case, there op_code should be set automatically.
http://www.daily-it.com
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.
http://www.daily-it.com
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.
What causes such Thing. I send with client 10 packets in row with message "Hello", when server recv-s them it shows 1. HelloHelloHello 2. HelloHello. Basicly it glues them togheter.
http://www.daily-it.com

This topic is closed to new replies.

Advertisement