]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
ircsocket.rb: use syswrite since ruby's buffered io is racy
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Tue, 24 Jun 2008 13:30:54 +0000 (15:30 +0200)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Tue, 24 Jun 2008 15:39:39 +0000 (17:39 +0200)
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.

lib/rbot/ircsocket.rb

index 2e6ff452d7f47a0685e3e7655f57cb5d8db940ae..4ac98da32d1ce7689d67b399f85286027f3fd4e2 100644 (file)
@@ -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