Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

WSARecvFrom returns 3435973836 bytes received

161 views
Skip to first unread message

aaa

unread,
Oct 13, 2005, 3:54:05 PM10/13/05
to
How can that happen? My code looks something like below. I have left out some
if statements and error tests

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?

aaa

unread,
Oct 13, 2005, 4:30:03 PM10/13/05
to
Most of the times I debug and put a breakpoint just before the WSARecvFrom
statement it seems to read right number of bytes though.

aaa

unread,
Oct 13, 2005, 4:51:06 PM10/13/05
to
I would say it works all of the times when I have the breakpoint. Also, when
I have reached the breakpoint I remove it, let the program run and it works
reading continuously (the WSAWaitForMultipleEvents is inside a while loop).

aaa

unread,
Oct 13, 2005, 5:02:05 PM10/13/05
to
No,... now it seems like it works in the beginning but suddenly it can stop

aaa

unread,
Oct 14, 2005, 12:14:50 AM10/14/05
to
Hmm... If I log I always get this large read bytes number

Dave Lowther

unread,
Oct 14, 2005, 2:08:21 AM10/14/05
to
CCCCCCCC
"aaa" <a...@discussions.microsoft.com> wrote

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.


Arkady Frenkel

unread,
Oct 14, 2005, 6:17:03 AM10/14/05
to
As Dave hint , that debug mode and i you'll change it you'll receive
something different.
Additionally , check the result of WSARecvFrom()
Arkady

"Dave Lowther" <da...@snsys.com> wrote in message
news:uEVCzWI...@TK2MSFTNGP10.phx.gbl...

Osman Ertugay [MSFT]

unread,
Nov 21, 2005, 5:39:41 PM11/21/05
to
Hello Aaa,

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...

0 new messages