Posted: Sat Apr 26, 2003 1:56 pm Post subject: [Asterisk-Dev] Some select(2) usage Linux specific, take 2
This patch is a bit more invasive, but it does create a wrapper
ast_select for select(2) which on Linux systems just calls select,
while on other systems it will also do calculations on the passed
timeval to match what a Linux kernel does.
Note 1: Even the Linux manpage for select(2) suggests *NOT* expecting
a known value in the passed timeval after doing select.
Note 2: The POSIX definition of select(2) does *NOT* specify that
the timeval will be usable for anything after calling select
Index: asterisk.c
===================================================================
RCS file: /usr/cvsroot/asterisk/asterisk.c,v
retrieving revision 1.5
diff -u -r1.5 asterisk.c
--- asterisk.c 23 Apr 2003 20:22:14 -0000 1.5
+++ asterisk.c 26 Apr 2003 13:58:22 -0000
@@ -130,7 +130,7 @@
max = con->fd;
if (con->p[0] > max)
max = con->p[0];
- res = select(max + 1, &rfds, NULL, NULL, NULL);
+ res = ast_select(max + 1, &rfds, NULL, NULL, NULL);
if (res < 0) {
ast_log(LOG_WARNING, "select returned < 0: %s\n", strerror(errno));
continue;
@@ -672,7 +676,7 @@
max = ast_consock;
if (STDIN_FILENO > max)
max = STDIN_FILENO;
- res = select(max+1, &rfds, NULL, NULL, NULL);
+ res = ast_select(max+1, &rfds, NULL, NULL, NULL);
if (res < 0) {
if (errno == EINTR)
continue;
@@ -1369,7 +1373,7 @@
//! Waits for activity on a group of channels
/*!
+ * \param nfds the maximum number of file descriptors in the sets
+ * \param rfds file descriptors to check for read availability
+ * \param wfds file descriptors to check for write availability
+ * \param efds file descriptors to check for exceptions (OOB data)
+ * \param tvp timeout while waiting for events
+ * This is the same as a standard select(), except it guarantees the
+ * behaviour where the passed struct timeval is updated with how much
+ * time was not slept while waiting for the specified events
+ */
+int ast_select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tvp);
+
+//! Waits for activity on a group of channels
+/*!
* \param chan an array of pointers to channels
* \param n number of channels that are to be waited upon
* \param fds an array of fds to wait upon
Index: res/res_parking.c
===================================================================
RCS file: /usr/cvsroot/asterisk/res/res_parking.c,v
retrieving revision 1.2
diff -u -r1.2 res_parking.c
--- res/res_parking.c 9 Apr 2003 04:00:43 -0000 1.2
+++ res/res_parking.c 26 Apr 2003 13:59:33 -0000
@@ -443,7 +443,7 @@
tv.tv_sec = ms / 1000;
tv.tv_usec = (ms % 1000) * 1000;
/* Wait for something to happen */
- select(max + 1, &rfds, NULL, &efds, (ms > -1) ? &tv : NULL);
+ ast_select(max + 1, &rfds, NULL, &efds, (ms > -1) ? &tv : NULL);
pthread_testcancel();
}
return NULL; /* Never reached */
--
Thorsten Lockert | tholo@sigmasoft.com | Universe, n.:
2121 N. Lakeshore Dr. | tholo@openbsd.org | The problem.
Chapel Hill, NC 27514 | |
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum