diff options
Diffstat (limited to 'src/daemon/proto_stdio.c')
-rw-r--r-- | src/daemon/proto_stdio.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/daemon/proto_stdio.c b/src/daemon/proto_stdio.c index 9aecdf0..6735746 100644 --- a/src/daemon/proto_stdio.c +++ b/src/daemon/proto_stdio.c @@ -23,7 +23,6 @@ #include "proto_stdio.h" #include "proto_stdio_private.h" - void message_receive(char *arg) { int cancelstate; @@ -37,19 +36,25 @@ void message_receive(char *arg) nanosleep(&respite, NULL); } -char *message_send(void) +struct tlv *message_send(struct tlv *in) { - char *ret = NULL; + struct tlv *ret = in; int cancelstate; pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cancelstate); pthread_mutex_lock(&state.out_m); if (state.readbuf) { - ret = strdup(state.readbuf); + tlv_init(ret, TEXT); + ret->data = malloc(state.bytes_read); + ret->head.size = state.bytes_read; + memcpy(ret->data, state.readbuf, state.bytes_read); free(state.readbuf); state.readbuf = NULL; state.readbufsize = 0; + state.bytes_read = 0; + } else { + ret = NULL; } pthread_mutex_unlock(&state.out_m); @@ -70,7 +75,7 @@ static void *read_stdin(void *arg) pthread_mutex_lock(&state.in_m); if (!state.readbuf) { - state.readbufsize = getline(&state.readbuf, NULL, stdin); + state.bytes_read = getline(&state.readbuf, &state.readbufsize, stdin); } pthread_mutex_unlock(&state.in_m); |