gpt4 book ai didi

c++ - 我如何(优雅地)终止 gSOAP 服务器?

转载 作者:太空宇宙 更新时间:2023-11-04 12:51:03 25 4
gpt4 key购买 nike

我有从 WSDL 文件 + Qt GUI 生成的 gSOAP 服务器。生成的代码工作得很好,除了一点导致我的进程在 GUI 退出后保持事件状态。 (我在 Windows 上部署,所以我没有信号)

我需要我的 GUI(自然地)保持事件状态,所以我将服务器代理对象移动到一个基于 QObject 的类,后者被移动到另一个 QThread,并且我通过外部信号启动它。服务器现在在其父 QObject 的事件循环上运行并且工作正常。

唯一的问题是我不知道如何在退出时终止服务器。我尝试为服务器调整生成的代码(顺便说一句,这真的是个好主意吗?)

int MySweetService::run(int port)
{ if (!soap_valid_socket(this->soap->master) && !soap_valid_socket(this->bind(NULL, port, 100)))
return this->soap->error;
for (;;) // =====> Maybe here I can put my while(module_is_running_atomic_bool) ?
{ if (!soap_valid_socket(this->accept()))
{ if (this->soap->errnum == 0) // timeout?
this->soap->error = SOAP_OK;
break;
}
if (this->serve())
break;
this->destroy();
}
return this->soap->error;
}

最佳答案

从另一个线程调用 soap_done(&soap) 会终止对 accept() 和下一个“服务”线程的阻塞调用。它适用于 Windows,但不适用于 Linux - 看起来 gsoap 有一些多任务处理问题。您还需要一些 bool 标志让“服务”线程知道您关闭了它,这不仅仅是 gsope 中的错误。

关于c++ - 我如何(优雅地)终止 gSOAP 服务器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49057117/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com