GetQueuedCompletionStatus blocks, though GetLastError which is called after AcceptEx returns ERROR_IO_PENDING [modified]
-
But the client can connect. some of the test codes server
void post_io_request_of_accept(SOCKET so_listen, PerIoData * per_io_data)
{
DWORD bytes_received;
BOOL ok = AcceptEx(so_listen,
per_io_data->so_local,
per_io_data->buf,
0,
sizeof(SOCKADDR_STORAGE)+16,
sizeof(SOCKADDR_STORAGE)+16,
&bytes_received,
per_io_data);
DWORD err = GetLastError();
if (ok)
{
assert(false);
}
else if (err==ERROR_IO_PENDING)
{
}
else
assert(false);
}DWORD WINAPI ServingThreadProc(LPVOID pParam)
{
DWORD bytes_tranfered;
ULONG_PTR completion_key;
PerIoData * per_io_data;while (true) { BOOL ok = GetQueuedCompletionStatus(HANDLE(pParam), &bytes\_tranfered, &completion\_key, (OVERLAPPED\*\*)&per\_io\_data, INFINITE); assert(ok); handle\_io\_completion(per\_io\_data); } return 0;
}
client
int main()
{
WSADATA wsa;
int res = WSAStartup(MAKEWORD(2,2), &wsa);
assert(res==0);SOCKADDR\_IN addr\_in; addr\_in.sin\_family = AF\_INET; addr\_in.sin\_addr.s\_addr = inet\_addr("127.0.0.1"); addr\_in.sin\_port = htons(5150); ZeroMemory(&addr\_in.sin\_zero, sizeof(addr\_in.sin\_zero)); SOCKET s = WSASocket(AF\_INET, SOCK\_STREAM, IPPROTO\_TCP, NULL, 0, 0); assert(s!=INVALID\_SOCKET); int ok = connect(s, (sockaddr\*)&addr\_in, sizeof(addr\_in)); assert(ok==0); for (int i=0; i<10; ++i) { char buf\[256\]; sprintf\_s(buf, sizeof(buf), "message %d", i); WSABUF wsa\_buf; wsa\_buf.buf = buf; wsa\_buf.len = strlen(buf); DWORD bytes\_sent; int res = WSASend(s, &wsa\_buf, 1, &bytes\_sent, 0, NULL, NULL); assert(res==0 && bytes\_sent==wsa\_buf.len); printf\_s("sent: %s\\n", buf); Sleep(1000); } WSACleanup(); return 0;
}
If use
PostQueuedCompletionStatus
, GetQueuedCompletionStatus will be unblocked. What is the problem? Thanks.modified on Friday, August 6, 2010 11:38 AM
-
But the client can connect. some of the test codes server
void post_io_request_of_accept(SOCKET so_listen, PerIoData * per_io_data)
{
DWORD bytes_received;
BOOL ok = AcceptEx(so_listen,
per_io_data->so_local,
per_io_data->buf,
0,
sizeof(SOCKADDR_STORAGE)+16,
sizeof(SOCKADDR_STORAGE)+16,
&bytes_received,
per_io_data);
DWORD err = GetLastError();
if (ok)
{
assert(false);
}
else if (err==ERROR_IO_PENDING)
{
}
else
assert(false);
}DWORD WINAPI ServingThreadProc(LPVOID pParam)
{
DWORD bytes_tranfered;
ULONG_PTR completion_key;
PerIoData * per_io_data;while (true) { BOOL ok = GetQueuedCompletionStatus(HANDLE(pParam), &bytes\_tranfered, &completion\_key, (OVERLAPPED\*\*)&per\_io\_data, INFINITE); assert(ok); handle\_io\_completion(per\_io\_data); } return 0;
}
client
int main()
{
WSADATA wsa;
int res = WSAStartup(MAKEWORD(2,2), &wsa);
assert(res==0);SOCKADDR\_IN addr\_in; addr\_in.sin\_family = AF\_INET; addr\_in.sin\_addr.s\_addr = inet\_addr("127.0.0.1"); addr\_in.sin\_port = htons(5150); ZeroMemory(&addr\_in.sin\_zero, sizeof(addr\_in.sin\_zero)); SOCKET s = WSASocket(AF\_INET, SOCK\_STREAM, IPPROTO\_TCP, NULL, 0, 0); assert(s!=INVALID\_SOCKET); int ok = connect(s, (sockaddr\*)&addr\_in, sizeof(addr\_in)); assert(ok==0); for (int i=0; i<10; ++i) { char buf\[256\]; sprintf\_s(buf, sizeof(buf), "message %d", i); WSABUF wsa\_buf; wsa\_buf.buf = buf; wsa\_buf.len = strlen(buf); DWORD bytes\_sent; int res = WSASend(s, &wsa\_buf, 1, &bytes\_sent, 0, NULL, NULL); assert(res==0 && bytes\_sent==wsa\_buf.len); printf\_s("sent: %s\\n", buf); Sleep(1000); } WSACleanup(); return 0;
}
If use
PostQueuedCompletionStatus
, GetQueuedCompletionStatus will be unblocked. What is the problem? Thanks.modified on Friday, August 6, 2010 11:38 AM
Perhaps you can use a IOCP networking class from CodeProject (or somewhere else) as a basis for your code? See if it helps: Internet & Network - Client/Server Development. :)