1
0
mirror of https://github.com/fumiama/simple-kanban.git synced 2026-06-23 20:16:44 +08:00

再次修复linux下的sendfile

This commit is contained in:
fumiama
2021-05-03 00:32:44 +08:00
parent 410c540233
commit 4ca5bd1434
2 changed files with 3 additions and 3 deletions

View File

@@ -72,7 +72,7 @@ int main(int argc,char *argv[]) { //usage: ./client host port
FILE *fp = NULL; FILE *fp = NULL;
fp = fopen(buf, "rb"); fp = fopen(buf, "rb");
if(fp) { if(fp) {
off_t len; off_t len = 0;
file_size = (uint32_t)fileSize(buf); file_size = (uint32_t)fileSize(buf);
#if __APPLE__ #if __APPLE__
struct iovec headers; struct iovec headers;

View File

@@ -127,7 +127,7 @@ int sendAll(char* file_path, THREADTIMER *timer) {
timer->is_open = 1; timer->is_open = 1;
uint32_t file_size = (uint32_t)fileSize(file_path); uint32_t file_size = (uint32_t)fileSize(file_path);
printf("Get file size: %u bytes.\n", file_size); printf("Get file size: %u bytes.\n", file_size);
off_t len; off_t len = 0;
#if __APPLE__ #if __APPLE__
struct iovec headers; struct iovec headers;
headers.iov_base = &file_size; headers.iov_base = &file_size;
@@ -136,7 +136,7 @@ int sendAll(char* file_path, THREADTIMER *timer) {
hdtr.hdr_cnt = 1; hdtr.hdr_cnt = 1;
sendfile(fileno(fp), timer->accept_fd, 0, &len, &hdtr, 0); sendfile(fileno(fp), timer->accept_fd, 0, &len, &hdtr, 0);
#else #else
//send(timer->accept_fd, &file_size, sizeof(uint32_t), 0); send(timer->accept_fd, &file_size, sizeof(uint32_t), 0);
sendfile(timer->accept_fd, fileno(fp), &len, file_size); sendfile(timer->accept_fd, fileno(fp), &len, file_size);
#endif #endif
printf("Send %lld bytes.\n", len); printf("Send %lld bytes.\n", len);