Sha256: 5bad47c593e89c6a2bddda2b6f3121ef3b33cdfb39b4fa235f17a302f3e9ae7a
Contents?: true
Size: 857 Bytes
Versions: 1
Compression:
Stored size: 857 Bytes
Contents
require 'ffi-rzmq' require 'mongrel2/request' require 'mongrel2/response' module Mongrel2 class Connection CTX = ZMQ::Context.new(1) def initialize(uuid, sub, pub) @uuid, @sub, @pub = uuid, sub, pub # Connect to receive requests @reqs = CTX.socket(ZMQ::PULL) @reqs.connect(sub) # Connect to send responses @resp = CTX.socket(ZMQ::PUB) @resp.connect(pub) @resp.setsockopt(ZMQ::IDENTITY, uuid) end def recv msg = @reqs.recv_string(0) msg.nil? ? nil : Request.parse(msg) end def reply(req, body, status = 200, headers = {}) resp = Response.new(@resp) resp.send_http(req, body, status, headers) resp.close(req) if req.close? end def close # I think I should be able to just close the context CTX.close rescue nil end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rack-mongrel2-0.2.3 | lib/mongrel2/connection.rb |