mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-04-27 04:50:59 +00:00
fs_cli: use nanosleep
This commit is contained in:
parent
e0db2c0e10
commit
5d1e95021c
@ -13,9 +13,9 @@
|
|||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
#include <sys/select.h>
|
#include <sys/select.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <time.h>
|
||||||
#else
|
#else
|
||||||
#define strdup(src) _strdup(src)
|
#define strdup(src) _strdup(src)
|
||||||
#define usleep(time) Sleep(time/1000)
|
|
||||||
#define fileno _fileno
|
#define fileno _fileno
|
||||||
#define read _read
|
#define read _read
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
@ -74,6 +74,25 @@ static EditLine *el;
|
|||||||
static History *myhistory;
|
static History *myhistory;
|
||||||
static HistEvent ev;
|
static HistEvent ev;
|
||||||
|
|
||||||
|
static void _sleep_ns(int secs, long nsecs) {
|
||||||
|
#ifndef WIN32
|
||||||
|
if (nsecs > 999999999) {
|
||||||
|
secs += nsecs/1000000000;
|
||||||
|
nsecs = nsecs % 1000000000;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
struct timespec ts = { secs, nsecs };
|
||||||
|
nanosleep(&ts, NULL);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
Sleep(secs*1000 + nsecs/1000000);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static void sleep_ns(long nsecs) { _sleep_ns(0, nsecs); }
|
||||||
|
static void sleep_ms(int msecs) { sleep_ns(msecs*1000000); }
|
||||||
|
static void sleep_s(int secs) { _sleep_ns(secs, 0); }
|
||||||
|
|
||||||
static int process_command(esl_handle_t *handle, const char *cmd);
|
static int process_command(esl_handle_t *handle, const char *cmd);
|
||||||
|
|
||||||
/* If a fnkey is configured then process the command */
|
/* If a fnkey is configured then process the command */
|
||||||
@ -599,7 +618,7 @@ static void *msg_thread_run(esl_thread_t *me, void *obj)
|
|||||||
if (aok) printf("Type control-D or /exit or /quit or /bye to exit.\n\n");
|
if (aok) printf("Type control-D or /exit or /quit or /bye to exit.\n\n");
|
||||||
warn_stop = 0;
|
warn_stop = 0;
|
||||||
}
|
}
|
||||||
usleep(1000);
|
sleep_ms(1);
|
||||||
}
|
}
|
||||||
thread_running = 0;
|
thread_running = 0;
|
||||||
esl_log(ESL_LOG_DEBUG, "Thread Done\n");
|
esl_log(ESL_LOG_DEBUG, "Thread Done\n");
|
||||||
@ -733,7 +752,7 @@ static const char *basic_gets(int *cnt)
|
|||||||
command_buf[0] = 0;
|
command_buf[0] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Sleep(20);
|
sleep_ms(20);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return command_buf;
|
return command_buf;
|
||||||
@ -1103,11 +1122,7 @@ int main(int argc, char *argv[])
|
|||||||
if (!argv_exec) usage(argv[0]);
|
if (!argv_exec) usage(argv[0]);
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
#ifndef WIN32
|
sleep_s(1);
|
||||||
sleep(1);
|
|
||||||
#else
|
|
||||||
Sleep(1000);
|
|
||||||
#endif
|
|
||||||
esl_log(ESL_LOG_INFO, "Retrying\n");
|
esl_log(ESL_LOG_INFO, "Retrying\n");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -1242,7 +1257,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
usleep(1000);
|
sleep_ms(1);
|
||||||
}
|
}
|
||||||
if (running < 0 && reconnect) {
|
if (running < 0 && reconnect) {
|
||||||
running = 1;
|
running = 1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user