Class: EventMachine::POSIX::Spawn::Child::Stream
- Inherits:
-
Connection
- Object
- Connection
- EventMachine::POSIX::Spawn::Child::Stream
- Includes:
- Deferrable
- Defined in:
- lib/em/posix/spawn/child.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#buffer ⇒ Object
readonly
Returns the value of attribute buffer.
Instance Method Summary collapse
- #close ⇒ Object
- #closed? ⇒ Boolean
- #force_encoding ⇒ Object
-
#initialize(buffer, name) ⇒ Stream
constructor
A new instance of Stream.
Constructor Details
#initialize(buffer, name) ⇒ Stream
Returns a new instance of Stream.
309 310 311 312 313 |
# File 'lib/em/posix/spawn/child.rb', line 309 def initialize(buffer, name) @buffer = buffer @name = name @closed = false end |
Instance Attribute Details
#buffer ⇒ Object (readonly)
Returns the value of attribute buffer.
307 308 309 |
# File 'lib/em/posix/spawn/child.rb', line 307 def buffer @buffer end |
Instance Method Details
#close ⇒ Object
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 |
# File 'lib/em/posix/spawn/child.rb', line 322 def close return if closed? # NB: Defer detach to the next tick, because EventMachine blows up # when a file descriptor is attached and detached in the same # tick. This can happen when the child process dies in the same # tick it started, and the `#waitpid` loop in the signal # handler picks it up afterwards. The signal handler, in turn, # queues the child's callback to the executed via # `EM#next_tick`. If the blocks queued by `EM#next_tick` are # executed after that, still in the same tick, the child's file # descriptors can be detached in the same tick they were # attached. EM.next_tick do # NB: The ordering here is important. If we're using epoll, # detach() attempts to deregister the associated fd via # EPOLL_CTL_DEL and marks the EventableDescriptor for # deletion upon completion of the iteration of the event # loop. However, if the fd was closed before calling # detach(), epoll_ctl() will sometimes return EBADFD and fail # to remove the fd. This can lead to epoll_wait() returning # an event whose data pointer is invalid (since it was # deleted in a prior iteration of the event loop). detach @io.close rescue nil end @closed = true end |
#closed? ⇒ Boolean
353 354 355 |
# File 'lib/em/posix/spawn/child.rb', line 353 def closed? @closed end |
#force_encoding ⇒ Object
315 316 317 318 319 320 |
# File 'lib/em/posix/spawn/child.rb', line 315 def force_encoding if @buffer.respond_to?(:force_encoding) @io.set_encoding('BINARY', 'BINARY') @buffer.force_encoding('BINARY') end end |