Skip to content

Instantly share code, notes, and snippets.

@trushkevich
Created March 2, 2016 13:08
Show Gist options
  • Save trushkevich/cc5b87e3b6f440738441 to your computer and use it in GitHub Desktop.
Save trushkevich/cc5b87e3b6f440738441 to your computer and use it in GitHub Desktop.

Revisions

  1. trushkevich created this gist Mar 2, 2016.
    31 changes: 31 additions & 0 deletions passenger_extension.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    module PhusionPassenger
    module Utils

    # Utility functions that can potentially be accelerated by native_support functions.
    module NativeSupportUtils
    extend self

    NULL = "\0".freeze

    class ProcessTimes < Struct.new(:utime, :stime)
    end

    def split_by_null_into_hash(data)
    args = data.split(NULL, -1)
    args.pop
    headers_hash = Hash.new
    args.each_slice(2).to_a.each do |pair|
    headers_hash[pair.first] = pair.last unless headers_hash.keys.include? pair.first
    end
    return headers_hash
    end

    def process_times
    times = Process.times
    return ProcessTimes.new((times.utime * 1_000_000).to_i,
    (times.stime * 1_000_000).to_i)
    end
    end

    end # module Utils
    end # module PhusionPassenger