]> git.sur5r.net Git - openldap/commitdiff
Cleanup prev commit
authorHoward Chu <hyc@symas.com>
Tue, 30 Jul 2013 19:47:12 +0000 (12:47 -0700)
committerHoward Chu <hyc@symas.com>
Tue, 30 Jul 2013 19:47:12 +0000 (12:47 -0700)
Loop on copyfd meta write, since pipes may return after partial write.

libraries/liblmdb/mdb.c

index 8f7e17cbc49225e30ffb8744b71371b6063d84d5..2a4bbeecc42ec31c325ab855361ad5c3806adcb6 100644 (file)
@@ -4007,6 +4007,14 @@ mdb_env_copyfd(MDB_env *env, HANDLE fd)
        int rc;
        size_t wsize;
        char *ptr;
+#ifdef _WIN32
+       DWORD len, w2;
+#define DOWRITE(fd, ptr, w2, len)      WriteFile(fd, ptr, w2, &len)
+#else
+       ssize_t len;
+       size_t w2;
+#define DOWRITE(fd, ptr, w2, len)      len = write(fd, ptr, w2)
+#endif
 
        /* Do the lock/unlock of the reader mutex before starting the
         * write txn.  Otherwise other read txns could block writers.
@@ -4030,52 +4038,50 @@ mdb_env_copyfd(MDB_env *env, HANDLE fd)
        }
 
        wsize = env->me_psize * 2;
-#ifdef _WIN32
+       ptr = env->me_map;
        {
-               DWORD len;
-               rc = WriteFile(fd, env->me_map, wsize, &len, NULL);
-               rc = (len == wsize) ? MDB_SUCCESS : ErrCode();
+               w2 = wsize;
+               while (w2 > 0) {
+                       DOWRITE(fd, ptr, w2, len);
+                       if (len > 0) {
+                               rc = MDB_SUCCESS;
+                               ptr += len;
+                               w2 -= len;
+                               continue;
+                       } else {
+                               /* Non-blocking or async handles are not supported */
+                               rc = ErrCode();
+                               if (!rc)
+                                       rc = EIO;
+                               break;
+                       }
+               }
        }
-#else
-       rc = write(fd, env->me_map, wsize);
-       rc = (rc == (int)wsize) ? MDB_SUCCESS : ErrCode();
-#endif
        if (env->me_txns)
                UNLOCK_MUTEX_W(env);
 
        if (rc)
                goto leave;
 
-       ptr = env->me_map + wsize;
        wsize = txn->mt_next_pgno * env->me_psize - wsize;
-#ifdef _WIN32
-       while (wsize > 0) {
-               DWORD len, w2;
-               if (wsize > MAX_WRITE)
-                       w2 = MAX_WRITE;
-               else
-                       w2 = wsize;
-               rc = WriteFile(fd, ptr, w2, &len, NULL);
-               rc = (len == w2) ? MDB_SUCCESS : ErrCode();
-               if (rc) break;
-               wsize -= w2;
-               ptr += w2;
-       }
-#else
        while (wsize > 0) {
-               size_t w2;
-               ssize_t wres;
                if (wsize > MAX_WRITE)
                        w2 = MAX_WRITE;
                else
                        w2 = wsize;
-               wres = write(fd, ptr, w2);
-               rc = (wres > 0 ) ? MDB_SUCCESS : ErrCode();
-               if (rc) break;
-               wsize -= wres;
-               ptr += wres;
+               DOWRITE(fd, ptr, w2, len);
+               if (len > 0) {
+                       rc = MDB_SUCCESS;
+                       ptr += len;
+                       wsize -= len;
+                       continue;
+               } else {
+                       rc = ErrCode();
+                       if (!rc)
+                               rc = EIO;
+                       break;
+               }
        }
-#endif
 
 leave:
        mdb_txn_abort(txn);