代码拉取完成,页面将自动刷新
#include "thread_pool.h"
#define FILENAME "bigfile.avi"
int transferFile(int sockfd)
{
//进行文件的发送
//1. 先发送文件名
//1.1 设置文件名的长度
train_t t;
memset(&t, 0, sizeof(t));
t.len = strlen(FILENAME);
strcpy(t.buff, FILENAME);
send(sockfd, &t, 4 + t.len, 0);
//2. 读取文件内容( 相对路径 )
int fd = open(FILENAME, O_RDWR);
ERROR_CHECK(fd, -1, "open");
memset(&t, 0, sizeof(t));
//2.1 获取文件的长度
struct stat fileInfo;
memset(&fileInfo, 0, sizeof(fileInfo));
fstat(fd, &fileInfo);
off_t length = fileInfo.st_size;
printf("file length: %ld\n", length);
//发送文件的长度
sendn(sockfd, &length, sizeof(length));
//借助于一条管道来搬运数据
int fds[2];
int ret = -1;
int curSize = 0;
pipe(fds);
//发送文件内容
while(curSize < length) {
ret = splice(fd, NULL, fds[1], NULL, 4096, SPLICE_F_MORE);
ret = splice(fds[0], NULL, sockfd, NULL, ret, SPLICE_F_MORE);
curSize += ret;
}
printf("curSize:%d\n", curSize);
close(fd);
return 0;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。