[#23457] [Bug #1471] "Mutual join" deadlock detection faulty in 1.8.6 and 1.8.7 — John Carter <redmine@...>

Bug #1471: "Mutual join" deadlock detection faulty in 1.8.6 and 1.8.7

17 messages 2009/05/15

[#23483] [Bug #1478] Ruby archive — Oleg Puchinin <redmine@...>

Bug #1478: Ruby archive

29 messages 2009/05/16
[#29225] [Feature #1478] Ruby archive — Luis Lavena <redmine@...> 2010/04/02

Issue #1478 has been updated by Luis Lavena.

[#30345] Re: [Feature #1478] Ruby archive — "NAKAMURA, Hiroshi" <nakahiro@...> 2010/05/21

On Fri, Apr 2, 2010 at 17:13, Luis Lavena <redmine@ruby-lang.org> wrote:

[#30346] Re: [Feature #1478] Ruby archive — Jonathan Nielsen <jonathan@...> 2010/05/21

> Thanks for your comment.

[#30347] Re: [Feature #1478] Ruby archive — Jonathan Nielsen <jonathan@...> 2010/05/21

OK Hiroshi, I read some of the comments earlier in the thread that I

[#30355] Re: [Feature #1478] Ruby archive — Caleb Clausen <vikkous@...> 2010/05/21

On 5/20/10, Jonathan Nielsen <jonathan@jmnet.us> wrote:

[#30364] Re: [Feature #1478] Ruby archive — Benoit Daloze <eregontp@...> 2010/05/22

Hi,

[#23505] [Bug #1494] tempfile#unlink may silently fail on windows — Nicholas Manning <redmine@...>

Bug #1494: tempfile#unlink may silently fail on windows

19 messages 2009/05/19

[#23572] [Bug #1525] Deadlock in Ruby 1.9's VM caused by ConditionVariable.wait and fork? — Hongli Lai <redmine@...>

Bug #1525: Deadlock in Ruby 1.9's VM caused by ConditionVariable.wait and fork?

27 messages 2009/05/27

[#23595] Meaning of RUBY_PLATFORM — Rick DeNatale <rick.denatale@...>

The RUBY_PLATFORM constant is documented in the latest Pickaxe as "The

17 messages 2009/05/28
[#23596] Re: Meaning of RUBY_PLATFORM — Luis Lavena <luislavena@...> 2009/05/28

On Thu, May 28, 2009 at 3:41 PM, Rick DeNatale <rick.denatale@gmail.com> wrote:

[#23602] Re: Meaning of RUBY_PLATFORM — Rick DeNatale <rick.denatale@...> 2009/05/28

On Thu, May 28, 2009 at 2:52 PM, Luis Lavena <luislavena@gmail.com> wrote:

[#23608] Re: Meaning of RUBY_PLATFORM — Luis Lavena <luislavena@...> 2009/05/28

On Thu, May 28, 2009 at 7:08 PM, Rick DeNatale <rick.denatale@gmail.com> wrote:

[#23609] Re: Meaning of RUBY_PLATFORM — Rick DeNatale <rick.denatale@...> 2009/05/29

On Thu, May 28, 2009 at 7:22 PM, Luis Lavena <luislavena@gmail.com> wrote:

[ruby-core:23446] Some expect.rb miprovements

From: Luiz Angelo Daros de Luca <luizluca@...>
Date: 2009-05-13 19:07:53 UTC
List: ruby-core #23446
Hello,

I was using expect.rb to substitute expect command (as I'm not in a mood to
learn Tcl). However, it demands some attention.

I took expect(1) command as a idea, but not a rule, of how expect should
behave.

First, a little bug that incorrect pattern classes are not treated
correctly. It would result in a "e_pat unspecified" which gives no clues of
what happened. Now I raise an exception. I let the another one parameter,
timeout, unchecked cause the error messagem like "String can't be coerced
into Fixnum" would give a good hint of what is wrong.

I changed pat and e_pat to pattern to meet some other similar parameter
references.

Back to the timeout parameter, timeout was not a global timeout but a single
char timeout. If the io keeps giving input, it never stops. For example:
While using expect.rb to interact with a dlink switch telnet, if it
generates any log information on the terminal (as it does constantly like
"link down") before the timeout time, even if my expression never occurs,
the timeout is never over. I changed this to use timeout as a global timeout
as expect command does.

Keeping on timeout stuff, if it read some input and times out, where this
buffer goes? In expect.rb, it is just lost. For the expect command, this
buffer can be used in the next matching. I use a instance variable to keep
and reuse the unused buffer on the next expect call.

I changed the default timeout value to meet the expect command default one.
If someone really wants to use 9999999 seconds, just go ahead ans specify it
on parameters. However, interactive scripts generally deal with unexpected
behaviors. 30s, as expect command uses, seems to be reasonable.

I also added some documentation that was missing.

This is my first patch sent to ruby. I should submit this to
redmine.ruby-lang.org, isn't it? But which version? Contribution
documentation seems to be a litte disperse.

Cheers,

---
    Luiz Angelo Daros de Luca, Me.
           luizluca@gmail.com

Attachments (1)

expect.patch (1.74 KB, text/x-patch)
--- expect.rb.orig	2009-05-13 15:14:05.000000000 -0300
+++ expect.rb	2009-05-13 15:50:57.000000000 -0300
@@ -1,26 +1,43 @@
 $expect_verbose = false
 
 class IO
-  def expect(pat,timeout=9999999)
+
+  # Reads ios until pattern matches or the timeout is over. It returns
+  # an array with the read buffer, folowed by the matches. If a block is given,
+  # the result is yielded to the block and returns nil. The optional timeout parameter defines,
+  # in seconds, the total time to wait for pattern. If it is over of eof is found, it 
+  # returns/yields nil. However, the buffer in a timeout session is kept for the next expect call.
+  # The default timeout is 30 seconds.
+  def expect(pattern,timeout=30)
     buf = ''
-    case pat
+    case pattern
     when String
-      e_pat = Regexp.new(Regexp.quote(pat))
+      pattern = Regexp.new(Regexp.quote(pattern))
     when Regexp
-      e_pat = pat
+      #pattern = pattern
+    else
+      raise ArgumentError, "unsupported pattern class: #{pattern.class}"
     end
+    @unusedBuf = '' if not @unusedBuf
+    starttime = Time.now
     while true
-      if !IO.select([self],nil,nil,timeout) or eof? then
-        result = nil
-        break
+      if not @unusedBuf.empty?
+        c = @unusedBuf.slice!(0).chr
+      else
+        remaining = timeout-(Time.new-starttime)
+        if remaining <= 0 or !IO.select([self],nil,nil,remaining) or eof? then
+          result = nil
+          @unusedBuf = buf
+          break
+        end
+        c = getc.chr
       end
-      c = getc.chr
       buf << c
       if $expect_verbose
         STDOUT.print c
         STDOUT.flush
       end
-      if mat=e_pat.match(buf) then
+      if mat=pattern.match(buf) then
         result = [buf,*mat.to_a[1..-1]]
         break
       end

In This Thread

Prev Next