diff options
-rwxr-xr-x | 03_exercise/cli/client | bin | 28360 -> 28360 bytes | |||
-rw-r--r-- | 03_exercise/cli/client.c | 14 | ||||
-rw-r--r-- | 03_exercise/test | bin | 4 -> 5 bytes |
3 files changed, 10 insertions, 4 deletions
diff --git a/03_exercise/cli/client b/03_exercise/cli/client Binary files differindex 34d1d01..0935c2b 100755 --- a/03_exercise/cli/client +++ b/03_exercise/cli/client diff --git a/03_exercise/cli/client.c b/03_exercise/cli/client.c index 052dabd..e5f2f84 100644 --- a/03_exercise/cli/client.c +++ b/03_exercise/cli/client.c @@ -55,14 +55,20 @@ void send_file(int server_fd, char *path) { memset(buffer, 0, BUF_SIZE); int tmp_fd, file_fd; - if ((tmp_fd = open(path, O_RDONLY)) == -1) { perror("Open"); } + if ((tmp_fd = open(path, O_RDONLY)) == -1) { + perror("Open"); + return; + } FILE *file = fdopen(tmp_fd, "r"); fseek(file, 0L, SEEK_END); long int sz = ftell(file); fseek(file, 0L, SEEK_SET); fclose(file); close(tmp_fd); - if ((file_fd = open(path, O_RDONLY)) == -1) { perror("Open"); } + if ((file_fd = open(path, O_RDONLY)) == -1) { + perror("Open"); + return; + } int length = snprintf(NULL, 0, "%ld", sz); sprintf(buffer, "<<!%ld!", sz); @@ -98,7 +104,6 @@ int parse(int server_sock, char *buffer, ssize_t length) { if (strlen(path) == 0) { fprintf(stderr, "path missing\n"); } else { - printf("got put with %s\n", path); send_file(sock, path); } return CONTINUE; @@ -145,7 +150,7 @@ int main() { pid_t pid = fork(); int done = 0; - if (pid != 0) { + if (pid == 0) { read_stdin(&done); } else { read_server_sock(&done); @@ -181,6 +186,7 @@ void read_stdin(int *done) { if ((length = read(STDIN_FILENO, stdinp_buffer, BUF_SIZE)) > 0) { switch (parse(sock, stdinp_buffer, length)) { case CONTINUE: + printf("$> "); continue; case BREAK: *done = 1; diff --git a/03_exercise/test b/03_exercise/test Binary files differindex eb1ae45..b4098bc 100644 --- a/03_exercise/test +++ b/03_exercise/test |