diff options
author | Thomas White <taw@physics.org> | 2021-06-21 22:44:31 +0200 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2021-06-21 22:45:16 +0200 |
commit | 63f708e2ef4525e9e38a7d6cb7140910a718cbac (patch) | |
tree | 89e892fc3e80e1ee08194b45403791fffd361c66 /src/repl-connection.c | |
parent | a460a40e9eed7519def796be8c7fab605465c421 (diff) |
Fixture display: Shut down REPL connection gracefully at exit
This avoids horrible spew on the main thread REPL (leaving only minor
spew instead).
Diffstat (limited to 'src/repl-connection.c')
-rw-r--r-- | src/repl-connection.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/repl-connection.c b/src/repl-connection.c index a159c0b..7d68d25 100644 --- a/src/repl-connection.c +++ b/src/repl-connection.c @@ -129,6 +129,21 @@ static void input_ready(GObject *source, GAsyncResult *res, gpointer vp) char *remaining; len = g_input_stream_read_finish(G_INPUT_STREAM(source), res, &error); + + if ( len == 0 ) { + printf("%p: EOF\n", repl); + g_object_unref(repl->conn); + repl->conn = NULL; + return; + } + + if ( len == -1 ) { + printf("%p: Error: %s\n", repl, error->message); + g_object_unref(repl->conn); + repl->conn = NULL; + return; + } + repl->inbuf[len] = '\0'; for ( i=0; i<len; i++ ) { @@ -220,3 +235,15 @@ int repl_send(ReplConnection *repl, const char *line) } return 0; } + + +int repl_closed(ReplConnection *repl) +{ + return repl->conn == NULL; +} + + +void repl_connection_close(ReplConnection *repl) +{ + repl_send(repl, ",q"); +} |