Even better: check a flag to see if we should timeout.
This commit is contained in:
parent
415f87a910
commit
e4d5da109e
2 changed files with 8 additions and 1 deletions
|
@ -49,6 +49,7 @@ int main(argc, argv)
|
||||||
usage(strdup(*argv));
|
usage(strdup(*argv));
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
cf.modem_tm = 0;
|
||||||
cf.loglevels = LL_ALL;
|
cf.loglevels = LL_ALL;
|
||||||
pthread_mutex_unlock(&cfmx);
|
pthread_mutex_unlock(&cfmx);
|
||||||
initialize();
|
initialize();
|
||||||
|
|
|
@ -53,9 +53,11 @@ int modemfd;
|
||||||
unsigned int cou = 0;
|
unsigned int cou = 0;
|
||||||
char buffer[512];
|
char buffer[512];
|
||||||
short doing_cid = 0;
|
short doing_cid = 0;
|
||||||
|
extern struct conf cf;
|
||||||
pthread_t modemth;
|
pthread_t modemth;
|
||||||
pthread_mutex_t modemmx = PTHREAD_MUTEX_INITIALIZER;
|
pthread_mutex_t modemmx = PTHREAD_MUTEX_INITIALIZER;
|
||||||
pthread_mutex_t buffermx = PTHREAD_MUTEX_INITIALIZER;
|
pthread_mutex_t buffermx = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
extern pthread_mutex_t cfmx;
|
||||||
void stmod(const char* str)
|
void stmod(const char* str)
|
||||||
{
|
{
|
||||||
pthread_mutex_lock(&modemmx);
|
pthread_mutex_lock(&modemmx);
|
||||||
|
@ -174,15 +176,19 @@ void *modem_io(k)
|
||||||
fd_set fds;
|
fd_set fds;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
char cbuf[1];
|
char cbuf[1];
|
||||||
|
short dotm = 0;
|
||||||
k = 0;
|
k = 0;
|
||||||
*cbuf = '\0'; cbuf[1] = '\0';
|
*cbuf = '\0'; cbuf[1] = '\0';
|
||||||
pthread_mutex_lock(&modemmx);
|
pthread_mutex_lock(&modemmx);
|
||||||
for(;;) {
|
for(;;) {
|
||||||
|
pthread_mutex_lock(&cfmx);
|
||||||
|
dotm = cf.modem_tm;
|
||||||
|
pthread_mutex_unlock(&cfmx);
|
||||||
FD_ZERO(&fds);
|
FD_ZERO(&fds);
|
||||||
FD_SET(modemfd, &fds);
|
FD_SET(modemfd, &fds);
|
||||||
tv.tv_sec = 2; /* tunable */
|
tv.tv_sec = 2; /* tunable */
|
||||||
tv.tv_usec = 0;
|
tv.tv_usec = 0;
|
||||||
switch(select(modemfd + 1, &fds, NULL, NULL, &tv)) {
|
switch(select(modemfd + 1, &fds, NULL, NULL, dotm ? &tv : NULL)) {
|
||||||
case -1:
|
case -1:
|
||||||
lprintf(error, "select on modem: %s", strerror(errno));
|
lprintf(error, "select on modem: %s", strerror(errno));
|
||||||
pthread_mutex_unlock(&modemmx);
|
pthread_mutex_unlock(&modemmx);
|
||||||
|
|
Loading…
Reference in a new issue