0001-thread.c-rb_thread_select-mark-original-fd_sets-prop.patch

Eric Wong, 09/11/2011 09:30 AM

Download (3.43 KB)

View differences:

ext/-test-/old_thread_select/old_thread_select.c
25 25
    return fds;
26 26
}
27 27

  
28
static void fdset2array(VALUE dst, fd_set *fds, int max)
29
{
30
    int i;
31

  
32
    rb_ary_clear(dst);
33

  
34
    for (i = 0; i < max; i++) {
35
	if (FD_ISSET(i, fds))
36
	    rb_ary_push(dst, INT2NUM(i));
37
    }
38
}
39

  
28 40
static VALUE
29 41
old_thread_select(VALUE klass, VALUE r, VALUE w, VALUE e, VALUE timeout)
30 42
{
......
45 57
    rc = rb_thread_select(max, rp, wp, ep, tvp);
46 58
    if (rc == -1)
47 59
	rb_sys_fail("rb_wait_for_single_fd");
60

  
61
    if (rp)
62
	fdset2array(r, &rfds, max);
63
    if (wp)
64
	fdset2array(w, &wfds, max);
65
    if (ep)
66
	fdset2array(e, &efds, max);
48 67
    return INT2NUM(rc);
49 68
}
50 69

  
test/-ext-/old_thread_select/test_old_thread_select.rb
34 34
    end
35 35
  end
36 36

  
37
  def test_old_select_false_positive
38
    bug5306 = '[ruby-core:39435]'
39
    with_pipe do |r2, w2|
40
      with_pipe do |r, w|
41
        t0 = Time.now
42
        w.syswrite '.'
43
        rfds = [ r.fileno, r2.fileno ]
44
        rc = IO.old_thread_select(rfds, nil, nil, nil)
45
        assert_equal [ r.fileno ], rfds, bug5306
46
        assert_equal 1, rc, bug5306
47
      end
48
    end
49
  end
50

  
37 51
  def test_old_select_read_write_check
38 52
    with_pipe do |r, w|
39 53
      w.syswrite('.')
thread.c
2682 2682
    return TRUE;
2683 2683
}
2684 2684

  
2685
static void rb_fd_rcopy(fd_set *dst, rb_fdset_t *src)
2686
{
2687
    size_t size = howmany(rb_fd_max(src), NFDBITS) * sizeof(fd_mask);
2688

  
2689
    if (size < sizeof(fd_set))
2690
	size = sizeof(fd_set);
2691
    memcpy(dst, rb_fd_ptr(src), size);
2692
    rb_fd_term(src);
2693
}
2694

  
2685 2695
int
2686 2696
rb_thread_select(int max, fd_set * read, fd_set * write, fd_set * except,
2687 2697
		 struct timeval *timeout)
......
2710 2720

  
2711 2721
    retval = rb_thread_fd_select(max, rfds, wfds, efds, timeout);
2712 2722

  
2713
    if (rfds)
2723
    if (rfds) {
2724
	rb_fd_rcopy(read, rfds);
2714 2725
	rb_fd_term(rfds);
2715
    if (wfds)
2726
    }
2727
    if (wfds) {
2728
	rb_fd_rcopy(write, wfds);
2716 2729
	rb_fd_term(wfds);
2717
    if (efds)
2730
    }
2731
    if (efds) {
2732
	rb_fd_rcopy(except, efds);
2718 2733
	rb_fd_term(efds);
2734
    }
2719 2735

  
2720 2736
    return retval;
2721 2737
}