-1

I have met a problem when I use IOCP in x64 platform.

When I compile my code in win32 platform, it runs well. But when I change it to x64 platform, function

GetQueuedCompletionStatus(CompletionPort, &BytesTransferred,(PULONG_PTR)&PerHandleData, (LPOVERLAPPED*)&IpOverlapped, INFINITE)

returnes true without pass the value to PerHandleData.

PerHandleData is defined as:

typedef struct
{
SOCKET socket;
SOCKADDR_STORAGE ClientAddr;
}PER_HANDLE_DATA,*LPPER_HANDLE_DATA;
LPPER_HANDLE_DATA PerHandleData;

That means, even if there seems no error with the function GetQueuedCompletionStatus() , struct PerHandleData can not read memory: socket can not read memory and so does ClientAddr. There is no values.

So when it runs to function WSARecv(PerHandleData->socket, &(PerIoData->databuff), 1, &RecvBytes, &Flags, &(PerIoData->overlapped), NULL); the application will stop for memory errors.

Who can tell me how to deal with it?

hoestelan
  • 43
  • 4

2 Answers2

1

I just encounter the same problem, and the problem is when in 32 bit, I just cast the completion key to DWORD and pass it to the CreateIoCompletionPort call. In 64 bit application, it can still build, just a compiler warning. Change code and cast to ULONG_PTR will fix the problem. The compler warning just tells the reason: data truncated. When the point address is bigger than 32 bit, GetQueuedCompletionStatus will get the truncated address, just 32bit.

チーズパン
  • 2,752
  • 8
  • 42
  • 63
bob dawson
  • 91
  • 5
0

The documentation of CreateIoCompletionPort tells us where the key comes from; before using it with GetQueuedCompletionStatus you need to pass the key to CreateIoCompletionPort.

The documentation of CreateIoCompletionPort also states that the key should be unique per file handle. (Not just per file).

So, as we don't have the actual code, these two requirements are the main suspects. One particular challenge might be the level of indirection on the completion key. You pass the key to CreateIoCompletionPort and you pass a pointer to the key to GetQueuedCompletionStatus (so it will put the key at pointed-to location - it's an OUT argument). And that key might be a pointer itself.

MSalters
  • 173,980
  • 10
  • 155
  • 350