Lines 85-124
Link Here
|
85 |
/* Print the content of the active cache slot (but skip the key). */ |
85 |
/* Print the content of the active cache slot (but skip the key). */ |
86 |
static int print_slot(struct cache_slot *slot) |
86 |
static int print_slot(struct cache_slot *slot) |
87 |
{ |
87 |
{ |
88 |
#ifdef HAVE_LINUX_SENDFILE |
88 |
off_t off; |
89 |
off_t start_off; |
89 |
ssize_t i; |
90 |
int ret; |
90 |
|
|
|
91 |
off = slot->keylen + 1; |
91 |
|
92 |
|
92 |
start_off = slot->keylen + 1; |
93 |
#ifdef HAVE_LINUX_SENDFILE |
|
|
94 |
off_t size; |
95 |
size = slot->cache_st.st_size; |
93 |
|
96 |
|
94 |
do { |
97 |
do { |
95 |
ret = sendfile(STDOUT_FILENO, slot->cache_fd, &start_off, |
98 |
i = sendfile(STDOUT_FILENO, slot->cache_fd, &off, size - off); |
96 |
slot->cache_st.st_size - start_off); |
99 |
if (i < 0) { |
97 |
if (ret < 0) { |
|
|
98 |
if (errno == EAGAIN || errno == EINTR) |
100 |
if (errno == EAGAIN || errno == EINTR) |
99 |
continue; |
101 |
continue; |
|
|
102 |
/* Fall back to read/write on EINVAL */ |
103 |
if (errno == EINVAL) |
104 |
break; |
100 |
return errno; |
105 |
return errno; |
101 |
} |
106 |
} |
102 |
return 0; |
107 |
if (off == size) |
|
|
108 |
return 0; |
103 |
} while (1); |
109 |
} while (1); |
104 |
#else |
110 |
#endif |
105 |
ssize_t i, j; |
|
|
106 |
|
111 |
|
107 |
i = lseek(slot->cache_fd, slot->keylen + 1, SEEK_SET); |
112 |
if (lseek(slot->cache_fd, off, SEEK_SET) != off) |
108 |
if (i != slot->keylen + 1) |
|
|
109 |
return errno; |
113 |
return errno; |
110 |
|
114 |
|
111 |
do { |
115 |
do { |
112 |
i = j = xread(slot->cache_fd, slot->buf, sizeof(slot->buf)); |
116 |
i = xread(slot->cache_fd, slot->buf, sizeof(slot->buf)); |
113 |
if (i > 0) |
117 |
if (i < 0) |
114 |
j = xwrite(STDOUT_FILENO, slot->buf, i); |
118 |
return errno; |
115 |
} while (i > 0 && j == i); |
119 |
if (i == 0) |
116 |
|
120 |
return 0; |
117 |
if (i < 0 || j != i) |
121 |
if (write_in_full(STDOUT_FILENO, slot->buf, i) < 0) |
118 |
return errno; |
122 |
return errno; |
119 |
else |
123 |
} while (1); |
120 |
return 0; |
|
|
121 |
#endif |
122 |
} |
124 |
} |
123 |
|
125 |
|
124 |
/* Check if the slot has expired */ |
126 |
/* Check if the slot has expired */ |