[asterisk-commits] tilghman: branch tilghman/ast_select r281684 - /team/tilghman/ast_select/chan...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Aug 10 18:21:18 CDT 2010


Author: tilghman
Date: Tue Aug 10 18:21:14 2010
New Revision: 281684

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=281684
Log:
Change some channel drivers over to use poll() instead of select()

Modified:
    team/tilghman/ast_select/channels/chan_alsa.c
    team/tilghman/ast_select/channels/chan_misdn.c
    team/tilghman/ast_select/channels/chan_oss.c

Modified: team/tilghman/ast_select/channels/chan_alsa.c
URL: http://svnview.digium.com/svn/asterisk/team/tilghman/ast_select/channels/chan_alsa.c?view=diff&rev=281684&r1=281683&r2=281684
==============================================================================
--- team/tilghman/ast_select/channels/chan_alsa.c (original)
+++ team/tilghman/ast_select/channels/chan_alsa.c Tue Aug 10 18:21:14 2010
@@ -277,34 +277,21 @@
 
 static void *sound_thread(void *unused)
 {
-	ast_fdset rfds;
-	ast_fdset wfds;
-	int max, res;
+	struct pollfd pfd[3] = { { sndcmd[0], POLLIN }, { writedev, 0 }, { readdev, 0 } };
+	int res;
 
 	for (;;) {
-		FD_ZERO(&rfds);
-		FD_ZERO(&wfds);
-		max = sndcmd[0];
-		FD_SET(sndcmd[0], &rfds);
-		if (cursound > -1) {
-			FD_SET(writedev, &wfds);
-			if (writedev > max)
-				max = writedev;
-		}
+		pfd[1].events = cursound > -1 ? POLLOUT : 0;
 #ifdef ALSA_MONITOR
-		if (!alsa.owner) {
-			FD_SET(readdev, &rfds);
-			if (readdev > max)
-				max = readdev;
-		}
-#endif
-		res = ast_select(max + 1, &rfds, &wfds, NULL, NULL);
+		pfd[2].events = !alsa.owner ? POLLIN : 0;
+#endif
+		res = ast_poll(pfd, 3, -1);
 		if (res < 1) {
-			ast_log(LOG_WARNING, "select failed: %s\n", strerror(errno));
+			ast_log(LOG_WARNING, "poll() failed: %s\n", strerror(errno));
 			continue;
 		}
 #ifdef ALSA_MONITOR
-		if (FD_ISSET(readdev, &rfds)) {
+		if (pfd[2].revents & POLLIN) {
 			/* Keep the pipe going with read audio */
 			snd_pcm_state_t state;
 			short buf[FRAME_SIZE];
@@ -329,7 +316,7 @@
 				alsa_monitor_read((char *) buf, r * 2);
 		}
 #endif
-		if (FD_ISSET(sndcmd[0], &rfds)) {
+		if (pfd[0].revents & POLLIN) {
 			if (read(sndcmd[0], &cursound, sizeof(cursound)) < 0) {
 				ast_log(LOG_WARNING, "read() failed: %s\n", strerror(errno));
 			}
@@ -337,9 +324,11 @@
 			offset = 0;
 			sampsent = 0;
 		}
-		if (FD_ISSET(writedev, &wfds))
-			if (send_sound())
+		if (pfd[1].revents & POLLOUT) {
+			if (send_sound()) {
 				ast_log(LOG_WARNING, "Failed to write sound\n");
+			}
+		}
 	}
 	/* Never reached */
 	return NULL;

Modified: team/tilghman/ast_select/channels/chan_misdn.c
URL: http://svnview.digium.com/svn/asterisk/team/tilghman/ast_select/channels/chan_misdn.c?view=diff&rev=281684&r1=281683&r2=281684
==============================================================================
--- team/tilghman/ast_select/channels/chan_misdn.c (original)
+++ team/tilghman/ast_select/channels/chan_misdn.c Tue Aug 10 18:21:14 2010
@@ -2763,9 +2763,8 @@
 static struct ast_frame *misdn_read(struct ast_channel *ast)
 {
 	struct chan_list *tmp;
-	ast_fdset rrfs;
-	struct timeval tv;
 	int len, t;
+	struct pollfd pfd = { -1, POLLIN };
 
 	if (!ast) {
 		chan_misdn_log(1, 0, "misdn_read called without ast\n");
@@ -2781,30 +2780,23 @@
 		return NULL;
 	}
 
-	tv.tv_sec=0;
-	tv.tv_usec=20000;
-
-	FD_ZERO(&rrfs);
-	FD_SET(tmp->pipe[0],&rrfs);
-
-	t = ast_select(tmp->pipe[0] + 1, &rrfs, NULL, NULL, &tv);
+	pfd.fd = tmp->pipe[0];
+	t = ast_poll(&pfd, 1, 20);
+
+	if (t < 0) {
+		chan_misdn_log(-1, tmp->bc->port, "poll() error (err=%s)\n", strerror(errno));
+		return NULL;
+	}
 
 	if (!t) {
-		chan_misdn_log(3, tmp->bc->port, "read Select Timed out\n");
-		len=160;
-	}
-
-	if (t<0) {
-		chan_misdn_log(-1, tmp->bc->port, "Select Error (err=%s)\n",strerror(errno));
-		return NULL;
-	}
-
-	if (FD_ISSET(tmp->pipe[0],&rrfs)) {
-		len=read(tmp->pipe[0],tmp->ast_rd_buf,sizeof(tmp->ast_rd_buf));
-
-		if (len<=0) {
+		chan_misdn_log(3, tmp->bc->port, "poll() timed out\n");
+		len = 160;
+	} else if (pfd.revents & POLLIN) {
+		len = read(tmp->pipe[0], tmp->ast_rd_buf, sizeof(tmp->ast_rd_buf));
+
+		if (len <= 0) {
 			/* we hangup here, since our pipe is closed */
-			chan_misdn_log(2,tmp->bc->port,"misdn_read: Pipe closed, hanging up\n");
+			chan_misdn_log(2, tmp->bc->port, "misdn_read: Pipe closed, hanging up\n");
 			return NULL;
 		}
 
@@ -4910,26 +4902,22 @@
 			if (ch->ast) 
 				ast_queue_frame(ch->ast, &frame);
 		} else {
-			ast_fdset wrfs;
-			struct timeval tv = { 0, 0 };
+			struct pollfd pfd = { ch->pipe[1], POLLOUT };
 			int t;
 
-			FD_ZERO(&wrfs);
-			FD_SET(ch->pipe[1], &wrfs);
-
-			t = ast_select(ch->pipe[1] + 1, NULL, &wrfs, NULL, &tv);
+			t = ast_poll(&pfd, 1, 0);
+
+			if (t < 0) {
+				chan_misdn_log(-1, bc->port, "poll() error (err=%s)\n", strerror(errno));
+				break;
+			}
 
 			if (!t) {
-				chan_misdn_log(9, bc->port, "Select Timed out\n");
+				chan_misdn_log(9, bc->port, "poll() timed out\n");
 				break;
 			}
-			
-			if (t < 0) {
-				chan_misdn_log(-1, bc->port, "Select Error (err=%s)\n", strerror(errno));
-				break;
-			}
-			
-			if (FD_ISSET(ch->pipe[1], &wrfs)) {
+
+			if (pfd.revents & POLLOUT) {
 				chan_misdn_log(9, bc->port, "writing %d bytes to asterisk\n", bc->bframe_len);
 				if (write(ch->pipe[1], bc->bframe, bc->bframe_len) <= 0) {
 					chan_misdn_log(0, bc->port, "Write returned <=0 (err=%s) --> hanging up channel\n", strerror(errno));

Modified: team/tilghman/ast_select/channels/chan_oss.c
URL: http://svnview.digium.com/svn/asterisk/team/tilghman/ast_select/channels/chan_oss.c?view=diff&rev=281684&r1=281683&r2=281684
==============================================================================
--- team/tilghman/ast_select/channels/chan_oss.c (original)
+++ team/tilghman/ast_select/channels/chan_oss.c Tue Aug 10 18:21:14 2010
@@ -604,38 +604,32 @@
 	if (read(o->sounddev, ign, sizeof(ign)) < 0) {
 	}
 	for (;;) {
-		ast_fdset rfds, wfds;
-		int maxfd, res;
+		int res;
+		struct pollfd pfd[2] = { { o->sndcmd[0], POLLIN }, { o->sounddev, 0 } };
 
 		pthread_testcancel();
 
-		FD_ZERO(&rfds);
-		FD_ZERO(&wfds);
-		FD_SET(o->sndcmd[0], &rfds);
-		maxfd = o->sndcmd[0];	/* pipe from the main process */
-		if (o->cursound > -1 && o->sounddev < 0)
+		if (o->cursound > -1 && o->sounddev < 0) {
 			setformat(o, O_RDWR);	/* need the channel, try to reopen */
-		else if (o->cursound == -1 && o->owner == NULL)
+		} else if (o->cursound == -1 && o->owner == NULL) {
 			setformat(o, O_CLOSE);	/* can close */
+		}
 		if (o->sounddev > -1) {
 			if (!o->owner) {	/* no one owns the audio, so we must drain it */
-				FD_SET(o->sounddev, &rfds);
-				maxfd = MAX(o->sounddev, maxfd);
+				pfd[1].events |= POLLIN;
 			}
 			if (o->cursound > -1) {
-				FD_SET(o->sounddev, &wfds);
-				maxfd = MAX(o->sounddev, maxfd);
+				pfd[1].events |= POLLOUT;
 			}
 		}
-		/* ast_select emulates linux behaviour in terms of timeout handling */
-		res = ast_select(maxfd + 1, &rfds, &wfds, NULL, NULL);
+		res = ast_poll(pfd, 2, -1);
 		pthread_testcancel();
 		if (res < 1) {
-			ast_log(LOG_WARNING, "select failed: %s\n", strerror(errno));
+			ast_log(LOG_WARNING, "poll() failed: %s\n", strerror(errno));
 			sleep(1);
 			continue;
 		}
-		if (FD_ISSET(o->sndcmd[0], &rfds)) {
+		if (pfd[0].revents & POLLIN) {
 			/* read which sound to play from the pipe */
 			int i, what = -1;
 
@@ -656,11 +650,13 @@
 				ast_log(LOG_WARNING, "invalid sound index: %d\n", what);
 		}
 		if (o->sounddev > -1) {
-			if (FD_ISSET(o->sounddev, &rfds))	/* read and ignore errors */
+			if (pfd[1].revents & POLLIN) {	/* read and ignore errors */
 				if (read(o->sounddev, ign, sizeof(ign)) < 0) {
 				}
-			if (FD_ISSET(o->sounddev, &wfds))
+			}
+			if (pfd[1].revents & POLLOUT) {
 				send_sound(o);
+			}
 		}
 	}
 	return NULL;				/* Never reached */




More information about the asterisk-commits mailing list