第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定

作業(yè)社區(qū)

探索學習新天地,共享知識資源!

0 提交作業(yè)
0 布置作業(yè)
0 滿分作業(yè)
得分 100
學習任務

北城半夏4806197 的學生作業(yè):

服務端 #include "tcp_socket.h" #include "debug.h" #include #include #include "file_transfer.h" // 線程執(zhí)行函數(shù) void *do_task(void *arg) { size_t size; int cfd = *(int *)arg; size = client_upload_file(cfd);// 接收客戶端上傳的文件 printf("client upload file size : %ld\n",size); pthread_exit(NULL); } int main(int argc,char *argv[]) { int sfd,cfd; struct sockaddr_in cli_addr; int ret; pthread_t tid; if (argc != 3){ fprintf(stderr,"Usage : %s < ip > < port >.\n",argv[0]); exit(EXIT_FAILURE); } sfd = create_tcp_server_socket(argv[1],atoi(argv[2])); if (sfd == -1) exit(EXIT_FAILURE); for(;;){ bzero(&cli_addr,sizeof(struct sockaddr_in)); cfd = wait_for_connect(sfd,&cli_addr); if (cfd == -1) exit(EXIT_FAILURE); show_tcp_network_address(&cli_addr); // 創(chuàng)建子線程,用于接收上傳的文件 ret = pthread_create(&tid,NULL,do_task,(void *)&cfd); if (ret != 0){ DEBUG_INFO("[ERROR] pthread_create() : %s\n",strerror(errno)); exit(EXIT_FAILURE); } // 進行線程分離 pthread_detach(tid); } close(cfd); close(sfd); return 0; } 客戶端 #include "tcp_socket.h" #include "file_transfer.h" #include int main(int argc,char *argv[]) { int cfd; if (argc != 4){ fprintf(stderr,"Usage : %s < ip > < port > < pathname >\n",argv[0]); exit(EXIT_FAILURE); } cfd = create_tcp_client_socket(argv[1],atoi(argv[2])); if (cfd == -1) exit(EXIT_FAILURE); upload_file(argv[3],cfd); // 上傳客戶端的數(shù)據(jù) close(cfd); return 0; } 【圖片】

得分 100
學習任務

北城半夏4806197 的學生作業(yè):

file_transfer.c #include"file_transfer.h" #include"debug.h" //接收協(xié)議頭 int recv_protocol_head(int cfd,file_protocol_t *p_head) { ssize_t rbytes; ssize_t total_received = 0; char *buffer = (char *)p_head;// 按照字節(jié)流接收 // 進行循環(huán)接收,防止 tcp 粘包 for(;;){ //接收數(shù)據(jù) rbytes = tcp_recv_pack(cfd,buffer + total_received,sizeof(file_protocol_t) - total_received); if (rbytes == -1){ DEBUG_INFO("[ERROR]: %s ",strerror(errno)); return -1; }else if (rbytes == 0){ DEBUG_INFO("[INFO] : The client has been shut down.\n"); break; }else if (rbytes > 0){ total_received += rbytes; if (total_received == sizeof(file_protocol_t)) // 接收固定長度的數(shù)據(jù) break; } } if (total_received != sizeof(file_protocol_t)){ DEBUG_INFO("[ERROR] : Failed to receive data.\n"); return -1; } return 0; } //接收文件數(shù)據(jù) int recv_filedata(int cfd,const char *filename,size_t targetsize) { int fd; ssize_t rbytes = 0,wbytes = 0,file_size = 0; char buffer[1024] = {0}; DEBUG_INFO("[INFO] : filename %s\n",filename); fd = open(filename,O_WRONLY|O_CREAT|O_TRUNC,0666); if (fd == -1){ DEBUG_INFO("[ERROR] Failed to open filename.\n"); return -1; } for(;;){ rbytes = tcp_recv_pack(cfd,buffer,sizeof(buffer)); if (rbytes == -1){ DEBUG_INFO("[ERROR]: %s ",strerror(errno)); return -1; }else if (rbytes == 0){ DEBUG_INFO("[INFO] : The client has been shut down.\n"); break; }else if (rbytes > 0){ wbytes = write(fd,buffer,rbytes); if (wbytes != rbytes){ DEBUG_INFO("[ERROR] : Failed to write data.\n"); return -1; } file_size += rbytes; if (file_size == targetsize) break; } } close(fd); return file_size; } //文件上傳接口 int client_upload_file(int cfd) { int ret; char *filename; size_t filesize = 0,recvsize = 0; file_protocol_t head; ret = recv_protocol_head(cfd,&head); if (ret == -1) return -1; filename = head.filename; filesize = head.filesize; recvsize = recv_filedata(cfd,filename,filesize); printf("Recv %%%d\n",(int)(recvsize * 1.0 / filesize) * 100); return recvsize; } //協(xié)議頭 發(fā)送接口 int send_protocol_head(const char *filename,int sockfd) { int fd; int filesize; int ret; file_protocol_t head; fd = open(filename,O_RDONLY); if (fd == -1){ DEBUG_INFO("[ERROR] Failed to open filename.\n"); return -1; } filesize = lseek(fd,0,SEEK_END); close(fd); head.filesize = filesize; strcpy(head.filename,filename); ret = tcp_send_pack(sockfd,&head,sizeof(head)); if (ret != sizeof(file_protocol_t)){ DEBUG_INFO("[ERROR] Failed to send protocol head.\n"); return -1; } return filesize; } //文件上傳發(fā)送 int upload_file(const char *filename,int sockfd) { int file_size,upload_size; int fd; ssize_t rbytes = 0,sbytes = 0; char buffer[1024] = {0}; file_size = send_protocol_head(filename,sockfd); if (file_size < 0){ return -1; } fd = open(filename,O_RDONLY); if (fd == -1){ DEBUG_INFO("[ERROR] Failed to open filename.\n"); return -1; } for(;;){ rbytes = read(fd,buffer,sizeof(buffer)); if (rbytes == -1){ DEBUG_INFO("[ERROR] Failed to read data.\n"); return -1; } sbytes = tcp_send_pack(sockfd,buffer,rbytes); if (sbytes != rbytes){ DEBUG_INFO("[ERROR] Failed to send data.\n"); return -1; } upload_size += rbytes; } close(fd); return upload_size; } file_transfer.h #ifndef __FILE_TRANSFER_H_ #define __FILE_TRANSFER_H #include "tcp_socket.h" #include #include #include #define FILENAME_SZ 256 typedef struct file_protocol{ size_t filesize; // 文件大小 char filename[FILENAME_SZ]; // 文件名 }file_protocol_t; extern int recv_protocol_head(int cfd,file_protocol_t *p_head); extern int recv_filedata(int cfd,const char *filename,size_t targetsize); extern int client_upload_file(int cfd); extern int send_protocol_head(const char *filename,int sockfd); extern int upload_file(const char *filename,int sockfd); #endif

