Even better: check a flag to see if we should timeout.

This commit is contained in:
dcp1990 2005-06-13 01:17:46 +00:00
parent 415f87a910
commit e4d5da109e
2 changed files with 8 additions and 1 deletions

View File

@ -49,6 +49,7 @@ int main(argc, argv)
usage(strdup(*argv));
return -2;
}
cf.modem_tm = 0;
cf.loglevels = LL_ALL;
pthread_mutex_unlock(&cfmx);
initialize();

View File

@ -53,9 +53,11 @@ int modemfd;
unsigned int cou = 0;
char buffer[512];
short doing_cid = 0;
extern struct conf cf;
pthread_t modemth;
pthread_mutex_t modemmx = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t buffermx = PTHREAD_MUTEX_INITIALIZER;
extern pthread_mutex_t cfmx;
void stmod(const char* str)
{
pthread_mutex_lock(&modemmx);
@ -174,15 +176,19 @@ void *modem_io(k)
fd_set fds;
struct timeval tv;
char cbuf[1];
short dotm = 0;
k = 0;
*cbuf = '\0'; cbuf[1] = '\0';
pthread_mutex_lock(&modemmx);
for(;;) {
pthread_mutex_lock(&cfmx);
dotm = cf.modem_tm;
pthread_mutex_unlock(&cfmx);
FD_ZERO(&fds);
FD_SET(modemfd, &fds);
tv.tv_sec = 2; /* tunable */
tv.tv_usec = 0;
switch(select(modemfd + 1, &fds, NULL, NULL, &tv)) {
switch(select(modemfd + 1, &fds, NULL, NULL, dotm ? &tv : NULL)) {
case -1:
lprintf(error, "select on modem: %s", strerror(errno));
pthread_mutex_unlock(&modemmx);