CCeSocket的bug(zz自msdn新闻组)

 

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

<script type="text/javascript">function loadTOCNode(){}</script>
Article ID:253945
Last Review:April 30, 2004
Revision:2.1
This article was previously published under Q253945

SYMPTOMS

<script type="text/javascript">loadTOCNode(1, 'symptoms');</script>
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

<script type="text/javascript">loadTOCNode(1, 'cause');</script>
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

<script type="text/javascript">loadTOCNode(1, 'resolution');</script>
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

<script type="text/javascript">loadTOCNode(1, 'status');</script>
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值