#497 open
Adam Gardiner

[BUG] Seek error writing to sockets and pipes

Reported by Adam Gardiner | April 15th, 2008 @ 06:19 PM | in 0.10

A seek error results on a socket when an attempt is made to write to a socket on which there is also data still to be read. On MatzRuby, no error occurs.

The exception on RBX is as follows:

    Unable to seek (ESPIPE)

Backtrace:
             IO(TCPSocket)#seek at kernel/core/io.rb:507
            IO(TCPSocket)#write at kernel/core/io.rb:490
          IO(TCPSocket)#puts {} at kernel/core/io.rb:371
                     Array#each at kernel/core/array.rb:573
             IO(TCPSocket)#puts at kernel/core/io.rb:355
              Object#__script__ at /home/ads/test_client.rb:10
       CompiledMethod#as_script at kernel/core/compiled_method.rb:326
            Compile.single_load at kernel/core/compile.rb:238
    Compile.load_from_extension at kernel/core/compile.rb:310
              Object#__script__ at kernel/loader.rb:201

The following server and client code can be used to reproduce the problem:

******* Server code *******

require 'socket'

REMOTE_DEBUG_PORT = 1098
TEST_DATA = <<-END
  Here
  is
  some
  multi-line
  data
END

port = ARGV.shift || REMOTE_DEBUG_PORT
server = TCPServer.open(port)

puts "*** waiting for client..."
socket = server.accept

puts "Sending data"
TEST_DATA.each_line {|l| socket.puts l}
socket.flush

resp = socket.gets
socket.close

******* Client code *******

require 'socket'

host = ARGV[0] || 'localhost'
port = ARGV[1] || 1098

socket = TCPSocket.new(host, port)
puts "Connected to server on #{host}:#{port}"
while line = socket.gets
  puts line
  socket.puts line
end
socket.close

Comments and changes to this ticket

Please Login or create a free account to add a new comment.

You can update this ticket by sending an email to from your email client. (help)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Tags