peakzhang 发表于 2007-12-28 23:33:23

ACE_Connector重连出错

ACE_Connector<BillingHandler, ACE_SOCK_CONNECTOR> m_Connector;重连部分代码:

BillingHandler* pHandler = this;
nRet = m_Connector.connect(pHandler, m_SvrAddr, ACE_Synch_Options::asynch);
if(nRet==-1)
{
    int nErrno = errno;
    if(nErrno != EWOULDBLOCK)
    //nErrno总是返回10038
    ...........
}
连接关闭的处理:
int BillingHandler::handle_close(ACE_HANDLE, ACE_Reactor_Mask)
{
ACE_Reactor::instance()->remove_handler(this, ACE_Event_Handler::ALL_EVENTS_MASK|ACE_Event_Handler::DONT_CALL);
if(get_handle() != ACE_INVALID_HANDLE)
{
    m_Peer.close();
    m_Connector.cancel(this);
}
...
}
连接完成时的处理:

int BillingHandler::open(void*)
{
m_Peer = peer();
if(m_Peer.enable(ACE_NONBLOCK) == -1)
{
    ACE_ERROR_RETURN((LM_ERROR, "(%t) %p\n", "enable"), -1);
}

if(ACE_Reactor::instance()->->register_handler(this, ACE_Event_Handler::READ_MASK) == -1)
{
    ACE_ERROR_RETURN((LM_ERROR,"(%t) %p\n","register_handler"), -1);
}
    return 0;
}

重连时nErrno总是返回10038, 问题出在哪里呢?或者handle_close处理不当?

peakzhang 发表于 2007-12-28 23:33:38

10038—WSAENOTSOCK
Socket operation on an invalid socket. This error can be returned from any Winsock function that takes a SOCKET handle as a parameter. This error indicates that the supplied socket handle is not valid.

你的代码返回这个错误,说明socket已经被关闭了,你后续的所有socket操作,都是无效的。
解决办法也简单,你delete这个handler,然后通过重新连接,重新建立一个就成了。
页: [1]
查看完整版本: ACE_Connector重连出错