aboutsummaryrefslogtreecommitdiff
path: root/client/acronc/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'client/acronc/main.c')
-rw-r--r--client/acronc/main.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/client/acronc/main.c b/client/acronc/main.c
index 6a473ed..d0e67ef 100644
--- a/client/acronc/main.c
+++ b/client/acronc/main.c
@@ -17,6 +17,7 @@
static uv_loop_t lop;
uv_loop_t *loop = &lop;
+static int current_req = -1;
static void on_close(uv_handle_t *handle);
@@ -47,6 +48,9 @@ static void on_sock_closed(void) {
}
static int on_input(ac_request_t *req) {
+ current_req = req->id;
+ stdin_stop();
+ LOGD("Stdin is paused.");
/* The socket will close itself upon errors. So do the input stream. */
return sock_request(req);
}
@@ -55,6 +59,24 @@ static int on_sock_ready(void) {
return h_stdin(on_input, on_stdin_closed);
}
+static int on_recv(ac_obj_t *obj) {
+ if (AC_IS_RESPONSE(obj->type)) {
+ ac_response_t *resp = (ac_response_t *) obj;
+ if (resp->id == current_req) {
+ if (resp->type == AC_RESPONSE_ERROR ||
+ resp->type == AC_RESPONSE_CMD_RESULT) {
+ int r = stdin_start();
+ if (r) {
+ LOGEV("Cannot resume stdin: %s", uv_strerror(r));
+ } else {
+ LOGD("Stdin is resumed.");
+ }
+ }
+ }
+ }
+ return handle_object(obj);
+}
+
static void on_resolv(int status, const struct addrinfo *ai, void (*on_connected)(bool)) {
if (status) {
uv_stop(loop);
@@ -65,7 +87,7 @@ static void on_resolv(int status, const struct addrinfo *ai, void (*on_connected
ai,
on_connected,
on_sock_ready,
- handle_object,
+ on_recv,
on_sock_closed)) {
/* Mark as true to clean up resources and prevent next retry. */
on_connected(true);