diff --git a/libs/esl/fs_cli.c b/libs/esl/fs_cli.c index 19e8d7f82a..a70d63fab5 100644 --- a/libs/esl/fs_cli.c +++ b/libs/esl/fs_cli.c @@ -589,22 +589,36 @@ static void *msg_thread_run(esl_thread_t *me, void *obj) while(thread_running && handle->connected) { esl_status_t status = esl_recv_event_timed(handle, 10, 1, NULL); - - if (WARN_STOP) { - printf("Type control-D or /exit or /quit or /bye to exit.\n\n"); - WARN_STOP = 0; - } + int aok = 1; if (status == ESL_FAIL) { - esl_log(ESL_LOG_WARNING, "Disconnected.\n"); + if (aok) esl_log(ESL_LOG_WARNING, "Disconnected.\n"); running = -1; thread_running = 0; } else if (status == ESL_SUCCESS) { +#ifndef WIN32 + fd_set can_write; + int fd; + struct timeval to; + + fd = fileno(stdout); + memset(&to, 0, sizeof(to)); + FD_ZERO(&can_write); + FD_SET(fd, &can_write); + to.tv_sec = 0; + to.tv_usec = 100000; + if (select(fd + 1, NULL, &can_write, NULL, &to) > 0) { + aok = FD_ISSET(fd, &can_write); + } else { + aok = 0; + } +#endif + if (handle->last_event) { const char *type = esl_event_get_header(handle->last_event, "content-type"); int known = 0; if (!esl_strlen_zero(type)) { - if (!strcasecmp(type, "log/data")) { + if (aok && !strcasecmp(type, "log/data")) { const char *userdata = esl_event_get_header(handle->last_event, "user-data"); if (esl_strlen_zero(userdata) || esl_strlen_zero(filter_uuid) || !strcasecmp(filter_uuid, userdata)) { @@ -631,7 +645,7 @@ static void *msg_thread_run(esl_thread_t *me, void *obj) } else if (!strcasecmp(type, "text/disconnect-notice")) { running = -1; thread_running = 0; known++; - } else if (!strcasecmp(type, "text/event-plain")) { + } else if (aok && !strcasecmp(type, "text/event-plain")) { char *foo; esl_event_serialize(handle->last_ievent, &foo, ESL_FALSE); printf("RECV EVENT\n%s\n", foo); @@ -641,7 +655,7 @@ static void *msg_thread_run(esl_thread_t *me, void *obj) } } - if (!known) { + if (aok && !known) { char *foo; printf("INCOMING DATA [%s]\n%s\n", type, handle->last_event->body ? handle->last_event->body : ""); esl_event_serialize(handle->last_event, &foo, ESL_FALSE); @@ -651,6 +665,11 @@ static void *msg_thread_run(esl_thread_t *me, void *obj) } } + if (WARN_STOP) { + if (aok) printf("Type control-D or /exit or /quit or /bye to exit.\n\n"); + WARN_STOP = 0; + } + usleep(1000); }