1
0
mirror of https://github.com/fumiama/simple-kanban.git synced 2026-06-05 00:10:29 +08:00

fix client

This commit is contained in:
源文雨
2023-11-08 18:07:58 +09:00
parent 5bc6279ee4
commit adc400aee4

View File

@@ -24,15 +24,19 @@ struct sockaddr_in their_addr;
pthread_t thread;
uint32_t file_size;
int recv_bin = 0;
FILE* fp;
static void __attribute__((destructor)) defer_close_fp() {
if (fp) fclose(fp);
}
void getMessage(void *p) {
int c, i;
while((c = recv(sockfd, bufr, BUFSIZ, 0)) > 0) {
printf("Recv %u bytes: ", c);
if(recv_bin) {
FILE* fp = fopen("dump.bin", "w+");
if(fp == NULL) fp = fopen("dump.bin", "w+");
fwrite(bufr, c, 1, fp);
fclose(fp);
} else for(i = 0; i < c; i++) putchar(bufr[i]);
putchar('\n');
}