C++ 中的 Gsoap 错误

发布于 2024-07-04 19:45:58 字数 1166 浏览 6 评论 0原文

我正在使用 gsoap 在 C++ 中创建一个肥皂服务器。 消息通过用 Java 编写的总线进行路由。 服务器和总线都是多线程的。 一切正常,通过系统一次发送一条消息。 如果我启动 3 个客户端,每个客户端都尽可能快地发送消息,对于大约 3500 条消息来说一切都很好。 然后我开始定期收到“一次只允许一个套接字连接”。 gsoap 代码中的错误。 通常,4000 条消息中大约有 3950 条能够顺利通过。 所有 50 次失败都发生在最近 500 次发送中。

  1. 为什么这些错误会在多次发送后出现,而不是在发送开始时出现? 发送速率没有增加。

  2. 它在说什么? 我找不到该错误的任何解释,并且我不清楚它的含义。

  3. 有人成功地对 gsoap 应用程序进行了多线程处理吗?

这是我的服务器代码。

long WINAPI threadGO(soap *x);

int main(int argc, char* argv[])
{
HANDLE thread1;
int m, s; /* master and slave sockets */
struct soap *soap = soap_new();
if (argc < 2)
soap_serve(soap); /* serve as CGI application */
else
{ 
  m = soap_bind(soap, NULL, atoi(argv[1]), 100); 
  if (m < 0)
  { 
      soap_print_fault(soap, stderr);
      exit(-1);
  }
  fprintf(stderr, "Socket connection successful: master socket = %d\n", m);
  for (;;)
  {
     s = soap_accept(soap);
     thread1 =    CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)threadGO,soap_copy(soap),0,NULL);
  }
}
soap_done(soap);
free(soap);
return 0;
}

long WINAPI threadGO(soap *x)
{
soap_serve(x);
soap_end(x);
return 0

;
}

I am using gsoap to create a soap server in C++. Messages are routed through a bus written in Java. Both the server and the bus are multithreaded. Everything works well sending one message at a time through the system. If I start 3 clients each sending messages as fast as possible everything is fine for about 3500 messages. Then I begin receiving periodic "Only one socket connection allowed at a time." errors from the gsoap code. Typical about 3950 of 4000 messages make it through OK. With all 50 failures happening in the last 500 sends.

  1. Why would these errors occur after many sends, but not at the beginning of the sending? The rate of send does not increase.

  2. What is it talking about? I cannot find any explanation of the error, and its meaning is not clear to me.

  3. Anyone successfully multithreaded a gsoap app?

Here is my server code.

long WINAPI threadGO(soap *x);

int main(int argc, char* argv[])
{
HANDLE thread1;
int m, s; /* master and slave sockets */
struct soap *soap = soap_new();
if (argc < 2)
soap_serve(soap); /* serve as CGI application */
else
{ 
  m = soap_bind(soap, NULL, atoi(argv[1]), 100); 
  if (m < 0)
  { 
      soap_print_fault(soap, stderr);
      exit(-1);
  }
  fprintf(stderr, "Socket connection successful: master socket = %d\n", m);
  for (;;)
  {
     s = soap_accept(soap);
     thread1 =    CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)threadGO,soap_copy(soap),0,NULL);
  }
}
soap_done(soap);
free(soap);
return 0;
}

long WINAPI threadGO(soap *x)
{
soap_serve(x);
soap_end(x);
return 0

;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

黎夕旧梦 2024-07-11 19:45:58

我相信您在 threadGO 中遇到了资源泄漏。

使用 soap_copy() 复制肥皂结构后,我相信需要通过调用以下所有内容来释放它:

soap_destroy(x);
soap_end(x);
soap_free(x);

具体来说,缺少对 soap_done() 的调用(从soap_free()) 调用 soap_closesock(),这将关闭套接字。

I believe you've got a resource leak in threadGO.

After copying the soap struct with soap_copy(), I believe it needs to be freed by calling all of:

soap_destroy(x);
soap_end(x);
soap_free(x);

Specifically, the missing call to soap_done() (which is called from soap_free()) calls soap_closesock(), which closes the socket.

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