您的位置:首页 > 其它

[gsoap] SIGPIPE (Broken pipe) in client/standalone server

2008-12-03 14:55 357 查看
注: 在使用Gsoap时,避免使用函数重载,否则会出现一些意想不到的问题.

Whenever you use keep-alive support, a signal handler is required on Unix/Linux systems. In general, a SIGPIPE signal handler will prevent your application from terminating in case of a dropped connection. You can use a SIGPIPE handler or use the soap.socket_flags = MSG_NOSIGNAL or soap.connect_flags = SO_NOSIGPIPE (client-side) or soap.accept_flags = SO_NOSIGPIPE. These settings are not portable. Some Unix systems support MSG_NOSIGNAL while others support SO_NOSIGPIPE.

Keep-alive support has other VERY IMPORTANT effects on your service application when you deploy it in the "real world". You must use multi-threading, otherwise a long keep-alive session with a client will block the service from serving other clients. You should also set soap.recv_timeout and soap.send_timeout values, otherwise a client application can keep one thread busy indefinitely (however, it appears that OpenSSL does not support non-blocking sockets, so OpenSSL may not work in that case. I am working on a fix). Finally, the number of requests served per keep-alive connection is limited to 100 (SOAP_MAXKEEPALIVE in stdsoap2.h, compile with -DSOAP_MAXKEEPALIVE=X to change this).Web servers use counters to limit the number of calls so that threads will eventually be released to avoid clients from holding a thread indefinitely. This means that sessions that exceed 100 calls will be closed by the gSOAP service. This is the cause of your SIGPIPE.

Remember that your application should never rely on keep-alive to implement stateful sessions. A client or service can always close a keep-alive connection at any time or even not support it. You should use cookies or SOAP headers to implement transaction control for stateful sessions. An example is implemented in the factory client and service in the package. SOAP headers are used to exchange object handles.

for example:

soap.socket_flags = MSG_NOSIGNAL; // in linux

soap.accept_flags = NOSIGPIPE; // other OS
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: