WSAOVERLAPPED l_overLappedNW;
ZeroMemory(&l_overLappedNW, sizeof(l_overLappedNW));
WSAEVENT l_pEvents[5];
WSAEVENT l_hReadEvent = WSA_INVALID_EVENT;
l_hReadEvent = WSACreateEvent();
WSAEventSelect(l_this->m_socket, l_hReadEvent, FD_READ);
l_pEvents[2] = l_hReadEvent;
l_overLappedNW.hEvent = l_pEvents[2];
char l_buf[501];
l_buf[500] = 0;
l_WSAbuf.buf = l_buf;
l_WSAbuf.len = 500;
DWORD l_flags = 0;
WSARecvFrom(l_this->m_socket, &l_WSAbuf, 1, &l_bytesRecvd, &l_flags,
&l_addr, &l_adrSize, &l_overLappedNW, NULL);
l_status = WSAWaitForMultipleEvents(5, l_pEvents, FALSE, l_timeOut, FALSE);
if (l_status == WSA_WAIT_EVENT_0 + 2) //Data read from diver unit
const int l_len = l_bytesRecvd / sizeof(char);
char* l_tmpBuf = new char[l_len + 1];
l_tmpBuf[l_len] = 0;
strncpy(l_tmpBuf, l_WSAbuf.buf, l_len);
This is included in one out of three subthreads that the main thread holds.
Only this thread reads from the socket. So, how can it happen that
WSARecvFrom above enters 3435973836 bytes received? I don't make any sense
out of this. Anyone?
Just a clue, 3435973836 = 0xCCCCCCCC. My first guess would be that the value
has not been set. I tend not to use the WSA socket functions so I can't
immediately see what's wrong with your code.
Dave.
"Dave Lowther" <da...@snsys.com> wrote in message
news:uEVCzWI...@TK2MSFTNGP10.phx.gbl...
The lpNumberOfBytesRecvd parameter in WSARecvFrom will be updated only if
the WSARecvFrom call succeeds inline, i.e. return 0. This is documented in
MSDN. You are issuing the WSARecvFrom call with an overlapped parameter,
hence it may fail with SOCKET_ERROR and WSAGetLastError may return
WSA_IO_PENDING, which means that the operation did NOT complete inline. When
an outstanding overlapped operation is eventually completed, you can get the
number of bytes transferred via the WSAGetOverlappedResult call. I hope this
solves your problem.
--Osman
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Arkady Frenkel" <ark...@hotmailxdotx.com> wrote in message
news:%23oVVnhK...@TK2MSFTNGP09.phx.gbl...