Microsoft KB Archive/253945

From BetaArchive Wiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
Knowledge Base


BUG: CCeSocket OnReceive() does not get called for accepted data sockets

Article ID: 253945

Article Last Modified on 4/30/2004



APPLIES TO

  • Microsoft Windows CE 2.12 for the Handheld PC
  • Microsoft Windows CE 2.11 for the Handheld PC
  • Microsoft Windows CE 2.0 for the Handheld PC
  • Microsoft Windows CE 1.0
  • Microsoft Windows CE 3.0 for the Handheld PC



This article was previously published under Q253945

SYMPTOMS

If you use the CCeSocket Microsoft Foundation Class (MFC) class to build a Transfer Control Protocol (TCP) server application, your override of the CCeSocket::OnReceive function is not called when data is received for the connection that you have accepted in your override of the CCeSocket::OnAccept function.

CAUSE

The problem is that the CCeSocketDataThread thread function does not check for incoming data if the private m_bConnectedCalled member variable of CCeSocket is not set. The problem does not occur in client applications that just use data sockets. In this case, the application calls the Connect member function to connect to a remote socket. Connect in turn calls the ConnectHelper function. The override of ConnectHelper in CCeSocket does set m_bConnectedCalled to TRUE and therefore DataThread does check for incoming data and CCeSocket::OnReceive does get called.

In case you build a server application, you do create a listen socket and the actual data socket is returned when you call Accept in your override of CCeSocket::OnAccept. However there is no override for Accept in CCeSocket and m_bConnectedCalled does not get set for the returned socket. The result is that DataThread does not check for incoming data and CCeSocket::OnReceive will never get called for this socket.

RESOLUTION

To work around this problem, in your override of CCeSocket::OnAccept, you can set the m_bConnectCalled member variable of the CCeSocket object to TRUE after it is returned by Accept.

The problem with this method is that m_bConnectCalled is declared as private and you do not have access to it in your code. To get the required access, you must modify the Wcesock.h SDK header file so that m_bConnectedCalled is declared as public before compiling your application. To do this, in Wcesock.h, insert a new line with just the "public:" statement on it before the "BOOL m_bConnectCalled;" line. Please make a backup copy of Wcesock.h before you modify it, and take care that you do not change anything else within the header file. Just changing the declaration does not change the memory layout of the class, and therefore your application will work properly with the MFC run-time dynamic-link library (DLL).

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.


Additional query words: ccesocket mfc chatsrv onreceive

Keywords: kbbug kbwinsock kbapi kbnetwork kbpending KB253945