Class: HTTPX::Plugins::StreamBidi::Signal

Inherits:
Object
  • Object
show all
Defined in:
lib/httpx/plugins/stream_bidi.rb

Overview

Proxy to wake up the session main loop when one of the connections has buffered data to write. It abides by the HTTPX::_Selectable API, which allows it to be registered in the selector alongside actual HTTP-based HTTPX::Connection objects.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSignal

Returns a new instance of Signal.



122
123
124
125
126
# File 'lib/httpx/plugins/stream_bidi.rb', line 122

def initialize
  @closed = false
  @error = nil
  @pipe_read, @pipe_write = IO.pipe
end

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



120
121
122
# File 'lib/httpx/plugins/stream_bidi.rb', line 120

def error
  @error
end

Instance Method Details

#callObject



145
146
147
148
149
# File 'lib/httpx/plugins/stream_bidi.rb', line 145

def call
  return if @closed

  @pipe_read.readpartial(1)
end

#handle_socket_timeout(interval) ⇒ Object

noop (the owner connection will take of it)



171
# File 'lib/httpx/plugins/stream_bidi.rb', line 171

def handle_socket_timeout(interval); end

#interestsObject



151
152
153
154
155
# File 'lib/httpx/plugins/stream_bidi.rb', line 151

def interests
  return if @closed

  :r
end

#log(&_) ⇒ Object

noop



133
# File 'lib/httpx/plugins/stream_bidi.rb', line 133

def log(**, &_); end

#on_error(error) ⇒ Object



165
166
167
168
# File 'lib/httpx/plugins/stream_bidi.rb', line 165

def on_error(error)
  @error = error
  terminate
end

#stateObject



128
129
130
# File 'lib/httpx/plugins/stream_bidi.rb', line 128

def state
  @closed ? :closed : :open
end

#terminateObject



159
160
161
162
163
# File 'lib/httpx/plugins/stream_bidi.rb', line 159

def terminate
  @pipe_write.close
  @pipe_read.close
  @closed = true
end

#timeoutObject



157
# File 'lib/httpx/plugins/stream_bidi.rb', line 157

def timeout; end

#to_ioObject



135
136
137
# File 'lib/httpx/plugins/stream_bidi.rb', line 135

def to_io
  @pipe_read.to_io
end

#wakeupObject



139
140
141
142
143
# File 'lib/httpx/plugins/stream_bidi.rb', line 139

def wakeup
  return if @closed

  @pipe_write.write("\0")
end