Jump to content
  • Advertisement
Sign in to follow this  
TiitHns

some IOCP questions

This topic is 3822 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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:

}

Share this post


Link to post
Share on other sites
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 status
foo->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) {
}

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!