得分 100
學習任務

北城半夏4806197 的學生作業(yè):

file_transfer.c #include"file_transfer.h" #include"debug.h" //接收協(xié)議頭 int recv_protocol_head(int cfd,file_protocol_t *p_head) { ssize_t rbytes; ssize_t total_received = 0; char *buffer = (char *)p_head;// 按照字節(jié)流接收 // 進行循環(huán)接收,防止 tcp 粘包 for(;;){ //接收數(shù)據(jù) rbytes = tcp_recv_pack(cfd,buffer + total_received,sizeof(file_protocol_t) - total_received); if (rbytes == -1){ DEBUG_INFO("[ERROR]: %s ",strerror(errno)); return -1; }else if (rbytes == 0){ DEBUG_INFO("[INFO] : The client has been shut down.\n"); break; }else if (rbytes > 0){ total_received += rbytes; if (total_received == sizeof(file_protocol_t)) // 接收固定長度的數(shù)據(jù) break; } } if (total_received != sizeof(file_protocol_t)){ DEBUG_INFO("[ERROR] : Failed to receive data.\n"); return -1; } return 0; } //接收文件數(shù)據(jù) int recv_filedata(int cfd,const char *filename,size_t targetsize) { int fd; ssize_t rbytes = 0,wbytes = 0,file_size = 0; char buffer[1024] = {0}; DEBUG_INFO("[INFO] : filename %s\n",filename); fd = open(filename,O_WRONLY|O_CREAT|O_TRUNC,0666); if (fd == -1){ DEBUG_INFO("[ERROR] Failed to open filename.\n"); return -1; } for(;;){ rbytes = tcp_recv_pack(cfd,buffer,sizeof(buffer)); if (rbytes == -1){ DEBUG_INFO("[ERROR]: %s ",strerror(errno)); return -1; }else if (rbytes == 0){ DEBUG_INFO("[INFO] : The client has been shut down.\n"); break; }else if (rbytes > 0){ wbytes = write(fd,buffer,rbytes); if (wbytes != rbytes){ DEBUG_INFO("[ERROR] : Failed to write data.\n"); return -1; } file_size += rbytes; if (file_size == targetsize) break; } } close(fd); return file_size; } //文件上傳接口 int client_upload_file(int cfd) { int ret; char *filename; size_t filesize = 0,recvsize = 0; file_protocol_t head; ret = recv_protocol_head(cfd,&head); if (ret == -1) return -1; filename = head.filename; filesize = head.filesize; recvsize = recv_filedata(cfd,filename,filesize); printf("Recv %%%d\n",(int)(recvsize * 1.0 / filesize) * 100); return recvsize; } //協(xié)議頭發(fā)送接口 int send_protocol_head(const char *filename,int sockfd) { int fd; int filesize; int ret; file_protocol_t head; fd = open(filename,O_RDONLY); if (fd == -1){ DEBUG_INFO("[ERROR] Failed to open filename.\n"); return -1; } filesize = lseek(fd,0,SEEK_END); close(fd); head.filesize = filesize; strcpy(head.filename,filename); ret = tcp_send_pack(sockfd,&head,sizeof(head)); if (ret != sizeof(file_protocol_t)){ DEBUG_INFO("[ERROR] Failed to send protocol head.\n"); return -1; } return filesize; } file_transfer.h #ifndef __FILE_TRANSFER_H_ #define __FILE_TRANSFER_H #include "tcp_socket.h" #include #include #include #define FILENAME_SZ 256 typedef struct file_protocol{ size_t filesize; // 文件大小 char filename[FILENAME_SZ]; // 文件名 }file_protocol_t; extern int recv_protocol_head(int cfd,file_protocol_t *p_head); extern int recv_filedata(int cfd,const char *filename,size_t targetsize); extern int client_upload_file(int cfd); extern int send_protocol_head(const char *filename,int sockfd); #endif

得分 100
學習任務

北城半夏4806197 的學生作業(yè):

file_transfer.c #include"file_transfer.h" #include"debug.h" //接收協(xié)議頭 int recv_protocol_head(int cfd,file_protocol_t *p_head) { ssize_t rbytes; ssize_t total_received = 0; char *buffer = (char *)p_head;// 按照字節(jié)流接收 // 進行循環(huán)接收,防止 tcp 粘包 for(;;){ //接收數(shù)據(jù) rbytes = tcp_recv_pack(cfd,buffer + total_received,sizeof(file_protocol_t) - total_received); if (rbytes == -1){ DEBUG_INFO("[ERROR]: %s ",strerror(errno)); return -1; }else if (rbytes == 0){ DEBUG_INFO("[INFO] : The client has been shut down.\n"); break; }else if (rbytes > 0){ total_received += rbytes; if (total_received == sizeof(file_protocol_t)) // 接收固定長度的數(shù)據(jù) break; } } if (total_received != sizeof(file_protocol_t)){ DEBUG_INFO("[ERROR] : Failed to receive data.\n"); return -1; } return 0; } //接收文件數(shù)據(jù) int recv_filedata(int cfd,const char *filename,size_t targetsize) { int fd; ssize_t rbytes = 0,wbytes = 0,file_size = 0; char buffer[1024] = {0}; DEBUG_INFO("[INFO] : filename %s\n",filename); fd = open(filename,O_WRONLY|O_CREAT|O_TRUNC,0666); if (fd == -1){ DEBUG_INFO("[ERROR] Failed to open filename.\n"); return -1; } for(;;){ rbytes = tcp_recv_pack(cfd,buffer,sizeof(buffer)); if (rbytes == -1){ DEBUG_INFO("[ERROR]: %s ",strerror(errno)); return -1; }else if (rbytes == 0){ DEBUG_INFO("[INFO] : The client has been shut down.\n"); break; }else if (rbytes > 0){ wbytes = write(fd,buffer,rbytes); if (wbytes != rbytes){ DEBUG_INFO("[ERROR] : Failed to write data.\n"); return -1; } file_size += rbytes; if (file_size == targetsize) break; } } close(fd); return file_size; } //文件上傳接口 int client_upload_file(int cfd) { int ret; char *filename; size_t filesize = 0,recvsize = 0; file_protocol_t head; ret = recv_protocol_head(cfd,&head); if (ret == -1) return -1; filename = head.filename; filesize = head.filesize; recvsize = recv_filedata(cfd,filename,filesize); printf("Recv %%%d\n",(int)(recvsize * 1.0 / filesize) * 100); return recvsize; } flie_transfer.h #ifndef __FILE_TRANSFER_H_ #define __FILE_TRANSFER_H #include "tcp_socket.h" #include #include #include #define FILENAME_SZ 256 typedef struct file_protocol{ size_t filesize; // 文件大小 char filename[FILENAME_SZ]; // 文件名 }file_protocol_t; extern int recv_protocol_head(int cfd,file_protocol_t *p_head); extern int recv_filedata(int cfd,const char *filename,size_t targetsize); extern int client_upload_file(int cfd); #endif

得分 100
學習任務

北城半夏4806197 的學生作業(yè):

file_transfer.c #include"file_transfer.h" #include"debug.h" //接收協(xié)議頭 int recv_protocol_head(int cfd,file_protocol_t *p_head) { ssize_t rbytes; ssize_t total_received = 0; char *buffer = (char *)p_head;// 按照字節(jié)流接收 // 進行循環(huán)接收,防止 tcp 粘包 for(;;){ //接收數(shù)據(jù) rbytes = tcp_recv_pack(cfd,buffer + total_received,sizeof(file_protocol_t) - total_received); if (rbytes == -1){ DEBUG_INFO("[ERROR]: %s ",strerror(errno)); return -1; }else if (rbytes == 0){ DEBUG_INFO("[INFO] : The client has been shut down.\n"); break; }else if (rbytes > 0){ total_received += rbytes; if (total_received == sizeof(file_protocol_t)) // 接收固定長度的數(shù)據(jù) break; } } if (total_received != sizeof(file_protocol_t)){ DEBUG_INFO("[ERROR] : Failed to receive data.\n"); return -1; } return 0; } //接收文件數(shù)據(jù) int recv_filedata(int cfd,const char *filename,size_t targetsize) { int fd; ssize_t rbytes = 0,wbytes = 0,file_size = 0; char buffer[1024] = {0}; DEBUG_INFO("[INFO] : filename %s\n",filename); fd = open(filename,O_WRONLY|O_CREAT|O_TRUNC,0666); if (fd == -1){ DEBUG_INFO("[ERROR] Failed to open filename.\n"); return -1; } for(;;){ rbytes = tcp_recv_pack(cfd,buffer,sizeof(buffer)); if (rbytes == -1){ DEBUG_INFO("[ERROR]: %s ",strerror(errno)); return -1; }else if (rbytes == 0){ DEBUG_INFO("[INFO] : The client has been shut down.\n"); break; }else if (rbytes > 0){ wbytes = write(fd,buffer,rbytes); if (wbytes != rbytes){ DEBUG_INFO("[ERROR] : Failed to write data.\n"); return -1; } file_size += rbytes; if (file_size == targetsize) break; } } close(fd); return file_size; } file_transfer.h #ifndef __FILE_TRANSFER_H_ #define __FILE_TRANSFER_H #include "tcp_socket.h" #include #include #include #define FILENAME_SZ 256 typedef struct file_protocol{ size_t filesize; // 文件大小 char filename[FILENAME_SZ]; // 文件名 }file_protocol_t; extern int recv_protocol_head(int cfd,file_protocol_t *p_head); extern int recv_filedata(int cfd,const char *filename,size_t targetsize); #endif

得分 100
學習任務

慕神4583458 的學生作業(yè):

#include #include #include #define MAX 3 //實際學?的存儲 struct student { char name[20]; int id; int age; }; typedef struct student datatype_t; typedef struct{ datatype_t buf[MAX]; //定義數(shù)組記錄班級學?每個學?的信息。 int n; //學?實際到來的個數(shù)。 }seqlist_t; seqlist_t *create_empty_seqlist() { seqlist_t *l = NULL; l = (seqlist_t *)malloc(sizeof(seqlist_t)); if (NULL == l) { printf("malloc is fail\r\n"); return NULL; } memset(l, 0, sizeof(seqlist_t)); l->n = 0; return l; } int is_full_seqlist(seqlist_t *l) { return l->n == MAX ? 1 : 0; } void insert_data_seqlist(seqlist_t *l,datatype_t data) { datatype_t *p = &l->buf[l->n++]; strcpy(p->name, data.name); p->id = data.id; p->age = data.age; }; void printf_data_seqlist(seqlist_t *l) { int i; printf("name\tid\tage\t\r\n"); for (i = 0; i < l->n; i++) { printf("%s\t%d\t%d\t\r\n", l->buf[i].name, l->buf[i].id, l->buf[i].age); } } int is_empty_seqlist(seqlist_t *l) { return l->n == 0 ? 1 : 0; } int delete_data_seqlist(seqlist_t *l, int id) { if (is_empty_seqlist(l) || !l) { printf("the seqlist is empty\n"); return -1; } int i = 0, j = 0; for (i = 0; i < l->n; i++) { if (l->buf[i].id != id) { memcpy(&l->buf[j], &l->buf[i], sizeof(datatype_t)); j++; } } if (i == j) return -2; l->n = j; return 0; } int main() { printf("please input student's info, name id age\r\n"); seqlist_t *s_p = create_empty_seqlist(); datatype_t data; while(!is_full_seqlist(s_p)) { scanf("%s%d%d", data.name, &data.id, &data.age); insert_data_seqlist(s_p, data); } printf_data_seqlist(s_p); printf("please input delete student id\n"); int delete_id; scanf("%d", &delete_id); if (delete_data_seqlist(s_p, delete_id) < 0) { printf("seq is empty or data not exist\n"); } else { printf("delete success\n"); printf_data_seqlist(s_p); } } 【圖片】

微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號