_sergey_001

Hi all.
I create TCP socket(client side)
I am developing client side and using model WSAEventSelect with event notification.
i develop 2 classes first for socket operation(CSocket) and the second for sockets threading model.
about problem.

at first i create socket,connect and sent data to server in this part everithing is good. the server in my send that i send send me a data which i must recive.
but when i start my thread for reciving data from server my worker threag where i realize WSAWaitForMultipleEvents is hover and i never get NetworkEvents for recive data.
this is two my function from class SocketThread and 2 function(send and recive) form socket class

how solve this hover in WSAWaitForMultipleEvents
thanks



DWORD CSocketThread::ThreadProc(LPVOID pVoid)
{
CSocketThread &this_ = *(CSocketThread*)pVoid;
DWORD error = 0;
WSANETWORKEVENTS NetworkEvents;
memset(&NetworkEvents, 0, sizeof(NetworkEvents));

while(1)
{
DWORD dw_Index = WSAWaitForMultipleEvents(this_.m_EventTotal,this_.m_Event,FALSE,WSA_INFINITE,FALSE);//hover
//DWORD dw_Index = WSAWaitForMultipleEvents(this_.m_EventTotal,this_.m_Event,FALSE,NULL,FALSE);
error = WSAGetLastError();
//for(...........)
this_.m_nLastError = WSAGetLastError();
if(dw_Index == SOCKET_ERROR)
{
this_.m_nLastError = WSAGetLastError();
}

WSANETWORKEVENTS NetworkEvents;
//NetworkEvents.lNetworkEvents = FD_READ;

if(SOCKET_ERROR == WSAEnumNetworkEvents(this_.m_Socket[dw_Index - WSA_WAIT_EVENT_0],
this_.m_Event[dw_Index - WSA_WAIT_EVENT_0],&NetworkEvents))
{

if(NetworkEvents.lNetworkEvents & FD_CONNECT)
{
obsocket.Connect(SERVERADDR,PORT);
}
if(NetworkEvents.lNetworkEvents & FD_READ)
{
obsocket.OnRecive(this_.m_pSocket->m_hsocket);
}
if(NetworkEvents.lNetworkEvents & FD_WRITE)
{
obsocket.OnSend(opacket);
}

}

WSAResetEvent(this_.m_Event[dw_Index - WSA_WAIT_EVENT_0]);
}

}

bool CSocketThread:tartThread(CSocket *pSocket)
{

m_pSocket = pSocket;
m_Event[m_EventTotal] = WSACreateEvent();
++m_EventTotal;

//recvOv.hEvent = m_Event[m_EventTotal];

WSAEventSelect(m_pSocket->m_hsocket, m_Event,FD_READ|FD_WRITE);
m_ThreadHandle = CreateThread(NULL, 0, &ThreadProc, (LPVOID)this, 0, &m_threadID);

if(!m_ThreadHandle)
{
m_pSocket == NULL;
return false;
}
else
return m_threadID;


return false;
}

///////////////////////////////////
int CSocket:nRecive(SOCKET m_hsocket)
{


WSABUF recv_buf;
char recvBuffer[RECV_MAX];
DWORD NumberOfDataREcived = 0;

DWORD dwFlag = 0;

recv_buf.buf = recvBuffer;
recv_buf.len = RECV_MAX;



int LastError = 0;
//if(INVALID_SOCKET == WSARecv(m_hsocket,&recv_buf,1,&NumberOfDataREcived,&dwFlag,lpOverlapped,NULL))
if(INVALID_SOCKET == WSARecv(m_hsocket,&recv_buf,1,&NumberOfDataREcived,&dwFlag,&recvOv,NULL))
{
LastError = ::WSAGetLastError();
return LastError;
}
return 0;


}

int CSocket:nSend(PACKET &paket)
{

WSABUF buffer;
int nLastError;
buffer.buf = paket.pBuffer;
buffer.len = strlen(paket.pBuffer);
DWORD dwNumberOfBytesSent,dwFlag = 0;




LPWSAOVERLAPPED lpOverlapped;

sendOv = paket.overlapped;
if(!buffer.len || !sendOv.hEvent)
return WSA_INVALID_PARAMETER;
if(WSASend(m_hsocket,&buffer,1,&dwNumberOfBytesSent,dwFlag,&sendOv,NULL))
//if(WSASend(m_hsocket,&buffer,1,&dwNumberOfBytesSent,dwFlag,lpOverlapped,NULL))
{
nLastError = WSAGetLastError();
return nLastError;
}
return 0;
}