diff options
author | 2019-05-21 20:04:23 +0300 | |
---|---|---|
committer | 2019-05-21 20:04:23 +0300 | |
commit | 92dbb5804e65b9802cdb8e788e6a7503d31a89e8 (patch) | |
tree | acdb2e5f4fa463060fbf004f22b362fb1cbd7e30 /src | |
parent | b24fdd90aee29a5e6362be5d8f061f7cbd500052 (diff) | |
download | usurpation-92dbb5804e65b9802cdb8e788e6a7503d31a89e8.tar.gz usurpation-92dbb5804e65b9802cdb8e788e6a7503d31a89e8.tar.bz2 usurpation-92dbb5804e65b9802cdb8e788e6a7503d31a89e8.zip |
daemon: implemented stdio interfaces
Signed-off-by: Paulius Ratkevičius <pauliuz95@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/daemon/proto_stdio.c | 54 | ||||
-rw-r--r-- | src/daemon/proto_stdio_private.h | 3 |
2 files changed, 52 insertions, 5 deletions
diff --git a/src/daemon/proto_stdio.c b/src/daemon/proto_stdio.c index ee4af9a..35fd467 100644 --- a/src/daemon/proto_stdio.c +++ b/src/daemon/proto_stdio.c @@ -2,6 +2,7 @@ * Usurpation – null (stdio) im proto * * Copyright (C) 2019 Gediminas Jakutis + * Copyright (C) 2019 Paulius Ratkevičius * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -22,18 +23,63 @@ #include "proto_stdio.h" #include "proto_stdio_private.h" -/* TODO: stub! */ + +void message_receive(char *arg) +{ + int done = 0; + while(!done) + { + pthread_mutex_lock(&state.out_m); + if(!state.writebuf) + { + state.writebuf = strdup(arg); + done = 1; + } + pthread_mutex_unlock(&state.out_m); + } +} + +char * message_send(void) +{ + char * ret; + pthread_mutex_lock(&state.out_m); + ret = strdup(state.writebuf); + free(state.writebuf); + state.writebuf = NULL; + pthread_mutex_unlock(&state.out_m); + return ret; +} + static void *read_stdin(void *arg) { - return arg; + while(1) + { + pthread_mutex_lock(&state.in_m); + if(!state.readbuf) + { + state.readbufsize = getline(&state.readbuf,NULL, stdin); + } + pthread_mutex_unlock(&state.in_m); + } } -/* TODO: stub! */ + static void *write_stdout(void *arg) { - return arg; + while(1) + { + pthread_mutex_lock(&state.out_m); + if(state.writebuf) + { + printf("%s", state.writebuf); + free(state.writebuf); + state.writebuf = NULL; + } + pthread_mutex_unlock(&state.out_m); + } } + int proto_stdio_init(void) { diff --git a/src/daemon/proto_stdio_private.h b/src/daemon/proto_stdio_private.h index bed159b..1fa48d4 100644 --- a/src/daemon/proto_stdio_private.h +++ b/src/daemon/proto_stdio_private.h @@ -2,7 +2,7 @@ * Usurpation – null (stdio) im proto * * Copyright (C) 2019 Gediminas Jakutis - * + * Copyright (C) 2019 Paulius Ratkevičius * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; version 2.1 @@ -21,6 +21,7 @@ #ifndef USURPATION_PROTO_STDIO_PRIVATE_H #define USURPATION_PROTO_STDIO_PRIVATE_H +#include <stdio.h> #include <sys/types.h> #include <pthread.h> |