[Asterisk-Dev] Some select(2) usage Linux-specific
Thorsten Lockert
tholo at sigmasoft.com
Fri Apr 25 08:12:41 MST 2003
Is there much point, given that it is used all of two times in this
manner...?
Thorsten
--
Thorsten Lockert | tholo at sigmasoft.com | Universe, n.:
2121 N. Lakeshore Dr. | tholo at openbsd.org | The problem.
Chapel Hill, NC 27514 | |
-----Original Message-----
From: asterisk-dev-admin at lists.digium.com
[mailto:asterisk-dev-admin at lists.digium.com] On Behalf Of Mark Spencer
Sent: Friday, April 25, 2003 10:30
To: asterisk-dev at lists.digium.com
Subject: Re: [Asterisk-Dev] Some select(2) usage Linux-specific
How about doing a macro called ast_select which resolves to select() on
linux and an inline function to do this sort of select on non-linux
systems?
Mark
On Thu, 24 Apr 2003, Thorsten Lockert wrote:
> A couple of calls to select(2) are assuming a Linux-specific side-
> effect of the passed timeval being updated with how much time was
> left in before a timeout would occur.
>
> This patch makes this work (at the expense of two more system calls)
> on many other systems.
>
> Index: channel.c
> ===================================================================
> RCS file: /usr/cvsroot/asterisk/channel.c,v
> retrieving revision 1.11
> diff -u -r1.11 channel.c
> --- channel.c 17 Apr 2003 02:52:53 -0000 1.11
> +++ channel.c 24 Apr 2003 21:46:10 -0000
> @@ -739,6 +739,9 @@
> {
> /* Wait for x amount of time on a file descriptor to have input. */
> struct timeval tv;
> +#ifndef __linux__
> + struct timeval tvstart, tvend, tvlen;
> +#endif
> fd_set rfds, efds;
> int res;
> int x, max=-1;
> @@ -756,8 +759,23 @@
> max = fds[x];
> }
> }
> - if (*ms >= 0)
> + if (*ms >= 0) {
> +#ifndef __linux__
> + gettimeofday(&tvstart, NULL);
> +#endif
> res = select(max + 1, &rfds, NULL, &efds, &tv);
> +#ifndef __linux__
> + gettimeofday(&tvend, NULL);
> + timersub(&tvend, &tvstart, &tvlen);
> + tvend.tv_sec = *ms / 1000;
> + tvend.tv_usec = (*ms % 1000) * 1000;
> + timersub(&tvend, &tvlen, &tv);
> + if (tv.tv_sec < 0 || tv.tv_usec < 0) {
> + tv.tv_sec = 0;
> + tv.tv_usec = 0;
> + }
> +#endif
> + }
> else
> res = select(max + 1, &rfds, NULL, &efds, NULL);
>
> @@ -786,6 +804,9 @@
> {
> /* Wait for x amount of time on a file descriptor to have input. */
> struct timeval tv;
> +#ifndef __linux__
> + struct timeval tvstart, tvend, tvlen;
> +#endif
> fd_set rfds, efds;
> int res;
> int x, y, max=-1;
> @@ -828,8 +849,23 @@
> if (fds[x] > max)
> max = fds[x];
> }
> - if (*ms >= 0)
> + if (*ms >= 0) {
> +#ifndef __linux__
> + gettimeofday(&tvstart, NULL);
> +#endif
> res = select(max + 1, &rfds, NULL, &efds, &tv);
> +#ifndef __linux__
> + gettimeofday(&tvend, NULL);
> + timersub(&tvend, &tvstart, &tvlen);
> + tvend.tv_sec = *ms / 1000;
> + tvend.tv_usec = (*ms % 1000) * 1000;
> + timersub(&tvend, &tvlen, &tv);
> + if (tv.tv_sec < 0 || tv.tv_usec < 0) {
> + tv.tv_sec = 0;
> + tv.tv_usec = 0;
> + }
> +#endif
> + }
> else
> res = select(max + 1, &rfds, NULL, &efds, NULL);
>
> --
> Thorsten Lockert | tholo at sigmasoft.com | Universe, n.:
> 2121 N. Lakeshore Dr. | tholo at openbsd.org | The problem.
> Chapel Hill, NC 27514 | |
> _______________________________________________
> Asterisk-Dev mailing list
> Asterisk-Dev at lists.digium.com
> http://lists.digium.com/mailman/listinfo/asterisk-dev
>
_______________________________________________
Asterisk-Dev mailing list
Asterisk-Dev at lists.digium.com
http://lists.digium.com/mailman/listinfo/asterisk-dev
More information about the asterisk-dev
mailing list