summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNiklas Halle <niklas@niklashalle.net>2020-06-07 13:02:54 +0200
committerNiklas Halle <niklas@niklashalle.net>2020-06-07 13:02:54 +0200
commit896cc4c94ee319b64be0a4c543e936d99d172515 (patch)
tree00e78cf2063a7750a45b1148bde25bd978555122
parent9629104f494a441681fd28295f98531682875fc7 (diff)
downloadbetriebssysteme-896cc4c94ee319b64be0a4c543e936d99d172515.tar.gz
betriebssysteme-896cc4c94ee319b64be0a4c543e936d99d172515.zip
works better? maybe?
-rwxr-xr-x03_exercise/cli/clientbin28360 -> 28360 bytes
-rw-r--r--03_exercise/cli/client.c14
-rw-r--r--03_exercise/testbin4 -> 5 bytes
3 files changed, 10 insertions, 4 deletions
diff --git a/03_exercise/cli/client b/03_exercise/cli/client
index 34d1d01..0935c2b 100755
--- a/03_exercise/cli/client
+++ b/03_exercise/cli/client
Binary files differ
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
index eb1ae45..b4098bc 100644
--- a/03_exercise/test
+++ b/03_exercise/test
Binary files differ