From: drh Date: Tue, 1 Nov 2011 15:45:28 +0000 (+0000) Subject: If the read() system call in unix returns fewer bytes than expected, retry X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fheads%2Fretry-short-reads;p=thirdparty%2Fsqlite.git If the read() system call in unix returns fewer bytes than expected, retry it until it either returns zero or an error. FossilOrigin-Name: 72256634773f6cba0aabaa3c953cd5daefd50e67 --- diff --git a/manifest b/manifest index 307b0c39c8..328f42bed6 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Version\s3.7.9 -D 2011-11-01T00:52:41.132 +C If\sthe\sread()\ssystem\scall\sin\sunix\sreturns\sfewer\sbytes\sthan\sexpected,\sretry\nit\suntil\sit\seither\sreturns\szero\sor\san\serror. +D 2011-11-01T15:45:28.858 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in a162fe39e249b8ed4a65ee947c30152786cfe897 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -166,7 +166,7 @@ F src/os.c 5d9b02782ed36345348d6fe21d7762ed3a9cfd2a F src/os.h 9dbed8c2b9c1f2f2ebabc09e49829d4777c26bf9 F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 F src/os_os2.c 4a75888ba3dfc820ad5e8177025972d74d7f2440 -F src/os_unix.c ddda0b1c5ae536669634d7bff31b3f8f4d654866 +F src/os_unix.c 82e71071198c2474d89f421076e524e2c4f3fda4 F src/os_win.c 49d418916428a59d773f39993db0ecde56ab4c37 F src/pager.c ad62daa0c21e27ae332b3ceb4f579a2a97046ddc F src/pager.h 9f81b08efb06db4ba8be69446e10b005c351373d @@ -974,8 +974,10 @@ F tool/tostr.awk e75472c2f98dd76e06b8c9c1367f4ab07e122d06 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f F tool/warnings-clang.sh 9f406d66e750e8ac031c63a9ef3248aaa347ef2a F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 -P 6635cd9a7714b681dd8aa96e90be462a40d10178 -R b059ff356abfc5b4524a9b548916f43e -T +sym-version-3.7.9 * +P c7c6050ef060877ebe77b41d959e9df13f8c9b5e +R 168a5dade3c3abfe1d87f94e8b5ca421 +T *branch * retry-short-reads +T *sym-retry-short-reads * +T -sym-trunk * U drh -Z a9ecbb5c487c786a176874d979505217 +Z 20b068a5313402ed91403f5e74abce9f diff --git a/manifest.uuid b/manifest.uuid index ce12ac8420..0460533f37 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c7c6050ef060877ebe77b41d959e9df13f8c9b5e \ No newline at end of file +72256634773f6cba0aabaa3c953cd5daefd50e67 \ No newline at end of file diff --git a/src/os_unix.c b/src/os_unix.c index 0ea6daf27f..293790cbf9 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -2944,35 +2944,44 @@ static int nfsUnlock(sqlite3_file *id, int eFileLock){ */ static int seekAndRead(unixFile *id, sqlite3_int64 offset, void *pBuf, int cnt){ int got; + int total = 0; #if (!defined(USE_PREAD) && !defined(USE_PREAD64)) i64 newOffset; #endif TIMER_START; + while( cnt>0 ){ #if defined(USE_PREAD) - do{ got = osPread(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR ); - SimulateIOError( got = -1 ); + do{ got = osPread(id->h, pBuf, cnt, offset); }while(got<0 && errno==EINTR); + SimulateIOError( got = -1 ); #elif defined(USE_PREAD64) - do{ got = osPread64(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR); - SimulateIOError( got = -1 ); + do{ got = osPread64(id->h, pBuf,cnt,offset); }while(got<0 && errno==EINTR); + SimulateIOError( got = -1 ); #else - newOffset = lseek(id->h, offset, SEEK_SET); - SimulateIOError( newOffset-- ); - if( newOffset!=offset ){ - if( newOffset == -1 ){ - ((unixFile*)id)->lastErrno = errno; - }else{ - ((unixFile*)id)->lastErrno = 0; + newOffset = lseek(id->h, offset, SEEK_SET); + SimulateIOError( newOffset-- ); + if( newOffset!=offset ){ + if( newOffset == -1 ){ + ((unixFile*)id)->lastErrno = errno; + }else{ + ((unixFile*)id)->lastErrno = 0; + } + return -1; } - return -1; - } - do{ got = osRead(id->h, pBuf, cnt); }while( got<0 && errno==EINTR ); + do{ got = osRead(id->h, pBuf, cnt); }while( got<0 && errno==EINTR ); #endif + if( got<=0 ) break; + total += got; + cnt -= got; + offset += got; + pBuf = (void*)(got + (char*)pBuf); + } TIMER_END; if( got<0 ){ ((unixFile*)id)->lastErrno = errno; + total = got; } - OSTRACE(("READ %-3d %5d %7lld %llu\n", id->h, got, offset, TIMER_ELAPSED)); - return got; + OSTRACE(("READ %-3d %5d %7lld %llu\n", id->h,total,offset,TIMER_ELAPSED)); + return total; } /*