michael@0: var zlibpool = exports, michael@0: spdy = require('../spdy'); michael@0: michael@0: // michael@0: // ### function Pool () michael@0: // Zlib streams pool michael@0: // michael@0: function Pool() { michael@0: this.pool = { michael@0: 'spdy/2': [], michael@0: 'spdy/3': [] michael@0: }; michael@0: } michael@0: michael@0: // michael@0: // ### function create () michael@0: // Returns instance of Pool michael@0: // michael@0: zlibpool.create = function create() { michael@0: return new Pool(); michael@0: }; michael@0: michael@0: var x = 0; michael@0: // michael@0: // ### function get () michael@0: // Returns pair from pool or a new one michael@0: // michael@0: Pool.prototype.get = function get(version, callback) { michael@0: if (this.pool[version].length > 0) { michael@0: return this.pool[version].pop(); michael@0: } else { michael@0: var id = version.split('/', 2)[1]; michael@0: michael@0: return { michael@0: version: version, michael@0: deflate: spdy.utils.createDeflate(id), michael@0: inflate: spdy.utils.createInflate(id) michael@0: }; michael@0: } michael@0: }; michael@0: michael@0: // michael@0: // ### function put (pair) michael@0: // Puts pair into pool michael@0: // michael@0: Pool.prototype.put = function put(pair) { michael@0: var self = this, michael@0: waiting = 2; michael@0: michael@0: spdy.utils.resetZlibStream(pair.inflate, done); michael@0: spdy.utils.resetZlibStream(pair.deflate, done); michael@0: michael@0: function done() { michael@0: if (--waiting === 0) { michael@0: self.pool[pair.version].push(pair); michael@0: } michael@0: } michael@0: };