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

  注: 在使用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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章