From 7eea6525a795fc7372384bb05270dbd65ed308d9 Mon Sep 17 00:00:00 2001 From: Jason Greene Date: Tue, 22 Jul 2003 07:20:55 +0000 Subject: [PATCH] Fix EINVAL errors for OS's (Solaris + BSD) that do not appreciate microseconds >= 1 second Patch submitted from meebery@php.net --- ext/sockets/sockets.c | 12 ++++++++++-- ext/standard/streamsfuncs.c | 12 ++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/ext/sockets/sockets.c b/ext/sockets/sockets.c index 9b1d3ad0d8..c45ff687f2 100644 --- a/ext/sockets/sockets.c +++ b/ext/sockets/sockets.c @@ -641,8 +641,16 @@ PHP_FUNCTION(socket_select) convert_to_long(&tmp); sec = &tmp; } - tv.tv_sec = Z_LVAL_P(sec); - tv.tv_usec = usec; + + /* Solaris + BSD do not like microsecond values which are >= 1 sec */ + if (usec > 999999) { + tv.tv_sec = Z_LVAL_P(sec) + (usec / 1000000); + tv.tv_usec = usec % 1000000; + } else { + tv.tv_sec = Z_LVAL_P(sec); + tv.tv_usec = usec; + } + tv_p = &tv; if (sec == &tmp) { diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c index 74d7701d2d..e6db9e8138 100644 --- a/ext/standard/streamsfuncs.c +++ b/ext/standard/streamsfuncs.c @@ -563,8 +563,16 @@ PHP_FUNCTION(stream_select) /* If seconds is not set to null, build the timeval, else we wait indefinitely */ if (sec != NULL) { convert_to_long_ex(&sec); - tv.tv_sec = Z_LVAL_P(sec); - tv.tv_usec = usec; + + /* Solaris + BSD do not like microsecond values which are >= 1 sec */ + if (usec > 999999) { + tv.tv_sec = Z_LVAL_P(sec) + (usec / 1000000); + tv.tv_usec = usec % 1000000; + } else { + tv.tv_sec = Z_LVAL_P(sec); + tv.tv_usec = usec; + } + tv_p = &tv; } -- 2.40.0