Class: Gopher::Connection

Inherits:
EM::Connection
  • Object
show all
Defined in:
lib/gopher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#appObject

Returns the value of attribute app.



253
254
255
# File 'lib/gopher.rb', line 253

def app
  @app
end

Instance Method Details

#receive_data(data) ⇒ Object



255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# File 'lib/gopher.rb', line 255

def receive_data(data)
  begin
    raise InvalidRequest if data.length > 255
    response = app.request(data)        
    case response
    when String then send_data(response)
    when StringIO then send_data(response.read)
    when File
      while chunk = response.read(8192) do
        send_data(chunk)
      end
    end
    close_connection_after_writing
  rescue Gopher::NotFound
    send_data "not found"
    close_connection_after_writing
  rescue => e
    close_connection
    raise e
  end
end