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

WSAEventSelect, WSAEnumNetworkEvents, and repeatedly generated FD_CONNECT event...

196 views
Skip to first unread message

Stefan Rådström

unread,
Aug 27, 1998, 3:00:00 AM8/27/98
to
Hi all!

My problem is that when I already have a TCP connection (FD_ACCEPT on the
server side, FD_CONNECT on the client) the client continues to get
FD_CONNECT with a few seconds interval. Does anybody know what's going on
here.
Below is an excerpt from my code:

/*static*/ UINT CAsyncSocket2::EventThread(CAsyncSocket2* pThis)
{
CSingleLock lockEndThread(&pThis->m_eventEndThreads);

CArray<WSAEVENT, WSAEVENT> arrayEvents;
arrayEvents.SetSize(1);
arrayEvents[0] = pThis->m_hEvent;

WSANETWORKEVENTS Events = { 0 };
DWORD dwWaitResult = 0;

BOOL bRun = TRUE;
while (bRun)
{
if (lockEndThread.Lock(0))
{
bRun = FALSE;
}
else
{
switch (dwWaitResult =
::WSAWaitForMultipleEvents(arrayEvents.GetSize(), arrayEvents.GetData(),
FALSE, 100, FALSE))
{
[intentionally left out trivial code for other cases]

case WSA_WAIT_EVENT_0:
//TRACE("WSA_WAIT_EVENT_0\n");
::ZeroMemory(&Events, sizeof(WSANETWORKEVENTS));
if (0 == ::WSAEnumNetworkEvents(pThis->m_hSocket,
arrayEvents[0], &Events))
{
if (FD_CONNECT == (Events.lNetworkEvents & FD_CONNECT))
{
pThis->OnConnect(Events.iErrorCode[FD_CONNECT_BIT]); //
Keeps coming and coming and coming....
}

[intentionally left out trivial code for other events]
break;
[contd.]

Thanks for any enlightment in this annoying situation.

/Stefan

Claes Bergefall

unread,
Aug 28, 1998, 3:00:00 AM8/28/98
to
Did you create the event with WSACreateEvent?
If so, you need to reset it with WSAResetEvent
after you've handled it.

Claes Bergefall
cl...@prosolvia.se


Stefan Rådström skrev i meddelandet ...

Stefan Rådström

unread,
Aug 28, 1998, 3:00:00 AM8/28/98
to
Yes, I have created the event with WSACreateEvent. It isn't necessary to
call WSAResetEvent since WSAEnumNetworkEvents does that. Besides that I've
read that it is an internal record that keeps track of what network events
that should be set at any time. That is, FD_READ is re-enabled by recv,
recvfrom, WSARecv, or WSARecvFrom; FD_WRITE by the functions that send data,
etc. However, it seems that it don't exist any function that re-enables the
FD_CONNECT and FD_CLOSE network events. The solution I've come up with is to
have two BOOL variables to keep track of them, but since the information is
kept internally, it should have been some way of re-enabling the events
manually.

/Stefan

Claes Bergefall skrev i meddelandet ...


>Did you create the event with WSACreateEvent?
>If so, you need to reset it with WSAResetEvent
>after you've handled it.
>
>Claes Bergefall
>cl...@prosolvia.se
>
>
>Stefan Rådström skrev i meddelandet ...
>>Hi all!
>>
>>My problem is that when I already have a TCP connection (FD_ACCEPT on the
>>server side, FD_CONNECT on the client) the client continues to get
>>FD_CONNECT with a few seconds interval. Does anybody know what's going on
>>here.

[snip]

0 new messages