/ Check-in [a210695a]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Make the unix VFS tolerant of read() calls that return less than the requested number of bytes.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: a210695abcfa5cb04279edfd04824d881b7c4ada
User & Date: drh 2011-11-07 18:16:00
Context
2011-11-09
18:07
Omit an unnecessary Sleep() call in windows pending-lock retry logic. Enhance the comment on that logic to discourage people from copying it into other VFSes. check-in: 0c951a97 user: drh tags: trunk
2011-11-08
20:08
Experimental change to the pcache interface to allow page buffers to be allocated separately from their associated container structures. check-in: c275c9d3 user: dan tags: experimental-pcache
2011-11-07
18:16
Make the unix VFS tolerant of read() calls that return less than the requested number of bytes. check-in: a210695a user: drh tags: trunk
17:54
Amplify the restriction on commit-hooks that they cannot recursively run SQL on the same database connection. check-in: 4fe5b731 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/os_unix.c.

  2947   2947   ** See tickets #2741 and #2681.
  2948   2948   **
  2949   2949   ** To avoid stomping the errno value on a failed read the lastErrno value
  2950   2950   ** is set before returning.
  2951   2951   */
  2952   2952   static int seekAndRead(unixFile *id, sqlite3_int64 offset, void *pBuf, int cnt){
  2953   2953     int got;
         2954  +  int prior = 0;
  2954   2955   #if (!defined(USE_PREAD) && !defined(USE_PREAD64))
  2955   2956     i64 newOffset;
  2956   2957   #endif
  2957   2958     TIMER_START;
         2959  +  do{
  2958   2960   #if defined(USE_PREAD)
  2959         -  do{ got = osPread(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR );
  2960         -  SimulateIOError( got = -1 );
         2961  +    got = osPread(id->h, pBuf, cnt, offset);
         2962  +    SimulateIOError( got = -1 );
  2961   2963   #elif defined(USE_PREAD64)
  2962         -  do{ got = osPread64(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR);
  2963         -  SimulateIOError( got = -1 );
         2964  +    got = osPread64(id->h, pBuf, cnt, offset);
         2965  +    SimulateIOError( got = -1 );
  2964   2966   #else
  2965         -  newOffset = lseek(id->h, offset, SEEK_SET);
  2966         -  SimulateIOError( newOffset-- );
  2967         -  if( newOffset!=offset ){
  2968         -    if( newOffset == -1 ){
         2967  +    newOffset = lseek(id->h, offset, SEEK_SET);
         2968  +    SimulateIOError( newOffset-- );
         2969  +    if( newOffset!=offset ){
         2970  +      if( newOffset == -1 ){
         2971  +        ((unixFile*)id)->lastErrno = errno;
         2972  +      }else{
         2973  +        ((unixFile*)id)->lastErrno = 0;			
         2974  +      }
         2975  +      return -1;
         2976  +    }
         2977  +    got = osRead(id->h, pBuf, cnt);
         2978  +#endif
         2979  +    if( got==cnt ) break;
         2980  +    if( got<0 ){
         2981  +      if( errno==EINTR ){ got = 1; continue; }
         2982  +      prior = 0;
  2969   2983         ((unixFile*)id)->lastErrno = errno;
  2970         -    }else{
  2971         -      ((unixFile*)id)->lastErrno = 0;			
         2984  +      break;
         2985  +    }else if( got>0 ){
         2986  +      cnt -= got;
         2987  +      offset += got;
         2988  +      prior += got;
         2989  +      pBuf = (void*)(got + (char*)pBuf);
  2972   2990       }
  2973         -    return -1;
  2974         -  }
  2975         -  do{ got = osRead(id->h, pBuf, cnt); }while( got<0 && errno==EINTR );
  2976         -#endif
         2991  +  }while( got>0 );
  2977   2992     TIMER_END;
  2978         -  if( got<0 ){
  2979         -    ((unixFile*)id)->lastErrno = errno;
  2980         -  }
  2981         -  OSTRACE(("READ    %-3d %5d %7lld %llu\n", id->h, got, offset, TIMER_ELAPSED));
  2982         -  return got;
         2993  +  OSTRACE(("READ    %-3d %5d %7lld %llu\n",
         2994  +            id->h, got+prior, offset-prior, TIMER_ELAPSED));
         2995  +  return got+prior;
  2983   2996   }
  2984   2997   
  2985   2998   /*
  2986   2999   ** Read data from a file into a buffer.  Return SQLITE_OK if all
  2987   3000   ** bytes were read successfully and SQLITE_IOERR if anything goes
  2988   3001   ** wrong.
  2989   3002   */