Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added seek callback, some extra logging

trying to get more information about an occasional error
reported as "Operation was aborted by an application callback"
  • Loading branch information...
commit 2a4e92865ee32fb4ef129f298bb49fbf1f163aaf 1 parent d81672f
@russross authored
Showing with 31 additions and 4 deletions.
  1. +6 −1 filecache.cpp
  2. +25 −3 s3request.cpp
View
7 filecache.cpp
@@ -266,7 +266,12 @@ void *flush_loop(void *param) {
while (!flush_shutdown) {
Filecache *file = Filecache::from_queue();
if (file) {
- file->fsync();
+ try {
+ file->fsync();
+ } catch (int e) {
+ syslog(LOG_ERR, "flush_loop: fsync failed[%s]",
+ file->path.c_str());
+ }
file->release();
delete file;
} else {
View
28 s3request.cpp
@@ -165,7 +165,22 @@ size_t uploadCallback(void *data, size_t blockSize, size_t numBlocks,
void *userPtr)
{
int *fd = static_cast<int *>(userPtr);
- return read(*fd, data, blockSize * numBlocks);
+ size_t len = read(*fd, data, blockSize * numBlocks);
+ if (len != blockSize * numBlocks) {
+ syslog(LOG_INFO, "uploadCallback: short read [%u] != [%u]",
+ (unsigned) len, (unsigned) (blockSize * numBlocks));
+ }
+ return len;
+}
+
+// lseek the uploadCallback data
+int seekCallback(void *userPtr, curl_off_t offset, int origin) {
+ syslog(LOG_INFO, "seekCallback: offset[%llu]", (unsigned long long) offset);
+
+ int *fd = static_cast<int *>(userPtr);
+ if (lseek(*fd, (off_t) offset, origin) < 0)
+ return 1; // CURL_SEEKFUNC_FAIL
+ return 0; // CURL_SEEKFUNC_OK
}
// store data in a fd and compute the md5 on the fly
@@ -177,7 +192,12 @@ size_t downloadCallback(void *data, size_t blockSize, size_t numBlocks,
// update the md5 sum
file->add(static_cast<unsigned char *>(data), blockSize * numBlocks);
- return write(file->fd, data, blockSize * numBlocks);
+ size_t len = write(file->fd, data, blockSize * numBlocks);
+ if (len != blockSize * numBlocks) {
+ syslog(LOG_INFO, "downloadCallback: short write [%u] != [%u]",
+ (unsigned) len, (unsigned) (blockSize * numBlocks));
+ }
+ return len;
}
// store received data in a string
@@ -567,9 +587,11 @@ void S3request::put_file(Fileinfo *info, int fd) {
// start reading from the beginning of the file
lseek(fd, 0, SEEK_SET);
- // store the data and compute the md5sum
+ // upload the data, allowing seeks
curl_easy_setopt(req.curl, CURLOPT_READDATA, &fd);
curl_easy_setopt(req.curl, CURLOPT_READFUNCTION, uploadCallback);
+ curl_easy_setopt(req.curl, CURLOPT_SEEKDATA, &fd);
+ curl_easy_setopt(req.curl, CURLOPT_SEEKFUNCTION, seekCallback);
}
// set all the headers
Please sign in to comment.
Something went wrong with that request. Please try again.