From: Giuseppe Bilotta Date: Tue, 24 Jun 2008 13:30:54 +0000 (+0200) Subject: ircsocket.rb: use syswrite since ruby's buffered io is racy X-Git-Url: https://git.netwichtig.de/gitweb/?a=commitdiff_plain;h=f95875a105566b1b81b2c8120e7fb7f5b0a840df;hp=9ad6b29acc7c96c394f470f261cea7331004110b;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git 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. --- 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