Cleanup prev commit

Loop on copyfd meta write, since pipes may return after partial write.
vmware
Howard Chu 11 years ago
parent eff35fcb2a
commit 254b77e63d
  1. 66
      libraries/liblmdb/mdb.c

@ -4007,6 +4007,14 @@ mdb_env_copyfd(MDB_env *env, HANDLE fd)
int rc; int rc;
size_t wsize; size_t wsize;
char *ptr; 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 /* Do the lock/unlock of the reader mutex before starting the
* write txn. Otherwise other read txns could block writers. * 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; wsize = env->me_psize * 2;
#ifdef _WIN32 ptr = env->me_map;
{ {
DWORD len; w2 = wsize;
rc = WriteFile(fd, env->me_map, wsize, &len, NULL); while (w2 > 0) {
rc = (len == wsize) ? MDB_SUCCESS : ErrCode(); 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) if (env->me_txns)
UNLOCK_MUTEX_W(env); UNLOCK_MUTEX_W(env);
if (rc) if (rc)
goto leave; goto leave;
ptr = env->me_map + wsize;
wsize = txn->mt_next_pgno * env->me_psize - wsize; wsize = txn->mt_next_pgno * env->me_psize - wsize;
#ifdef _WIN32
while (wsize > 0) { while (wsize > 0) {
DWORD len, w2;
if (wsize > MAX_WRITE) if (wsize > MAX_WRITE)
w2 = MAX_WRITE; w2 = MAX_WRITE;
else else
w2 = wsize; w2 = wsize;
rc = WriteFile(fd, ptr, w2, &len, NULL); DOWRITE(fd, ptr, w2, len);
rc = (len == w2) ? MDB_SUCCESS : ErrCode(); if (len > 0) {
if (rc) break; rc = MDB_SUCCESS;
wsize -= w2; ptr += len;
ptr += w2; wsize -= len;
continue;
} else {
rc = ErrCode();
if (!rc)
rc = EIO;
break;
} }
#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;
} }
#endif
leave: leave:
mdb_txn_abort(txn); mdb_txn_abort(txn);

Loading…
Cancel
Save