Click here to Skip to main content
16,005,339 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: General Question Pin
pankajdaga22-Aug-02 23:43
pankajdaga22-Aug-02 23:43 
GeneralQuestion about BeginPaint and EndPaint Pin
pankajdaga22-Aug-02 22:32
pankajdaga22-Aug-02 22:32 
GeneralRe: Question about BeginPaint and EndPaint Pin
Paul M Watt22-Aug-02 22:41
mentorPaul M Watt22-Aug-02 22:41 
GeneralRe: Question about BeginPaint and EndPaint Pin
Tomasz Sowinski22-Aug-02 22:42
Tomasz Sowinski22-Aug-02 22:42 
GeneralRe: Question about BeginPaint and EndPaint Pin
Paul M Watt22-Aug-02 22:52
mentorPaul M Watt22-Aug-02 22:52 
GeneralRe: Question about BeginPaint and EndPaint Pin
pankajdaga22-Aug-02 23:31
pankajdaga22-Aug-02 23:31 
GeneralCFlatTabCtrl Pin
alex.barylski22-Aug-02 21:57
alex.barylski22-Aug-02 21:57 
GeneralOverlapped sockets question Pin
Niko Tanghe22-Aug-02 21:50
Niko Tanghe22-Aug-02 21:50 
For a project we use overlapped sockets instead of CSocket (not thread-safe).

Everytime when a socket is accepted:
- the virtual function OnAccept is called, the socket is accepted
- A new thread is started
- new Events are created (m_hStopEvent, m_Read.hEvent, m_Write.hEvent, m_hEvent)
- The socket is 'attached' (see below for code)

but the events still arrive at the listening socket.
the WSAWaitForMultipleEvents goes off.
but WSAEnumNetworkEvents queries 0.

The implementation works fine for UDP (the same socket is used !)

Thanks in advance.

Greetings,

Niko

The code:
socket thread:
int CASyncSocket::SocketFunc()
{
WSAEVENT handles[]={
m_hStopEvent,
m_Read.hEvent,
m_Write.hEvent,
m_hEvent};
WSANETWORKEVENTS netEvents;
DWORD dwWaitResult;
DWORD dwTimeOut;

OnAttach();

for(;;)
{

if(m_ulTimeout == 0)
dwTimeOut = WSA_INFINITE;
else
dwTimeOut = m_ulTimeout;

dwWaitResult = WSAWaitForMultipleEvents(
sizeof(handles)/sizeof(WSAEVENT),
handles,
FALSE,
dwTimeOut,
TRUE);

if(dwWaitResult == WSA_WAIT_EVENT_0+3){
if(WSAEnumNetworkEvents(m_Socket, m_hEvent, &netEvents)!=SOCKET_ERROR)
{
if((netEvents.lNetworkEvents&FD_READ) == FD_READ)
{
_OnReceive(netEvents.iErrorCode[FD_READ_BIT]);
}
if((netEvents.lNetworkEvents&FD_WRITE) == FD_WRITE)
{
_OnSend(netEvents.iErrorCode[FD_WRITE_BIT]);
}
if((netEvents.lNetworkEvents&FD_CLOSE) == FD_CLOSE)
{
_OnClose(netEvents.iErrorCode[FD_CLOSE_BIT]);
}
if((netEvents.lNetworkEvents&FD_CONNECT) == FD_CONNECT)
{
_OnConnect(netEvents.iErrorCode[FD_CONNECT_BIT]);
}
if((netEvents.lNetworkEvents&FD_ACCEPT) == FD_ACCEPT)
{
_OnAccept(netEvents.iErrorCode[FD_ACCEPT_BIT]);
}
}
else
{
int iError = WSAGetLastError();
if(iError == WSANOTINITIALISED ||
iError == WSAENOTSOCK)
{
Close();
}
}
}
else if(dwWaitResult == WSA_WAIT_EVENT_0)
{
break;

}else if(dwWaitResult == WSA_WAIT_EVENT_0+1)
{
_OnReceiveComplete();

}else if(dwWaitResult == WSA_WAIT_EVENT_0+2)
{
_OnSendComplete();
}
else if(dwWaitResult == WSA_WAIT_FAILED)
{
break;

}
else if(dwWaitResult == WSA_WAIT_TIMEOUT)
{
_OnTimeout();
}
else
{
Close();
}
}

_OnClear();

if(bAutoDelete == true)
delete this;

return 0;
}

Accept function:

void CASyncSocket::Accept(CASyncSocket& SocketToAccept) const
{
ASSERT(SocketToAccept.m_Socket == INVALID_SOCKET);

SAcceptedSocket as;
int iLength=sizeof(sockaddr);

sockaddr sockaddress;
as.s = ::WSAAccept(m_Socket, &sockaddress, &iLength, NULL, 0);
as.addr = CIPAddress(sockaddress);

SocketToAccept.Attach(as.s,as.addr);
}

bool CASyncSocket::Attach(SOCKET s, const CIPAddress& Peername)
{
if(s!=INVALID_SOCKET){

Close();

m_Peername = Peername;

m_Socket = s;

if(Init() == true) // starts the thread
{
return true;
}
}

return false;
}
GeneralRe: Overlapped sockets question Pin
Moak23-Aug-02 3:14
Moak23-Aug-02 3:14 
QuestionWhere did my WM_COMMAND go? Pin
JennyP22-Aug-02 20:10
JennyP22-Aug-02 20:10 
AnswerRe: Where did my WM_COMMAND go? Pin
Tomasz Sowinski22-Aug-02 22:13
Tomasz Sowinski22-Aug-02 22:13 
GeneralRe: Where did my WM_COMMAND go? Pin
JennyP23-Aug-02 5:26
JennyP23-Aug-02 5:26 
GeneralRe: Where did my WM_COMMAND go? Pin
Tomasz Sowinski23-Aug-02 5:26
Tomasz Sowinski23-Aug-02 5:26 
GeneralRe: Where did my WM_COMMAND go? Pin
JennyP23-Aug-02 5:43
JennyP23-Aug-02 5:43 
GeneralRe: Where did my WM_COMMAND go? Pin
Tomasz Sowinski23-Aug-02 5:47
Tomasz Sowinski23-Aug-02 5:47 
QuestionCan I play MP3 from memory using DirectShow? Pin
sonshiro22-Aug-02 19:42
sonshiro22-Aug-02 19:42 
GeneralSlow metafiles on W2K Pin
Anonymous22-Aug-02 19:20
Anonymous22-Aug-02 19:20 
GeneralUpdating NT Log thru VC appl. Pin
abhinarulkar22-Aug-02 19:05
abhinarulkar22-Aug-02 19:05 
GeneralRe: Updating NT Log thru VC appl. Pin
Pavel Klocek22-Aug-02 22:42
Pavel Klocek22-Aug-02 22:42 
GeneralApplication Instance Pin
Prateeti22-Aug-02 18:57
Prateeti22-Aug-02 18:57 
GeneralRe: Application Instance Pin
Chris Losinger22-Aug-02 19:01
professionalChris Losinger22-Aug-02 19:01 
GeneralFirewall Pin
sunwareinc@yahoo.com22-Aug-02 18:20
susssunwareinc@yahoo.com22-Aug-02 18:20 
GeneralRe: Firewall Pin
Philip Fitzsimons22-Aug-02 23:05
Philip Fitzsimons22-Aug-02 23:05 
GeneralAn ADO question Pin
Anonymous22-Aug-02 18:22
Anonymous22-Aug-02 18:22 
GeneralRe: An ADO question Pin
Todd Smith22-Aug-02 18:43
Todd Smith22-Aug-02 18:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.