]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
add wait for response
authorBastian Dehn <hhaalo@arcor.de>
Thu, 25 Jan 2024 16:52:06 +0000 (17:52 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Thu, 25 Jan 2024 17:06:41 +0000 (18:06 +0100)
src/kds_s2000w_client.c

index 19dc06f2eff1f05c051878e2cc020625a88418a7..4d268a1fc06e2ac2d3120e97ca49535ffc45f896 100644 (file)
@@ -1,8 +1,21 @@
 #include <string.h>
 #include <stdlib.h>
+#include <unistd.h>
 #include <curl/curl.h>
 #include "kds_s2000w_client.h"
 
+int _wait = 0;
+
+void _kds_s2000w_client_wait_for_response()
+{
+       for (int i = 0; i < 10; i++) {
+               if (!_wait)
+                       break;
+
+               sleep(1);
+       }
+}
+
 size_t _kds_s2000w_client_callback(char *ptr, size_t size, size_t nmemb, void *userdata)
 {
        response* data = (response*) userdata;
@@ -15,6 +28,7 @@ size_t _kds_s2000w_client_callback(char *ptr, size_t size, size_t nmemb, void *u
        memcpy(data->data, ptr, fullsize);
        data->size = fullsize + 1;
 
+       _wait = 0;
        return fullsize;
 }
 
@@ -57,7 +71,9 @@ int kds_s2000w_client_open_session(const char* username, response* response)
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body);
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, _kds_s2000w_client_callback);
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*) response);
+       _wait = 1;
        CURLcode result = curl_easy_perform(curl);
+       _kds_s2000w_client_wait_for_response();
        curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response->code);
 
        curl_url_cleanup(url_handler);