Project

General

Profile

Actions

Bug #745

closed

IO associates with the file descriptor, not the stream

Added by jredville (Jim Deville) over 15 years ago. Updated almost 13 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 #1

Updated by rogerdpack (Roger Pack) over 15 years ago

=begin
is this a bug or more of a design decision? [i.e. "should descriptors to the same IO all close together?" is the question].
Thanks!
-=R
=end

Actions #2

Updated by matz (Yukihiro Matsumoto) over 15 years ago

  • Status changed from Open to Rejected

=begin
I think the current behavior follows the underlying OS behavior.
When you create an IO object over a file descriptor, every operation of the IO should work on the descriptor. If you want streams work serapratedly, you should dup the descriptor explicitly.

Am I missing something?

=end

Actions

Also available in: Atom PDF

Like0
Like0Like0