mirror of
https://github.com/fumiama/simple-kanban.git
synced 2026-06-07 17:40:25 +08:00
适配非苹果系统
This commit is contained in:
25
client.c
25
client.c
@@ -9,6 +9,9 @@
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/stat.h>
|
||||
#include <pthread.h>
|
||||
#if !__APPLE__
|
||||
#include <sys/sendfile.h>
|
||||
#endif
|
||||
|
||||
int sockfd;
|
||||
char buf[BUFSIZ];
|
||||
@@ -68,16 +71,22 @@ int main(int argc,char *argv[]) { //usage: ./client host port
|
||||
fp = fopen(buf, "rb");
|
||||
if(fp) {
|
||||
off_t len;
|
||||
struct iovec headers;
|
||||
headers.iov_base = &file_size;
|
||||
headers.iov_len = sizeof(uint32_t);
|
||||
hdtr.headers = &headers;
|
||||
hdtr.hdr_cnt = 1;
|
||||
file_size = (uint32_t)fileSize(buf);
|
||||
if(!sendfile(fileno(fp), sockfd, 0, &len, &hdtr, 0)) puts("Send file success.");
|
||||
else puts("Send file error.");
|
||||
printf("Send count:%lld\n", len);
|
||||
#if __APPLE__
|
||||
struct iovec headers;
|
||||
headers.iov_base = &file_size;
|
||||
headers.iov_len = sizeof(uint32_t);
|
||||
hdtr.headers = &headers;
|
||||
hdtr.hdr_cnt = 1;
|
||||
if(!sendfile(fileno(fp), sockfd, 0, &len, &hdtr, 0)) puts("Send file success.");
|
||||
else puts("Send file error.");
|
||||
#else
|
||||
send(timer->accept_fd, &file_size, sizeof(uint32_t), 0);
|
||||
if(!sendfile(fileno(fp), sockfd, &len, file_size)) puts("Send file success.");
|
||||
else puts("Send file error.");
|
||||
#endif
|
||||
fclose(fp);
|
||||
printf("Send count:%lld\n", len);
|
||||
} else puts("Open file error!");
|
||||
} else send(sockfd, buf, strlen(buf), 0);
|
||||
sleep(1);
|
||||
|
||||
20
server.c
20
server.c
@@ -13,6 +13,9 @@
|
||||
#include <unistd.h>
|
||||
#include <pthread.h>
|
||||
#include <time.h>
|
||||
#if !__APPLE__
|
||||
#include <sys/sendfile.h>
|
||||
#endif
|
||||
|
||||
#define PASSWORD "fumiama"
|
||||
|
||||
@@ -120,14 +123,19 @@ int sendAll(char* file_path, THREADTIMER *timer) {
|
||||
if(fp) {
|
||||
timer->fp = fp;
|
||||
timer->is_open = 1;
|
||||
struct iovec headers;
|
||||
uint32_t file_size = (uint32_t)fileSize(file_path);
|
||||
off_t len;
|
||||
headers.iov_base = &file_size;
|
||||
headers.iov_len = sizeof(uint32_t);
|
||||
hdtr.headers = &headers;
|
||||
hdtr.hdr_cnt = 1;
|
||||
sendfile(fileno(fp), timer->accept_fd, 0, &len, &hdtr, 0);
|
||||
#if __APPLE__
|
||||
struct iovec headers;
|
||||
headers.iov_base = &file_size;
|
||||
headers.iov_len = sizeof(uint32_t);
|
||||
hdtr.headers = &headers;
|
||||
hdtr.hdr_cnt = 1;
|
||||
sendfile(fileno(fp), timer->accept_fd, 0, &len, &hdtr, 0);
|
||||
#else
|
||||
send(timer->accept_fd, &file_size, sizeof(uint32_t), 0);
|
||||
sendfile(fileno(fp), timer->accept_fd, &len, file_size);
|
||||
#endif
|
||||
printf("Send %lld bytes.", len);
|
||||
closeFile(fp);
|
||||
timer->is_open = 0;
|
||||
|
||||
Reference in New Issue
Block a user