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

ruby-changes:38164

From: nobu <ko1@a...>
Date: Sun, 12 Apr 2015 09:24:29 +0900 (JST)
Subject: [ruby-changes:38164] nobu:r50245 (trunk): wait.c: get_timeout

nobu	2015-04-12 09:24:12 +0900 (Sun, 12 Apr 2015)

  New Revision: 50245

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

  Log:
    wait.c: get_timeout
    
    * ext/io/wait/wait.c (get_timeout): extract function to get
      timeout value.

  Modified files:
    trunk/ext/io/wait/wait.c
Index: ext/io/wait/wait.c
===================================================================
--- ext/io/wait/wait.c	(revision 50244)
+++ ext/io/wait/wait.c	(revision 50245)
@@ -44,6 +44,20 @@ static VALUE io_wait_readable _((int arg https://github.com/ruby/ruby/blob/trunk/ext/io/wait/wait.c#L44
 static VALUE io_wait_writable _((int argc, VALUE *argv, VALUE io));
 void Init_wait _((void));
 
+static struct timeval *
+get_timeout(int argc, VALUE *argv, struct timeval *timerec)
+{
+    VALUE timeout = Qnil;
+    rb_check_arity(argc, 0, 1);
+    if (!argc || NIL_P(timeout = argv[0])) {
+	return NULL;
+    }
+    else {
+	*timerec = rb_time_interval(timeout);
+	return timerec;
+    }
+}
+
 /*
  * call-seq:
  *   io.nread -> int
@@ -109,21 +123,12 @@ io_wait_readable(int argc, VALUE *argv, https://github.com/ruby/ruby/blob/trunk/ext/io/wait/wait.c#L123
     rb_io_t *fptr;
     int i;
     ioctl_arg n;
-    VALUE timeout;
     struct timeval timerec;
     struct timeval *tv;
 
     GetOpenFile(io, fptr);
     rb_io_check_readable(fptr);
-    rb_scan_args(argc, argv, "01", &timeout);
-    if (NIL_P(timeout)) {
-	tv = NULL;
-    }
-    else {
-	timerec = rb_time_interval(timeout);
-	tv = &timerec;
-    }
-
+    tv = get_timeout(argc, argv, &timerec);
     if (rb_io_read_pending(fptr)) return Qtrue;
     if (!FIONREAD_POSSIBLE_P(fptr->fd)) return Qfalse;
     i = rb_wait_for_single_fd(fptr->fd, RB_WAITFD_IN, tv);
@@ -148,21 +153,12 @@ io_wait_writable(int argc, VALUE *argv, https://github.com/ruby/ruby/blob/trunk/ext/io/wait/wait.c#L153
 {
     rb_io_t *fptr;
     int i;
-    VALUE timeout;
     struct timeval timerec;
     struct timeval *tv;
 
     GetOpenFile(io, fptr);
     rb_io_check_writable(fptr);
-    rb_scan_args(argc, argv, "01", &timeout);
-    if (NIL_P(timeout)) {
-	tv = NULL;
-    }
-    else {
-	timerec = rb_time_interval(timeout);
-	tv = &timerec;
-    }
-
+    tv = get_timeout(argc, argv, &timerec);
     i = rb_wait_for_single_fd(fptr->fd, RB_WAITFD_OUT, tv);
     if (i < 0)
 	rb_sys_fail(0);

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

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