gSOAP **不**关闭套接字?

发布于 2024-09-26 15:51:23 字数 804 浏览 5 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅浅 2024-10-03 15:51:23

您应该准确找出抛出的错误。

您可能会从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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文