diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2008-06-24 15:30:54 +0200 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2008-06-24 17:39:39 +0200 |
commit | f95875a105566b1b81b2c8120e7fb7f5b0a840df (patch) | |
tree | 64615e0a34f688fc624ea106bee4e5128ac52378 /lib/rbot/ircsocket.rb | |
parent | 9ad6b29acc7c96c394f470f261cea7331004110b (diff) |
ircsocket.rb: use syswrite since ruby's buffered io is racy
In some situations a PRIVMSG could be output twice in sequence with no
intervening newline when using the Socket#puts function. Use syswrite to
skip Ruby's buffered IO.
Diffstat (limited to 'lib/rbot/ircsocket.rb')
-rw-r--r-- | lib/rbot/ircsocket.rb | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/rbot/ircsocket.rb b/lib/rbot/ircsocket.rb index 2e6ff452..4ac98da3 100644 --- a/lib/rbot/ircsocket.rb +++ b/lib/rbot/ircsocket.rb @@ -455,7 +455,11 @@ module Irc if @sock.nil? error "SEND attempted on closed socket" else - @sock.puts(@filter.out(message)) + # we use Socket#syswrite() instead of Socket#puts() because + # the latter is racy and can cause double message output in + # some circumstances + actual = @filter.out(message) + "\n" + @sock.syswrite actual @last_send = Time.new @flood_send += message.irc_send_penalty if penalty @lines_sent += 1 |