mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-03-13 04:36:42 +00:00
make windows restart while it's blocking on the console FSCORE-435
Should work in every case with 1 exception if you have started to type a command on the real console and never hit enter then do a *restart* not a shutdown, you will have to complete the command. git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@15167 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
165fdd250f
commit
a94c35366d
@ -841,15 +841,16 @@ SWITCH_DECLARE(switch_status_t) switch_console_set_complete(const char *string)
|
|||||||
SWITCH_DECLARE(void) switch_console_loop(void)
|
SWITCH_DECLARE(void) switch_console_loop(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
char cmd[2048];
|
char cmd[2048] = "";
|
||||||
int32_t activity = 1;
|
int32_t activity = 1, r;
|
||||||
switch_size_t x = 0;
|
|
||||||
|
|
||||||
gethostname(hostname, sizeof(hostname));
|
gethostname(hostname, sizeof(hostname));
|
||||||
|
|
||||||
while (running) {
|
while (running) {
|
||||||
int32_t arg;
|
int32_t arg;
|
||||||
#ifndef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
|
HANDLE stdinHandle = GetStdHandle(STD_INPUT_HANDLE);
|
||||||
|
INPUT_RECORD in[128];
|
||||||
|
#else
|
||||||
fd_set rfds, efds;
|
fd_set rfds, efds;
|
||||||
struct timeval tv = { 0, 20000 };
|
struct timeval tv = { 0, 20000 };
|
||||||
#endif
|
#endif
|
||||||
@ -863,11 +864,33 @@ SWITCH_DECLARE(void) switch_console_loop(void)
|
|||||||
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_CONSOLE, "\nfreeswitch@%s> ", hostname);
|
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_CONSOLE, "\nfreeswitch@%s> ", hostname);
|
||||||
}
|
}
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
activity = WaitForSingleObject(GetStdHandle(STD_INPUT_HANDLE), 20);
|
r = WaitForSingleObject(stdinHandle, 200);
|
||||||
|
activity = 0;
|
||||||
|
|
||||||
|
if (r == WAIT_OBJECT_0) {
|
||||||
|
DWORD bytes = 0;
|
||||||
|
DWORD read, i;
|
||||||
|
PeekConsoleInput(stdinHandle, in, 128, &read);
|
||||||
|
for (i = 0; i < read; i++) {
|
||||||
|
if (in[i].EventType == KEY_EVENT && !in[i].Event.KeyEvent.bKeyDown) {
|
||||||
|
activity = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (activity) {
|
||||||
|
char *end;
|
||||||
|
ReadConsole(stdinHandle, cmd, sizeof(cmd), &bytes, NULL);
|
||||||
|
end = end_of_p(cmd);
|
||||||
|
while(*end == '\r' || *end == '\n') {
|
||||||
|
*end-- = '\0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cmd[0]) {
|
||||||
|
running = switch_console_process(cmd, 0);
|
||||||
|
memset(cmd, 0, sizeof(cmd));
|
||||||
|
}
|
||||||
|
|
||||||
if (activity == 102) {
|
|
||||||
fflush(stdout);
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
FD_ZERO(&rfds);
|
FD_ZERO(&rfds);
|
||||||
@ -890,7 +913,7 @@ SWITCH_DECLARE(void) switch_console_loop(void)
|
|||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
memset(&cmd, 0, sizeof(cmd));
|
memset(&cmd, 0, sizeof(cmd));
|
||||||
for (x = 0; x < (sizeof(cmd) - 1); x++) {
|
for (x = 0; x < (sizeof(cmd) - 1); x++) {
|
||||||
int c = getchar();
|
int c = getchar();
|
||||||
@ -911,6 +934,7 @@ SWITCH_DECLARE(void) switch_console_loop(void)
|
|||||||
if (cmd[0]) {
|
if (cmd[0]) {
|
||||||
running = switch_console_process(cmd, 0);
|
running = switch_console_process(cmd, 0);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -1593,11 +1593,36 @@ SWITCH_DECLARE(int32_t) switch_core_session_ctl(switch_session_ctl_t cmd, int32_
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SCSC_SHUTDOWN:
|
case SCSC_SHUTDOWN:
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
{
|
||||||
|
HANDLE shutdown_event;
|
||||||
|
char path[512];
|
||||||
|
/* for windows we need the event to signal for shutting down a background FreeSWITCH */
|
||||||
|
snprintf(path, sizeof(path), "Global\\Freeswitch.%d", getpid());
|
||||||
|
|
||||||
|
/* open the event so we can signal it */
|
||||||
|
shutdown_event = OpenEvent(EVENT_MODIFY_STATE, FALSE, path);
|
||||||
|
|
||||||
|
|
||||||
|
if (shutdown_event) {
|
||||||
|
/* signal the event to shutdown */
|
||||||
|
SetEvent(shutdown_event);
|
||||||
|
/* cleanup */
|
||||||
|
CloseHandle(shutdown_event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
if (*val) {
|
if (*val) {
|
||||||
switch_set_flag((&runtime), SCF_RESTART);
|
switch_set_flag((&runtime), SCF_RESTART);
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Restarting\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Restarting\n");
|
||||||
} else {
|
} else {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Shutting down\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Shutting down\n");
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
fclose(stdin);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
runtime.running = 0;
|
runtime.running = 0;
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user