gsoap 超時(timeout)設置


參考:http://www.cs.fsu.edu/~engelen/soapdoc2.html#tth_sEc19.19

gsoap就不用介紹了,是一個c/c++編寫的可用於服務端與客戶端的連接工具。

Socket connect, accept, send, and receive timeout values can be set to manage socket communication timeouts. The soap.connect_timeoutsoap.accept_timeoutsoap.send_timeout, and soap.recv_timeout attributes of the current gSOAP runtime context soap can be set to the appropriate user-defined socket send, receive, and accept timeout values. A positive value measures the timeout in seconds. A negative timeout value measures the timeout in microseconds (10−6 sec).
 
The soap.connect_timeout specifies the timeout for soap_call_ns__method calls.
 
The soap.accept_timeout specifies the timeout for soap_accept(&soap) calls.
 
The soap.send_timeout and soap.recv_timeout specify the timeout for non-blocking socket I/O operations.
 
Example: 

struct soap soap; 
soap_init(&soap); 
soap.send_timeout = 10; 
soap.recv_timeout = 10;

This will result in a timeout if no data can be send in 10 seconds and no data is received within 10 seconds after initiating a send or receive operation over the socket. A value of zero disables timeout, for example: 

soap.send_timeout = 0; 
soap.recv_timeout = 0;

When a timeout occurs in send/receive operations, a SOAP_EOF exception will be raised ("end of file or no input"). Negative timeout values measure timeouts in microseconds, for example: 

#define uSec *-1 
#define mSec *-1000 
soap.accept_timeout = 10 uSec; 
soap.send_timeout = 20 mSec; 
soap.recv_timeout = 20 mSec;

The macros improve readability.
 
Caution: many Linux versions do not support non-blocking connect(). Therefore, setting soap.connect_timeout for non-blocking soap_call_ns__method calls may not work under Linux.
 
Caution: interrupts (EINTR) can affect the blocking time in I/O operations. The maximum number of EINTR that will not trigger an error is set by SOAP_MAXEINTR in stdsoap2.h, which is 10 by default. Each EINTR may increase the blocking time by up to one second, up to SOAP_MAXEINTR seconds total.

 

初始化gsoap后,然后就可以設置了。

在struct soap里面 是有很多參數的,具體可以參見  stdsoap2.h文件。。

只要

soap.send_timeout = 10; 
soap.recv_timeout = 10;

就可以。。

因為gsoap使用的包裝http協議。然后最主要的是socket傳輸,對於我們熟悉的socket傳輸,我們在非阻塞的情況下才能設置超時。(包括 連接超時 accetp_timeout, 發送超時 send_timeout, 以及接受超時 recv_timeout)。

轉自:https://www.cnblogs.com/hcu5555/p/3707190.html

 

1.修改gsoap自動生成的代碼才能進行超時設置(我這邊訪問web service的代碼都是gsoap工具自動生成.根據wsdl接口)

 2.找到生成的soapwwwsdlBindingProxy.cpp文件

 3.找到你要設置超時的那個調用服務器的方法

 4.找到該方法代碼   struct soap *soap = this;

      在該代碼下添加如下三行代碼(時間大小根據項目自行調整)
     soap->recv_timeout = 2;//接受  (單位是秒)
     soap->send_timeout = 2;//發送  (單位是秒)
     soap->connect_timeout = 2;//連接(單位是秒)

轉自:https://www.cnblogs.com/yishaochu/p/5078644.html

 

參考:https://www.cnblogs.com/liushui-sky/p/11889178.html

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM