celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From abroekh...@apache.org
Subject svn commit: r1655949 - in /celix/trunk/remote_services: remote_service_admin/public/include/remote_proxy.h remote_service_admin_http/private/src/remote_service_admin_impl.c
Date Fri, 30 Jan 2015 07:31:40 GMT
Author: abroekhuis
Date: Fri Jan 30 07:31:40 2015
New Revision: 1655949

URL: http://svn.apache.org/r1655949
Log:
CELIX-211: Added code to be able to set the timeout for calls to an endpoint.

Modified:
    celix/trunk/remote_services/remote_service_admin/public/include/remote_proxy.h
    celix/trunk/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c

Modified: celix/trunk/remote_services/remote_service_admin/public/include/remote_proxy.h
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/remote_service_admin/public/include/remote_proxy.h?rev=1655949&r1=1655948&r2=1655949&view=diff
==============================================================================
--- celix/trunk/remote_services/remote_service_admin/public/include/remote_proxy.h (original)
+++ celix/trunk/remote_services/remote_service_admin/public/include/remote_proxy.h Fri Jan
30 07:31:40 2015
@@ -31,6 +31,7 @@
 #include "remote_service_admin.h"
 
 #define OSGI_RSA_REMOTE_PROXY_FACTORY 	"remote_proxy_factory"
+#define OSGI_RSA_REMOTE_PROXY_TIMEOUT   "remote_proxy_timeout"
 
 typedef celix_status_t (*sendToHandle)(remote_service_admin_pt remote_service_admin_ptr,
endpoint_description_pt endpointDescription, char *request, char **reply, int* replyStatus);
 typedef celix_status_t (*createProxyService)(void *handle, endpoint_description_pt endpointDescription,
remote_service_admin_pt rsa, sendToHandle sendToCallback, properties_pt properties, void **service);

Modified: celix/trunk/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c?rev=1655949&r1=1655948&r2=1655949&view=diff
==============================================================================
--- celix/trunk/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c
(original)
+++ celix/trunk/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c
Fri Jan 30 07:31:40 2015
@@ -81,6 +81,7 @@ static const char * const ENDPOINT_URL =
 static const char *DEFAULT_PORT = "8888";
 static const char *DEFAULT_IP = "127.0.0.1";
 
+static const unsigned int DEFAULT_TIMEOUT = 0;
 
 static int remoteServiceAdmin_callback(struct mg_connection *conn);
 
@@ -674,6 +675,22 @@ celix_status_t remoteServiceAdmin_send(r
     char url[256];
     snprintf(url, 256, "%s", serviceUrl);
 
+    // assume the default timeout
+    int timeout = DEFAULT_TIMEOUT;
+
+    char *timeoutStr = NULL;
+    // Check if the endpoint has a timeout, if so, use it.
+	timeoutStr = properties_get(endpointDescription->properties, (char*) OSGI_RSA_REMOTE_PROXY_TIMEOUT);
+    if (timeoutStr == NULL) {
+    	// If not, get the global variable and use that one.
+    	bundleContext_getProperty(rsa->context, (char*) OSGI_RSA_REMOTE_PROXY_TIMEOUT, &timeoutStr);
+    }
+
+    // Update timeout if a property is used to set it.
+    if (timeoutStr != NULL) {
+    	timeout = atoi(timeoutStr);
+    }
+
     celix_status_t status = CELIX_SUCCESS;
     CURL *curl;
     CURLcode res;
@@ -682,6 +699,7 @@ celix_status_t remoteServiceAdmin_send(r
     if(!curl) {
         status = CELIX_ILLEGAL_STATE;
     } else {
+    	curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);
         curl_easy_setopt(curl, CURLOPT_URL, &url[0]);
         curl_easy_setopt(curl, CURLOPT_POST, 1L);
         curl_easy_setopt(curl, CURLOPT_READFUNCTION, remoteServiceAdmin_readCallback);



Mime
View raw message