C++ 中的 Gsoap 错误
我正在使用 gsoap 在 C++ 中创建一个肥皂服务器。 消息通过用 Java 编写的总线进行路由。 服务器和总线都是多线程的。 一切正常,通过系统一次发送一条消息。 如果我启动 3 个客户端,每个客户端都尽可能快地发送消息,对于大约 3500 条消息来说一切都很好。 然后我开始定期收到“一次只允许一个套接字连接”。 gsoap 代码中的错误。 通常,4000 条消息中大约有 3950 条能够顺利通过。 所有 50 次失败都发生在最近 500 次发送中。
为什么这些错误会在多次发送后出现,而不是在发送开始时出现? 发送速率没有增加。
它在说什么? 我找不到该错误的任何解释,并且我不清楚它的含义。
有人成功地对 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.
Why would these errors occur after many sends, but not at the beginning of the sending? The rate of send does not increase.
What is it talking about? I cannot find any explanation of the error, and its meaning is not clear to me.
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信您在 threadGO 中遇到了资源泄漏。
使用
soap_copy()
复制肥皂结构后,我相信需要通过调用以下所有内容来释放它:具体来说,缺少对
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:Specifically, the missing call to
soap_done()
(which is called fromsoap_free()
) callssoap_closesock()
, which closes the socket.