mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-02 19:16:15 +00:00
More select/poll updates for various applications
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@2762 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -84,11 +84,10 @@ static int mp3play(char *filename, int fd)
|
||||
static int timed_read(int fd, void *data, int datalen)
|
||||
{
|
||||
int res;
|
||||
fd_set fds;
|
||||
struct timeval tv = { 2, 0 }; /* Wait no more than 2 seconds */
|
||||
FD_ZERO(&fds);
|
||||
FD_SET(fd, &fds);
|
||||
res = ast_select(fd + 1, &fds, NULL, NULL, &tv);
|
||||
struct pollfd fds[1];
|
||||
fds[0].fd = fd;
|
||||
fds[0].events = POLLIN;
|
||||
res = poll(fds, 1, 2000);
|
||||
if (res < 1) {
|
||||
ast_log(LOG_NOTICE, "Selected timed out/errored out with %d\n", res);
|
||||
return -1;
|
||||
@@ -146,7 +145,7 @@ static int mp3_exec(struct ast_channel *chan, void *data)
|
||||
res = -1;
|
||||
break;
|
||||
}
|
||||
if (ms) {
|
||||
if (ms > 40) {
|
||||
f = ast_read(chan);
|
||||
if (!f) {
|
||||
ast_log(LOG_DEBUG, "Null frame == hangup() detected\n");
|
||||
@@ -161,6 +160,15 @@ static int mp3_exec(struct ast_channel *chan, void *data)
|
||||
}
|
||||
ast_frfree(f);
|
||||
} else {
|
||||
#if 0
|
||||
{
|
||||
static struct timeval last;
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
printf("Since last: %ld\n", (tv.tv_sec - last.tv_sec) * 1000 + (tv.tv_usec - last.tv_usec) / 1000);
|
||||
last = tv;
|
||||
}
|
||||
#endif
|
||||
res = timed_read(fds[0], myf.frdata, sizeof(myf.frdata));
|
||||
if (res > 0) {
|
||||
myf.f.frametype = AST_FRAME_VOICE;
|
||||
@@ -182,7 +190,10 @@ static int mp3_exec(struct ast_channel *chan, void *data)
|
||||
res = 0;
|
||||
break;
|
||||
}
|
||||
ms = res / 16;
|
||||
ms += res / 16;
|
||||
#if 0
|
||||
printf("Next: %d\n", ms);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Asterisk -- A telephony toolkit for Linux.
|
||||
*
|
||||
* Silly application to play an NBScat file -- uses mpg123
|
||||
* Silly application to play an NBScat file -- uses nbscat8k
|
||||
*
|
||||
* Copyright (C) 1999, Mark Spencer
|
||||
*
|
||||
@@ -71,11 +71,10 @@ static int NBScatplay(int fd)
|
||||
static int timed_read(int fd, void *data, int datalen)
|
||||
{
|
||||
int res;
|
||||
fd_set fds;
|
||||
struct timeval tv = { 2, 0 }; /* Wait no more than 2 seconds */
|
||||
FD_ZERO(&fds);
|
||||
FD_SET(fd, &fds);
|
||||
res = ast_select(fd + 1, &fds, NULL, NULL, &tv);
|
||||
struct pollfd fds[1];
|
||||
fds[0].fd = fd;
|
||||
fds[0].events = POLLIN;
|
||||
res = poll(fds, 1, 2000);
|
||||
if (res < 1) {
|
||||
ast_log(LOG_NOTICE, "Selected timed out/errored out with %d\n", res);
|
||||
return -1;
|
||||
@@ -129,7 +128,7 @@ static int NBScat_exec(struct ast_channel *chan, void *data)
|
||||
res = -1;
|
||||
break;
|
||||
}
|
||||
if (ms) {
|
||||
if (ms > 40) {
|
||||
f = ast_read(chan);
|
||||
if (!f) {
|
||||
ast_log(LOG_DEBUG, "Null frame == hangup() detected\n");
|
||||
@@ -165,7 +164,7 @@ static int NBScat_exec(struct ast_channel *chan, void *data)
|
||||
res = 0;
|
||||
break;
|
||||
}
|
||||
ms = res / 16;
|
||||
ms += res / 16;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -40,7 +40,6 @@
|
||||
#include <asterisk/lock.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/wait.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
@@ -594,7 +594,7 @@ int ast_softhangup_nolock(struct ast_channel *chan, int cause)
|
||||
/* Inform channel driver that we need to be hung up, if it cares */
|
||||
chan->_softhangup |= cause;
|
||||
ast_queue_frame(chan, &f);
|
||||
/* Interrupt any select call or such */
|
||||
/* Interrupt any poll call or such */
|
||||
if (chan->blocking)
|
||||
pthread_kill(chan->blocker, SIGURG);
|
||||
return res;
|
||||
|
2
pbx.c
2
pbx.c
@@ -305,7 +305,7 @@ static struct pbx_builtin {
|
||||
{ "SetLanguage", pbx_builtin_setlanguage,
|
||||
"Sets user language",
|
||||
" SetLanguage(language): Set the channel language to 'language'. This\n"
|
||||
"information is used for the generation of numbers, and to select a natural\n"
|
||||
"information is used for the generation of numbers, and to choose a natural\n"
|
||||
"language file when available. For example, if language is set to 'fr' and\n"
|
||||
"the file 'demo-congrats' is requested to be played, if the file 'fr/demo-\n"
|
||||
"congrats' exists, then it will play that file, and if not will play the\n"
|
||||
|
@@ -61,7 +61,7 @@ static void *autodial(void *ignore)
|
||||
char * sendbufptr=sendbuf;
|
||||
int fd=open(dialfile,O_RDONLY|O_NONBLOCK);
|
||||
int flags = fcntl(fd, F_GETFL);
|
||||
fd_set fds;
|
||||
struct pollfd fds[1];
|
||||
fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
|
||||
if (option_debug)
|
||||
ast_log(LOG_DEBUG, "Entered Wil-Calu fd=%d\n",fd);
|
||||
@@ -77,9 +77,9 @@ static void *autodial(void *ignore)
|
||||
void *pass;
|
||||
|
||||
memset(buf,0,257);
|
||||
FD_ZERO(&fds);
|
||||
FD_SET(fd, &fds);
|
||||
ast_select(fd + 1, &fds, NULL, NULL, NULL);
|
||||
fds[0].fd = fd;
|
||||
fds[0].events = POLLIN;
|
||||
poll(fds, 1, -1);
|
||||
bytes=read(fd,buf,256);
|
||||
buf[(int)bytes]=0;
|
||||
|
||||
|
Reference in New Issue
Block a user