static HistEvent ev;
#endif
+
+static esl_mutex_t *MUTEX = NULL;
+
static void _sleep_ns(int secs, long nsecs) {
#ifndef WIN32
if (nsecs > 999999999) {
thread_running = 1;
while(thread_running && handle->connected) {
int aok = 1;
- esl_status_t status = esl_recv_event_timed(handle, 10, 1, NULL);
- if (status == ESL_FAIL) {
+ esl_status_t status;
+
+ esl_mutex_lock(MUTEX);
+ status = esl_recv_event_timed(handle, 10, 1, NULL);
+ esl_mutex_unlock(MUTEX);
+
+ if (status == ESL_BREAK) {
+ sleep_ms(1);
+ } else if (status == ESL_FAIL) {
esl_log(ESL_LOG_WARNING, "Disconnected.\n");
running = -1; thread_running = 0;
} else if (status == ESL_SUCCESS) {
static int process_command(esl_handle_t *handle, const char *cmd)
{
+ int r = 0;
+
while (*cmd == ' ') cmd++;
+ esl_mutex_lock(MUTEX);
if ((*cmd == '/' && cmd++) || !strncasecmp(cmd, "...", 3)) {
if (!strcasecmp(cmd, "help")) {
!strcasecmp(cmd, "bye")
) {
esl_log(ESL_LOG_INFO, "Goodbye!\nSee you at ClueCon http://www.cluecon.com/\n");
- return -1;
+ r = -1; goto end;
} else if (!strncasecmp(cmd, "logfilter", 9)) {
cmd += 9;
while (*cmd && *cmd == ' ') {
snprintf(cmd_str, sizeof(cmd_str), "api %s\nconsole_execute: true\n\n", cmd);
if (esl_send_recv(handle, cmd_str)) {
output_printf("Socket interrupted, bye!\n");
- return -1;
+ r = -1; goto end;
}
if (handle->last_sr_event) {
if (handle->last_sr_event->body) {
}
}
}
+
end:
- return 0;
+
+ esl_mutex_unlock(MUTEX);
+
+ return r;
}
static int get_profile(const char *name, cli_profile_t **profile)
} else {
snprintf(cmd_str, sizeof(cmd_str), "api console_complete %s\n\n", buf);
}
+
esl_send_recv(global_handle, cmd_str);
+
if (global_handle->last_sr_event && global_handle->last_sr_event->body) {
char *r = global_handle->last_sr_event->body;
char *w, *p1;
static unsigned char complete(EditLine *el, int ch)
{
const LineInfo *lf = el_line(el);
- return esl_console_complete(lf->buffer, lf->cursor, lf->lastchar);
+ int r;
+
+ esl_mutex_lock(MUTEX);
+ r = esl_console_complete(lf->buffer, lf->cursor, lf->lastchar);
+ esl_mutex_unlock(MUTEX);
+
+ return r;
}
#endif
int loops = 2, reconnect = 0;
char *ccheck;
+
+ esl_mutex_create(&MUTEX);
+
#if HAVE_DECL_EL_PROMPT_ESC
feature_level = 1;
#else
esl_disconnect(&handle);
global_handle = NULL;
thread_running = 0;
+
+ esl_mutex_destroy(&MUTEX);
+
return 0;
}