Subject: | Add the timeout setting for curl transport to avoid infinite wait of the RPC call in some corner cases |
Date: | Wed, 6 Nov 2013 02:37:39 +0000 |
To: | "bug-RPC-Xmlrpc_c [...] rt.cpan.org" <bug-RPC-Xmlrpc_c [...] rt.cpan.org> |
From: | 蒋凯 <jiangkai [...] 360.cn> |
Hi,
In a few machines in our environment, the RPC call gets into the infinite wait because some of the RPC response packets are lost due to the networking. It could be simulated by using some tools such as ptcproxy to delay or drop the packets from the server. We want a timeout setting to the rpc calls so the program could continue working in this case, but the module seems not support the setting, although it is supported by the xmlrpc c library( through the code: curl_easy_setopt(curlSessionP, CURLOPT_TIMEOUT, (long)timeoutMs) ).
We modified the Curl.c in the module. Below is the patch we applied to support the timeout setting( the patch file is attached ), we tested and it works fine. Could someone please review the codes, and if OK, submit the codes into the trunk?
--- original/RPC-Xmlrpc_c/Client/Curl/Curl.c 2013-08-13 23:40:14.000000000 +0800
+++ RPC-Xmlrpc_c/Client/Curl/Curl.c 2013-11-05 19:03:43.000000000 +0800
@@ -176,7 +176,27 @@
*valueP = XMLRPC_SSLVERSION_DEFAULT;
}
-
+static void
+fetchHvTimeout(HV * const hashP,
+ const char * const key,
+ unsigned int * const timeoutP) {
+/*----------------------------------------------------------------------------
+ Get the value of the timeout in milliseconds. This could be used for curl
+ CURLOPT_TIMEOUT option to avoid infinite wait in some corner cases.
+ If no timeout specified, set the value to 0, which mean no timeout
+-----------------------------------------------------------------------------*/
+ SV ** const valueSvPP = hv_fetch(hashP, key, strlen(key), 0);
+
+ if (valueSvPP == NULL)
+ *timeoutP = 0;
+ else{
+ SV * const valueSvP = *valueSvPP;
+
+ assert(valueSvP);
+
+ *timeoutP = SvUV(valueSvP);
+ }
+}
static void
makeXportParms(SV * const xportParmsR,
@@ -231,8 +251,10 @@
&xportParmsP->egdsocket);
fetchHvString(inHashP, "ssl_cipher_list",
&xportParmsP->ssl_cipher_list);
+ fetchHvTimeout(inHashP, "timeout",
+ &xportParmsP->timeout);
- *parmSizeP = XMLRPC_CXPSIZE(ssl_cipher_list);
+ *parmSizeP = XMLRPC_CXPSIZE(timeout);
*errorP = NULL;
}
Thanks.
Kai
Message body is not shown because sender requested not to inline it.