Class: HttpParser::Parser::DataCallback

Inherits:
FFI::Function
  • Object
show all
Defined in:
lib/http-parser/parser.rb

Class Method Summary collapse

Class Method Details

.new(&block) ⇒ Object



246
247
248
249
250
251
252
253
254
255
# File 'lib/http-parser/parser.rb', line 246

def self.new(&block)
    super(:int, [::HttpParser::Instance.ptr, :pointer, :size_t]) do |parser, buffer, length|
        begin
            data = buffer.get_bytes(0, length)
            catch(:return) { yield(parser, data); 0 }
        rescue
            -1
        end
    end
end