rhuidean 0.2.4 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,7 +14,7 @@ module IRC
14
14
  class Client
15
15
  ##
16
16
  # constants
17
- VERSION = '0.2.4'
17
+ VERSION = '0.2.5'
18
18
 
19
19
  ##
20
20
  # instance attributes
@@ -193,8 +193,8 @@ class Client
193
193
  ret = @socket.readpartial(8192)
194
194
  rescue Errno::EAGAIN
195
195
  retry
196
- rescue EOFError
197
- ret = nil
196
+ rescue Errno::ETIMEDOUT, EOFError
197
+ ret = nil # Dead
198
198
  end
199
199
 
200
200
  unless ret
@@ -349,7 +349,15 @@ class Client
349
349
 
350
350
  writefd = [@socket] unless @sendq.empty?
351
351
 
352
- ret = IO.select([@socket], writefd, [], 10)
352
+ # Ruby's threads suck. In theory, the timers should
353
+ # manage themselves in separate threads. Unfortunately,
354
+ # Ruby has a global lock and the scheduler isn't great, so
355
+ # this tells select() to timeout when the next timer needs to run.
356
+ timeout = (Timer.next_time - Time.now.to_f).round(0).to_i
357
+ timeout = 1 if timeout == 0 # Don't want 0, that's forever
358
+ timeout = 60 if timeout < 0 # Less than zero means no timers
359
+
360
+ ret = IO.select([@socket], writefd, [], timeout)
353
361
 
354
362
  next unless ret
355
363
 
@@ -464,7 +472,7 @@ class Message
464
472
  ##
465
473
  # instance attributes
466
474
  attr_reader :client, :ctcp, :origin, :params, :raw, :target
467
- attr_reader :origin_nick
475
+ attr_reader :origin_nick, :origin_user, :origin_host
468
476
 
469
477
  #
470
478
  # Creates a new Message. We use these to represent the old
@@ -476,7 +484,7 @@ class Message
476
484
 
477
485
  # Is the origin a user? Let's make this a little more simple...
478
486
  if m = ORIGIN_RE.match(@origin)
479
- @origin_nick = m[1]
487
+ @origin_nick, @origin_user, @origin_host = m[1..3]
480
488
  end
481
489
 
482
490
  # Reformat it a bit if it's a CTCP.
@@ -15,7 +15,7 @@ class Timer
15
15
 
16
16
  ##
17
17
  # instance attributes
18
- attr_reader :time, :repeat
18
+ attr_reader :time, :timeout, :repeat
19
19
 
20
20
  #
21
21
  # Creates a new timer to be executed within +10 seconds of +time+.
@@ -26,9 +26,10 @@ class Timer
26
26
  # returns:: +self+
27
27
  #
28
28
  def initialize(time, repeat = false, &block)
29
- @time = time.to_i
30
- @repeat = repeat
31
- @block = block
29
+ @time = time.to_i
30
+ @timeout = Time.now.to_f + @time
31
+ @repeat = repeat
32
+ @block = block
32
33
 
33
34
  @@timers << self
34
35
 
@@ -61,6 +62,15 @@ class Timer
61
62
  new(time, false, &block)
62
63
  end
63
64
 
65
+ #
66
+ # Returns the Unix timestamp of the next time a timer should run
67
+ # ---
68
+ # returns:: minimum timer interval, see above
69
+ #
70
+ def Timer.next_time
71
+ @@timers.collect { |t| t.timeout }.min
72
+ end
73
+
64
74
  #
65
75
  # Stops all timers.
66
76
  # ---
@@ -93,6 +103,7 @@ class Timer
93
103
  loop do
94
104
  sleep(@time)
95
105
  @block.call
106
+ @timeout = Time.now.to_f + @time if @repeat
96
107
  break unless @repeat
97
108
  end
98
109
 
data/rakefile CHANGED
@@ -10,7 +10,7 @@
10
10
  require 'rake/' + m
11
11
  end
12
12
 
13
- VER = '0.2.4'
13
+ VER = '0.2.5'
14
14
 
15
15
  #
16
16
  # Default task - unit tests.
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rhuidean
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 4
10
- version: 0.2.4
9
+ - 5
10
+ version: 0.2.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Eric Will
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-24 00:00:00 -04:00
18
+ date: 2010-10-01 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies: []
21
21