I am trying to read data from an HTTP server asynchronously, and trying to respond to FD_READ notifications properly. I made code to respond by doing WSAIoctl + FIONREAD to determine the data left in the buffer, and then allocated memory for it, and read from the buffer. Here is my code in response to an FD_READ
Code:
DWORD bytesOutput;
DWORD bytesRecvd;
DWORD flags;
WSABUF wsaBuffer;
int ret;
char * buf;
unsigned long toBeRead;
ret = ::WSAIoctl
(wParam, FIONREAD, 0, 0, &toBeRead,
sizeof toBeRead, &bytesOutput, 0, 0);
if(ret != SOCKET_ERROR && bytesOutput == sizeof toBeRead)
{
wsaBuffer.buf = new char[toBeRead + 1];
wsaBuffer.len = toBeRead;
ret = ::WSARecv
(wParam, &wsaBuffer, 1, &bytesRecvd, &flags, 0, 0);
if(ret == SOCKET_ERROR)
{
ErrorMessage
(_T("WSARecv: %d"), ::WSAGetLastError());
}
wsaBuffer.buf[bytesRecvd] = 0;
}
The first FD_READ notifications results in WSARecv failing with error 10045 - Operation not supported
Originally Posted by
MSDN
The attempted operation is not supported for the type of object referenced. Usually this occurs when a socket descriptor to a socket that cannot support this operation is trying to accept a connection on a datagram socket
In addition, I get an exception (don't know if it matters)
First-chance exception at 0x00401407 in Dialog Testing - Modal + Icon.exe: 0xC0000005: Access violation writing location 0x00dfee60.
Unhandled exception at 0x00401407 in Dialog Testing - Modal + Icon.exe: 0xC0000005: Access violation writing location 0x00dfee60.