Data_read() no longer gives warning messages when reaching the end of the cache file.

This commit is contained in:
Fufu Fang 2019-09-02 16:49:49 +01:00
parent 127c4ce651
commit ee397d1513
No known key found for this signature in database
GPG Key ID: 0F6BB5EF6F8BB729
3 changed files with 23 additions and 21 deletions

2
.gitignore vendored
View File

@ -1,5 +1,3 @@
*.o
*.kate-swp
html
mnt
httpdirfs

View File

@ -26,10 +26,12 @@ opened.
- This problem only occurred during the first time you download a file.
During subsequent accesses, when you are only reading from the cache, this
problem did not occur.
- Cache system: Previously it was possible for cache_bgdl()'s download offset
- Cache system: Previously it was possible for Cache_bgdl()'s download offset
to be modified by the parent thread after the child thread had been
launched. This used to cause permanent cache file corruption.
- Cache system: cache_bgdl() no longer prefetches beyond EOF.
- Cache system: Cache_bgdl() no longer prefetches beyond EOF.
- Cache system: Data_read() no longer gives warning messages when reaching the
end of the cache file.
## [1.1.8] - 2019-08-24
### Changed

View File

@ -360,20 +360,23 @@ static long Data_read(Cache *cf, uint8_t *buf, off_t len, off_t offset)
#endif
PTHREAD_MUTEX_LOCK(&cf->seek_lock);
long byte_read = 0;
if (fseeko(cf->dfp, offset, SEEK_SET)) {
/* fseeko failed */
fprintf(stderr, "Data_read(): fseeko(): %s\n", strerror(errno));
#ifdef CACHE_LOCK_DEBUG
fprintf(stderr, "Data_read(): thread %lu: unlocking seek_lock;\n",
pthread_self());
#endif
PTHREAD_MUTEX_UNLOCK(&cf->seek_lock);
return -EIO;
byte_read = -EIO;
goto end;
}
long byte_read = fread(buf, sizeof(uint8_t), len, cf->dfp);
if (offset + len > cf->content_length) {
len -= offset + len - cf->content_length;
if (len < 0) {
goto end;
}
}
byte_read = fread(buf, sizeof(uint8_t), len, cf->dfp);
if (byte_read != len) {
fprintf(stderr,
"Data_read(): fread(): requested %ld, returned %ld!\n",
@ -390,6 +393,7 @@ static long Data_read(Cache *cf, uint8_t *buf, off_t len, off_t offset)
}
}
end:
#ifdef CACHE_LOCK_DEBUG
fprintf(stderr, "Data_read(): thread %lu: unlocking seek_lock;\n",
pthread_self());
@ -424,19 +428,16 @@ static long Data_write(Cache *cf, const uint8_t *buf, off_t len,
#endif
PTHREAD_MUTEX_LOCK(&cf->seek_lock);
long byte_written = 0;
if (fseeko(cf->dfp, offset, SEEK_SET)) {
/* fseeko failed */
fprintf(stderr, "Data_write(): fseeko(): %s\n", strerror(errno));
#ifdef CACHE_LOCK_DEBUG
fprintf(stderr, "Data_write(): thread %lu: unlocking seek_lock;\n",
pthread_self());
#endif
PTHREAD_MUTEX_UNLOCK(&cf->seek_lock);
return -EIO;
byte_written = -EIO;
goto end;
}
long byte_written = fwrite(buf, sizeof(uint8_t), len, cf->dfp);
byte_written = fwrite(buf, sizeof(uint8_t), len, cf->dfp);
if (byte_written != len) {
fprintf(stderr,
"Data_write(): fwrite(): requested %ld, returned %ld!\n",
@ -448,6 +449,7 @@ static long Data_write(Cache *cf, const uint8_t *buf, off_t len,
}
}
end:
#ifdef CACHE_LOCK_DEBUG
fprintf(stderr, "Data_write(): thread %lu: unlocking seek_lock;\n",
pthread_self());