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