Rewrite some read/write loops for readability
[platform/core/security/tef-simulator.git] / TEECLib / src / teec_connection.c
index da805d3..7ae18cc 100644 (file)
@@ -130,12 +130,14 @@ static uint32_t sendCommandtoDaemon(int32_t sockfd, char *fdata, size_t size)
 
        if (sockfd >= 0) {
                // send size number of bytes to Simulator Daemon
-               do {
+               while (nbytes < size) {
                        nwrite = send(sockfd, fdata + nbytes, size - nbytes, 0);
-               } while ((nwrite == -1 && errno == EINTR) || (nwrite > 0 && ((nbytes +=
-
-                                        nwrite) < size)));
-
+                       if (nwrite == -1 && errno == EINTR)
+                               continue;
+                       if (nwrite <= 0)
+                               break;
+                       nbytes += nwrite;
+               }
                return (size != nbytes) ? errno : 0;
        }
 
@@ -163,12 +165,14 @@ static uint32_t receiveResponse(int32_t sockfd, char *fdata, size_t size)
 
        if (sockfd >= 0) {
                // receive size number of bytes to Simulator Daemon
-               do {
+               while (nbytes < size) {
                        nread = recv(sockfd, fdata + nbytes, size - nbytes, 0);
-               } while ((nread == -1 && errno == EINTR)
-
-                                || (nread > 0 && ((nbytes += nread) < size)));
-
+                       if (nread == -1 && errno == EINTR)
+                               continue;
+                       if (nread <= 0)
+                               break;
+                       nbytes += nread;
+               }
                return (size != nbytes) ? errno : 0;
        }