lib/rb-kqueue/watcher/read_write.rb in rb-kqueue-0.0.2 vs lib/rb-kqueue/watcher/read_write.rb in rb-kqueue-0.0.3

- old
+ new

@@ -7,10 +7,17 @@ # and write events are watched via {Queue#watch_stream_for_write}. # # Note that read and write events for sockets # use the {SocketReadWrite} class. class ReadWrite < Watcher + # The Ruby IO object from which the file descriptor was extracted. + # This is only set if an IO object was used to construct this watcher. + # Otherwise, it's `nil`. + # + # @return [IO, nil] + attr_reader :io + # The file descriptor for the stream being watched. # # @return [Fixnum] attr_reader :fd @@ -21,9 +28,14 @@ # Creates a new read/write Watcher. # # @private def initialize(queue, fd, type, callback) + if fd.is_a?(IO) + @io = fd + fd = fd.fileno + end + @fd = fd @type = type super(queue, @fd, type, [], nil, callback) end end