Class: Ebb::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/ebb.rb,
ext/ebb_ffi.c

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.reset_responsesObject



101
102
103
# File 'lib/ebb.rb', line 101

def self.reset_responses
  @@responses = {} # used for memory management :|
end

.responsesObject



105
106
107
# File 'lib/ebb.rb', line 105

def self.responses
  @@responses
end

Instance Method Details

#append_request(req) ⇒ Object

called from c



114
115
116
# File 'lib/ebb.rb', line 114

def append_request(req)
  @requests.push req
end

#on_closeObject



124
125
126
127
128
129
# File 'lib/ebb.rb', line 124

def on_close
  # garbage collection ! 
  @requests.each { |req| req.connection = nil }
  responses.each { |res| res.connection = nil }
  @@responses.delete(self)
end

#on_openObject



118
119
120
121
122
# File 'lib/ebb.rb', line 118

def on_open
  @being_written = nil
  @requests = []
  @@responses[self] = []
end

#on_writableObject

called after FFI::connection_write if complete



146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/ebb.rb', line 146

def on_writable
  @being_written = nil
  return unless res = responses.first
  if res.finished?
    responses.shift
    if res.last 
      FFI::connection_schedule_close(self) 
      return
    end
  end 
  write
end

#responsesObject



109
110
111
# File 'lib/ebb.rb', line 109

def responses
  @@responses[self]
end

#writeObject



135
136
137
138
139
140
141
142
143
# File 'lib/ebb.rb', line 135

def write
  return if writing?
  return unless res = responses.first
  return if res.output.empty?
  # NOTE: connection_write does not buffer!
  chunk = res.output.shift
  @being_written = chunk # need to store this so ruby doesn't gc it
  FFI::connection_write(self, chunk) 
end

#writing?Boolean

Returns:

  • (Boolean)


131
132
133
# File 'lib/ebb.rb', line 131

def writing?
  ! @being_written.nil?
end