more win tweaks for t31
This commit is contained in:
parent
9c0c321890
commit
1be966ea01
|
@ -168,15 +168,19 @@ int modem_close(modem_t *modem)
|
||||||
|
|
||||||
switch_clear_flag(modem, MODEM_FLAG_RUNNING);
|
switch_clear_flag(modem, MODEM_FLAG_RUNNING);
|
||||||
|
|
||||||
if (modem->master > -1) {
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
|
if (modem->master > -1) {
|
||||||
shutdown(modem->master, 2);
|
shutdown(modem->master, 2);
|
||||||
close(modem->master);
|
close(modem->master);
|
||||||
#else
|
|
||||||
SetCommMask(modem->master, 0);
|
|
||||||
CloseHandle(modem->master);
|
|
||||||
#endif
|
|
||||||
modem->master = -1;
|
modem->master = -1;
|
||||||
|
#else
|
||||||
|
if (modem->master) {
|
||||||
|
SetEvent(modem->threadAbort);
|
||||||
|
CloseHandle(modem->threadAbort);
|
||||||
|
CloseHandle(modem->master);
|
||||||
|
modem->master = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
r++;
|
r++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -315,11 +319,14 @@ int modem_init(modem_t *modem, modem_control_handler_t control_handler)
|
||||||
timeouts.WriteTotalTimeoutConstant=50;
|
timeouts.WriteTotalTimeoutConstant=50;
|
||||||
timeouts.WriteTotalTimeoutMultiplier=10;
|
timeouts.WriteTotalTimeoutMultiplier=10;
|
||||||
|
|
||||||
|
SetCommMask(modem->master, EV_RXCHAR);
|
||||||
|
|
||||||
if(!SetCommTimeouts(modem->master, &timeouts)){
|
if(!SetCommTimeouts(modem->master, &timeouts)){
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot set up non-blocking read on %s\n", modem->devlink);
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot set up non-blocking read on %s\n", modem->devlink);
|
||||||
modem_close(modem);
|
modem_close(modem);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
modem->threadAbort = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!(modem->t31_state = t31_init(NULL, t31_at_tx_handler, modem, t31_call_control_handler, modem, NULL, NULL))) {
|
if (!(modem->t31_state = t31_init(NULL, t31_at_tx_handler, modem, t31_call_control_handler, modem, NULL, NULL))) {
|
||||||
|
@ -1167,22 +1174,19 @@ static int modem_wait_sock(int sock, uint32_t ms, modem_poll_t flags)
|
||||||
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
static int modem_wait_sock(HANDLE handle, int ms, modem_poll_t flags)
|
static int modem_wait_sock(modem_t *modem, int ms, modem_poll_t flags)
|
||||||
{
|
{
|
||||||
/* this method ignores ms and waits infinitely */
|
/* this method ignores ms and waits infinitely */
|
||||||
DWORD dwEvtMask;
|
DWORD dwEvtMask, dwWait;
|
||||||
OVERLAPPED o;
|
OVERLAPPED o;
|
||||||
BOOL result;
|
BOOL result;
|
||||||
|
int ret = MODEM_POLL_ERROR;
|
||||||
|
HANDLE arHandles[2];
|
||||||
|
|
||||||
result = SetCommMask(handle, EV_RXCHAR);
|
arHandles[0] = modem->threadAbort;
|
||||||
|
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
/* failed */
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
o.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
o.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||||
|
arHandles[1] = o.hEvent;
|
||||||
|
|
||||||
/* Initialize the rest of the OVERLAPPED structure to zero. */
|
/* Initialize the rest of the OVERLAPPED structure to zero. */
|
||||||
o.Internal = 0;
|
o.Internal = 0;
|
||||||
|
@ -1191,7 +1195,7 @@ static int modem_wait_sock(HANDLE handle, int ms, modem_poll_t flags)
|
||||||
o.OffsetHigh = 0;
|
o.OffsetHigh = 0;
|
||||||
assert(o.hEvent);
|
assert(o.hEvent);
|
||||||
|
|
||||||
result = WaitCommEvent(handle, &dwEvtMask, &o);
|
result = WaitCommEvent(modem->master, &dwEvtMask, &o);
|
||||||
|
|
||||||
if (result == 0)
|
if (result == 0)
|
||||||
{
|
{
|
||||||
|
@ -1199,19 +1203,18 @@ static int modem_wait_sock(HANDLE handle, int ms, modem_poll_t flags)
|
||||||
/* something went horribly wrong with WaitCommEvent(), so
|
/* something went horribly wrong with WaitCommEvent(), so
|
||||||
clear all errors and try again */
|
clear all errors and try again */
|
||||||
DWORD comerrors;
|
DWORD comerrors;
|
||||||
ClearCommError(handle,&comerrors,0);
|
ClearCommError(modem->master,&comerrors,0);
|
||||||
CloseHandle (o.hEvent);
|
|
||||||
} else {
|
} else {
|
||||||
/* IO is pending, wait for it to finish */
|
/* IO is pending, wait for it to finish */
|
||||||
WaitForSingleObject(o.hEvent,INFINITE);
|
dwWait = WaitForMultipleObjects(2, arHandles, FALSE, INFINITE);
|
||||||
CloseHandle (o.hEvent);
|
if (dwWait == WAIT_OBJECT_0 + 1) {
|
||||||
return MODEM_POLL_READ;
|
ret = MODEM_POLL_READ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CloseHandle (o.hEvent);
|
CloseHandle (o.hEvent);
|
||||||
return MODEM_POLL_READ;
|
return ret;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1234,7 +1237,11 @@ static void *SWITCH_THREAD_FUNC modem_thread(switch_thread_t *thread, void *obj)
|
||||||
|
|
||||||
while (switch_test_flag(modem, MODEM_FLAG_RUNNING)) {
|
while (switch_test_flag(modem, MODEM_FLAG_RUNNING)) {
|
||||||
|
|
||||||
|
#ifndef WIN32
|
||||||
r = modem_wait_sock(modem->master, -1, MODEM_POLL_READ | MODEM_POLL_ERROR);
|
r = modem_wait_sock(modem->master, -1, MODEM_POLL_READ | MODEM_POLL_ERROR);
|
||||||
|
#else
|
||||||
|
r = modem_wait_sock(modem, -1, MODEM_POLL_READ | MODEM_POLL_ERROR);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!switch_test_flag(modem, MODEM_FLAG_RUNNING)) {
|
if (!switch_test_flag(modem, MODEM_FLAG_RUNNING)) {
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -95,6 +95,7 @@ struct modem {
|
||||||
int master;
|
int master;
|
||||||
#else
|
#else
|
||||||
HANDLE master;
|
HANDLE master;
|
||||||
|
HANDLE threadAbort;
|
||||||
#endif
|
#endif
|
||||||
int slave;
|
int slave;
|
||||||
char *stty;
|
char *stty;
|
||||||
|
|
Loading…
Reference in New Issue