From f95875a105566b1b81b2c8120e7fb7f5b0a840df Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Tue, 24 Jun 2008 15:30:54 +0200 Subject: 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. --- lib/rbot/ircsocket.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib/rbot') 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 -- cgit v1.2.3