Fix network communication on arm64 - continued
authorPB <pjbanasik@gmail.com>
Fri, 16 Aug 2019 08:26:05 +0000 (10:26 +0200)
committerPB <pjbanasik@gmail.com>
Fri, 16 Aug 2019 08:26:05 +0000 (10:26 +0200)
The 55d8b880fca26ccf4b897bca1fe66796b9972345 commit on the original pigpio repo fixed parsing data received from a socket on 64bit systems.
This one fixes also the response that is being sent back to the socket - 64bit array is translated back to a 32bit array that is passed to the send function.

pigpio.c

index cbe818f14a5cfb680a1aa7fc954a80c518e5a0a0..47c58382f7041933f43351df151bbad91bb65996 100644 (file)
--- a/pigpio.c
+++ b/pigpio.c
@@ -6953,7 +6953,8 @@ static void *pthSocketThreadHandler(void *fdC)
 {
    int sock = *(int*)fdC;
    uintptr_t p[10];
-   uint32_t tmp;
+   uint32_t tmp, response[4];
+   int i;
    int opt;
    char buf[CMD_MAX_EXTENSION];
 
@@ -7043,7 +7044,16 @@ static void *pthSocketThreadHandler(void *fdC)
             p[3] = myDoCommand(p, sizeof(buf)-1, buf);
       }
 
-      if (write(sock, p, 16) == -1) { /* ignore errors */ }
+      if (sizeof(uintptr_t) == 8) // 64-bit system
+      {
+         for (i = 0; i < 4; i++)
+            response[i] = (uint32_t)p[i];
+         if (write(sock, response, 16) == -1) { /* ignore errors */ }
+      }
+      else // 32-bit system
+      {
+         if (write(sock, p, 16) == -1) { /* ignore errors */ }
+      }
 
       switch (p[0])
       {