gSOAP **不**关闭套接字?
我有一个 gSoap 问题 - 它没有关闭套接字。情况如下:应用程序工作正常,但是当我调用“重新加载”函数时,它无法重新连接。这是一段代码:
soap_destroy( &m_soapObj );
soap_end( &m_soapObj );
soap_done(&m_soapObj);
sleep(1);
soap_init(&m_soapObj);
//m_ptrThis should be initialized already
assert( m_ptrThis != NULL );
m_soapObj.user = &m_ptrThis;
m_soapObj.accept_timeout = nAcceptTimeout;
m_ptrThreadPool->SetNumThreads( nNumThreads );
m_nSocketListener = soap_bind(&m_soapObj, NULL, nPort, nBacklog);
if (!soap_valid_socket(m_nSocketListener))
{
throw Exception(
"Cannot start listening on port: %d", nPort );
}
它抛出..当我尝试使用soap_free时,程序崩溃,因为我没有创建新的Soap对象,只是再次初始化它。所以,soap_done 应该可以工作。有趣的是,这并不是每次都会发生。
这很奇怪..而且很紧急:/
提前非常感谢
编辑问题已解决。非常感谢鸭子!
I've an issue with gSoap - it's not closing the socket.. Here's the situation: the application is working fine, but when I call "reload" function, it cannot reconnect.. Here's a piece of code:
soap_destroy( &m_soapObj );
soap_end( &m_soapObj );
soap_done(&m_soapObj);
sleep(1);
soap_init(&m_soapObj);
//m_ptrThis should be initialized already
assert( m_ptrThis != NULL );
m_soapObj.user = &m_ptrThis;
m_soapObj.accept_timeout = nAcceptTimeout;
m_ptrThreadPool->SetNumThreads( nNumThreads );
m_nSocketListener = soap_bind(&m_soapObj, NULL, nPort, nBacklog);
if (!soap_valid_socket(m_nSocketListener))
{
throw Exception(
"Cannot start listening on port: %d", nPort );
}
and it throws.. When I try to use soap_free, the program crashes, as I don't create new Soap object, just initialize it again. SO, soap_done should work. And the interesting thing is, that this does not happen every time.
It's very strange.. and urgent :/
Thanks a lot in advance
EDIT The problem is solved. Many thanks to Duck!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该准确找出抛出的错误。
您可能会从bind() 收到“地址已在使用中”错误。您可以尝试使用setsockopt() 或等效的soap 调用以及SO_REUSEADDR 选项来纠正此问题。
此链接提供了简洁的解释。
You should find out exactly what error is being thrown.
It is possible you are getting an "Address Already in Use" error from bind(). You can try to correct for this by using setsockopt() - or the equivalent soap call - with the SO_REUSEADDR option.
This link provides a concise explanation.