Project

General

Profile

This project is closed and read-only.

Actions

Bug #745

closed

IO associates with the file descriptor, not the stream

Bug #745: IO associates with the file descriptor, not the stream

Added by jredville (Jim Deville) almost 18 years ago. Updated over 15 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
[ruby-core:19851]

Description

=begin
When IO.new is called with a file descriptor, it is linked to the file descriptor, not the associated stream.

f = File.open("test.rb", "w") #f.to_i == 3 on windows
i = IO.new(f.to_i, "w")
f.close #file descriptor 3 is now free'd, so it can be reused
g = File.open("test2","w") # g.to_i == 3 because f was closed
i.write "foo" #the stream that i was opened on is now closed, but i is still active
i.flush

i.close #this closes the stream! Not just the FD
g.close #this throws an error, because i.close closed g's stream

This has been observed on Windows, and OS X with Ruby 1.8.6 p111. I expect i.write to fail because the stream has already been closed. If there is good reason to keep i associated with the fd, then i.close shouldn't close g.
=end

Actions

Also available in: PDF Atom