diff options
| author | 2014-03-02 17:00:16 (JST) | |
|---|---|---|
| committer | 2014-03-02 17:00:16 (JST) | |
| commit | 667bf9f6ed38daac4e4d7e88903eb0f28319c165 (patch) | |
| tree | d7d36d505fb3c183bdec673c6e294b27e1a12310 /cache.c | |
| parent | 1f57ee005551ae7ee2b387f14eb7dd104a120ee3 (diff) | |
| parent | f2fa9c56e29ae32bbe5841e7bfe0217ada4e3df9 (diff) | |
| download | cgit-667bf9f6ed38daac4e4d7e88903eb0f28319c165.zip cgit-667bf9f6ed38daac4e4d7e88903eb0f28319c165.tar.gz | |
Merge tag 'v0.10.1'
CGIT 0.10.1
Diffstat (limited to 'cache.c')
| -rw-r--r-- | cache.c | 28 |
1 files changed, 26 insertions, 2 deletions
| @@ -13,6 +13,9 @@ | |||
| 13 | * | 13 | * |
| 14 | */ | 14 | */ |
| 15 | 15 | ||
| 16 | #ifdef HAVE_LINUX_SENDFILE | ||
| 17 | #include <sys/sendfile.h> | ||
| 18 | #endif | ||
| 16 | #include "cgit.h" | 19 | #include "cgit.h" |
| 17 | #include "cache.h" | 20 | #include "cache.h" |
| 18 | #include "html.h" | 21 | #include "html.h" |
| @@ -30,7 +33,6 @@ struct cache_slot { | |||
| 30 | const char *lock_name; | 33 | const char *lock_name; |
| 31 | int match; | 34 | int match; |
| 32 | struct stat cache_st; | 35 | struct stat cache_st; |
| 33 | struct stat lock_st; | ||
| 34 | int bufsize; | 36 | int bufsize; |
| 35 | char buf[CACHE_BUFSIZE]; | 37 | char buf[CACHE_BUFSIZE]; |
| 36 | }; | 38 | }; |
| @@ -81,6 +83,23 @@ static int close_slot(struct cache_slot *slot) | |||
| 81 | /* Print the content of the active cache slot (but skip the key). */ | 83 | /* Print the content of the active cache slot (but skip the key). */ |
| 82 | static int print_slot(struct cache_slot *slot) | 84 | static int print_slot(struct cache_slot *slot) |
| 83 | { | 85 | { |
| 86 | #ifdef HAVE_LINUX_SENDFILE | ||
| 87 | off_t start_off; | ||
| 88 | int ret; | ||
| 89 | |||
| 90 | start_off = slot->keylen + 1; | ||
| 91 | |||
| 92 | do { | ||
| 93 | ret = sendfile(STDOUT_FILENO, slot->cache_fd, &start_off, | ||
| 94 | slot->cache_st.st_size - start_off); | ||
| 95 | if (ret < 0) { | ||
| 96 | if (errno == EAGAIN || errno == EINTR) | ||
| 97 | continue; | ||
| 98 | return errno; | ||
| 99 | } | ||
| 100 | return 0; | ||
| 101 | } while (1); | ||
| 102 | #else | ||
| 84 | ssize_t i, j; | 103 | ssize_t i, j; |
| 85 | 104 | ||
| 86 | i = lseek(slot->cache_fd, slot->keylen + 1, SEEK_SET); | 105 | i = lseek(slot->cache_fd, slot->keylen + 1, SEEK_SET); |
| @@ -97,6 +116,7 @@ static int print_slot(struct cache_slot *slot) | |||
| 97 | return errno; | 116 | return errno; |
| 98 | else | 117 | else |
| 99 | return 0; | 118 | return 0; |
| 119 | #endif | ||
| 100 | } | 120 | } |
| 101 | 121 | ||
| 102 | /* Check if the slot has expired */ | 122 | /* Check if the slot has expired */ |
| @@ -188,6 +208,10 @@ static int fill_slot(struct cache_slot *slot) | |||
| 188 | /* Generate cache content */ | 208 | /* Generate cache content */ |
| 189 | slot->fn(); | 209 | slot->fn(); |
| 190 | 210 | ||
| 211 | /* update stat info */ | ||
| 212 | if (fstat(slot->lock_fd, &slot->cache_st)) | ||
| 213 | return errno; | ||
| 214 | |||
| 191 | /* Restore stdout */ | 215 | /* Restore stdout */ |
| 192 | if (dup2(tmp, STDOUT_FILENO) == -1) | 216 | if (dup2(tmp, STDOUT_FILENO) == -1) |
| 193 | return errno; | 217 | return errno; |
| @@ -319,7 +343,7 @@ int cache_process(int size, const char *path, const char *key, int ttl, | |||
| 319 | int result; | 343 | int result; |
| 320 | 344 | ||
| 321 | /* If the cache is disabled, just generate the content */ | 345 | /* If the cache is disabled, just generate the content */ |
| 322 | if (size <= 0) { | 346 | if (size <= 0 || ttl == 0) { |
| 323 | fn(); | 347 | fn(); |
| 324 | return 0; | 348 | return 0; |
| 325 | } | 349 | } |
