[前][次][番号順一覧][スレッド一覧]

ruby-changes:9752

From: shyouhei <ko1@a...>
Date: Sun, 4 Jan 2009 04:49:04 +0900 (JST)
Subject: [ruby-changes:9752] Ruby:r21290 (ruby_1_8_7): merge revision(s) 18262:

shyouhei	2009-01-04 04:46:23 +0900 (Sun, 04 Jan 2009)

  New Revision: 21290

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=21290

  Log:
    merge revision(s) 18262:
    * win32/win32.c (rb_w32_select): recalc the rest of timeout for each
      iterations.  [ruby-core:18015]

  Added files:
    branches/ruby_1_8_7/test/ruby/test_sleep.rb
  Modified files:
    branches/ruby_1_8_7/ChangeLog
    branches/ruby_1_8_7/version.h
    branches/ruby_1_8_7/win32/win32.c

Index: ruby_1_8_7/ChangeLog
===================================================================
--- ruby_1_8_7/ChangeLog	(revision 21289)
+++ ruby_1_8_7/ChangeLog	(revision 21290)
@@ -1,3 +1,8 @@
+Sun Jan  4 04:45:26 2009  Nobuyoshi Nakada  <nobu@r...>
+
+	* win32/win32.c (rb_w32_select): recalc the rest of timeout for each
+	  iterations.  [ruby-core:18015]
+
 Fri Jan  2 03:08:47 2009  Kouhei Sutou  <kou@c...>
 
 	* test/rss/: use PNG instead of zlib as binary data. [ruby-dev:35666]
Index: ruby_1_8_7/version.h
===================================================================
--- ruby_1_8_7/version.h	(revision 21289)
+++ ruby_1_8_7/version.h	(revision 21290)
@@ -1,15 +1,15 @@
 #define RUBY_VERSION "1.8.7"
-#define RUBY_RELEASE_DATE "2009-01-02"
+#define RUBY_RELEASE_DATE "2009-01-04"
 #define RUBY_VERSION_CODE 187
-#define RUBY_RELEASE_CODE 20090102
-#define RUBY_PATCHLEVEL 74
+#define RUBY_RELEASE_CODE 20090104
+#define RUBY_PATCHLEVEL 75
 
 #define RUBY_VERSION_MAJOR 1
 #define RUBY_VERSION_MINOR 8
 #define RUBY_VERSION_TEENY 7
 #define RUBY_RELEASE_YEAR 2009
 #define RUBY_RELEASE_MONTH 1
-#define RUBY_RELEASE_DAY 2
+#define RUBY_RELEASE_DAY 4
 
 #ifdef RUBY_EXTERN
 RUBY_EXTERN const char ruby_version[];
Index: ruby_1_8_7/test/ruby/test_sleep.rb
===================================================================
--- ruby_1_8_7/test/ruby/test_sleep.rb	(revision 0)
+++ ruby_1_8_7/test/ruby/test_sleep.rb	(revision 21290)
@@ -0,0 +1,10 @@
+require 'test/unit'
+
+class TestSleep < Test::Unit::TestCase
+  def test_sleep_5sec
+    start = Time.now
+    sleep 5
+    slept = Time.now-start
+    assert_in_delta(5.0, slept, 0.1, "[ruby-core:18015]: longer than expected")
+  end
+end

Property changes on: ruby_1_8_7/test/ruby/test_sleep.rb
___________________________________________________________________
Name: svn:eol-style
   + LF

Index: ruby_1_8_7/win32/win32.c
===================================================================
--- ruby_1_8_7/win32/win32.c	(revision 21289)
+++ ruby_1_8_7/win32/win32.c	(revision 21290)
@@ -2177,7 +2177,7 @@
 }
 
 static inline int
-subst(struct timeval *rest, const struct timeval *wait)
+subtract(struct timeval *rest, const struct timeval *wait)
 {
     while (rest->tv_usec < wait->tv_usec) {
 	if (rest->tv_sec <= wait->tv_sec) {
@@ -2207,8 +2207,8 @@
 
 #undef Sleep
 long 
-rb_w32_select (int nfds, fd_set *rd, fd_set *wr, fd_set *ex,
-	       struct timeval *timeout)
+rb_w32_select(int nfds, fd_set *rd, fd_set *wr, fd_set *ex,
+	      struct timeval *timeout)
 {
     long r;
     fd_set pipe_rd;
@@ -2216,11 +2216,29 @@
     fd_set else_rd;
     fd_set else_wr;
     int nonsock = 0;
+    struct timeval limit;
 
     if (nfds < 0 || (timeout && (timeout->tv_sec < 0 || timeout->tv_usec < 0))) {
 	errno = EINVAL;
 	return -1;
     }
+
+    if (timeout) {
+	if (timeout->tv_sec < 0 ||
+	    timeout->tv_usec < 0 ||
+	    timeout->tv_usec >= 1000000) {
+	    errno = EINVAL;
+	    return -1;
+	}
+	gettimeofday(&limit, NULL);
+	limit.tv_sec += timeout->tv_sec;
+	limit.tv_usec += timeout->tv_usec;
+	if (limit.tv_usec >= 1000000) {
+	    limit.tv_usec -= 1000000;
+	    limit.tv_sec++;
+	}
+    }
+
     if (!NtSocketsInitialized) {
 	StartSockets();
     }
@@ -2253,10 +2271,9 @@
 	struct timeval rest;
 	struct timeval wait;
 	struct timeval zero;
-	if (timeout) rest = *timeout;
 	wait.tv_sec = 0; wait.tv_usec = 10 * 1000; // 10ms
 	zero.tv_sec = 0; zero.tv_usec = 0;         //  0ms
-	do {
+	for (;;) {
 	    if (nonsock) {
 		// modifying {else,pipe,cons}_rd is safe because
 		// if they are modified, function returns immediately.
@@ -2272,8 +2289,7 @@
 		break;
 	    }
 	    else {
-		struct timeval *dowait =
-		    compare(&rest, &wait) < 0 ? &rest : &wait;
+		struct timeval *dowait = &wait;
 
 		fd_set orig_rd;
 		fd_set orig_wr;
@@ -2287,10 +2303,16 @@
 		if (wr) *wr = orig_wr;
 		if (ex) *ex = orig_ex;
 
-		// XXX: should check the time select spent
+		if (timeout) {
+		    struct timeval now;
+		    gettimeofday(&now, NULL);
+		    rest = limit;
+		    if (!subtract(&rest, &now)) break;
+		    if (compare(&rest, &wait) < 0) dowait = &rest;
+		}
 		Sleep(dowait->tv_sec * 1000 + dowait->tv_usec / 1000);
 	    }
-	} while (!timeout || subst(&rest, &wait));
+	}
     }
 
     return r;

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]