diff --git a/src/sexpots/sexpots.c b/src/sexpots/sexpots.c index eb18c8bd69b5b90b0cc3de33b1a53d2f1dc68037..7415d7500699c8e939c30ea1599ade2a157cb082 100644 --- a/src/sexpots/sexpots.c +++ b/src/sexpots/sexpots.c @@ -89,6 +89,7 @@ ulong com_baudrate=0; BOOL dcd_ignore=FALSE; int dcd_timeout=10; /* seconds */ ulong dtr_delay=100; /* milliseconds */ +int hangup_attempts=10; BOOL terminated=FALSE; BOOL terminate_after_one_call=FALSE; @@ -1256,24 +1257,29 @@ BOOL handle_call(void) BOOL hangup_call(COM_HANDLE com_handle) { time_t start; + int attempt; if((comGetModemStatus(com_handle)&COM_DCD)==0) /* DCD already low */ return TRUE; lprintf(LOG_DEBUG,"Waiting for transmit buffer to empty"); SLEEP(dtr_delay); - lprintf(LOG_INFO,"Dropping DTR"); - if(!comLowerDTR(com_handle)) - return FALSE; - - lprintf(LOG_INFO,"Waiting for loss of Carrier Detect (DCD)"); - start=time(NULL); - while(time(NULL)-start <= dcd_timeout) { - if((comGetModemStatus(com_handle)&COM_DCD) == 0) - return TRUE; - SLEEP(1000); + for(attempt=0; attempt<hangup_attempts; attempt++) { + lprintf(LOG_INFO,"Dropping DTR (attempt #%d)", attempt+1); + if(!comLowerDTR(com_handle)) { + lprintf(LOG_ERR,"ERROR %u lowering DTR", COM_ERROR); + continue; + } + lprintf(LOG_INFO,"Waiting for loss of Carrier Detect (DCD)"); + start=time(NULL); + while(time(NULL)-start <= dcd_timeout) { + if((comGetModemStatus(com_handle)&COM_DCD)==0) + return TRUE; + SLEEP(1000); + } + lprintf(LOG_ERR,"TIMEOUT waiting for DCD to drop (attempt #%d of %d)" + , attempt+1, hangup_attempts); } - lprintf(LOG_ERR,"TIMEOUT waiting for DCD to drop"); return FALSE; } @@ -1318,6 +1324,7 @@ void parse_ini_file(const char* ini_fname) iniGetExistingString(list, section, "Device", NULL, com_dev); com_baudrate = iniGetLongInt(list, section, "BaudRate", com_baudrate); com_hangup = iniGetBool(list, section, "Hangup", com_hangup); + hangup_attempts = iniGetInteger(list, section, "HangupAttempts", hangup_attempts); dcd_timeout = iniGetInteger(list, section, "DCDTimeout", dcd_timeout); dcd_ignore = iniGetBool(list, section, "IgnoreDCD", dcd_ignore); dtr_delay = iniGetLongInt(list, section, "DTRDelay", dtr_delay);