testing/xpcshell/node-spdy/lib/spdy/zlib-pool.js

Wed, 31 Dec 2014 06:55:46 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:46 +0100
changeset 1
ca08bd8f51b2
permissions
-rw-r--r--

Added tag TORBROWSER_REPLICA for changeset 6474c204b198

michael@0 1 var zlibpool = exports,
michael@0 2 spdy = require('../spdy');
michael@0 3
michael@0 4 //
michael@0 5 // ### function Pool ()
michael@0 6 // Zlib streams pool
michael@0 7 //
michael@0 8 function Pool() {
michael@0 9 this.pool = {
michael@0 10 'spdy/2': [],
michael@0 11 'spdy/3': []
michael@0 12 };
michael@0 13 }
michael@0 14
michael@0 15 //
michael@0 16 // ### function create ()
michael@0 17 // Returns instance of Pool
michael@0 18 //
michael@0 19 zlibpool.create = function create() {
michael@0 20 return new Pool();
michael@0 21 };
michael@0 22
michael@0 23 var x = 0;
michael@0 24 //
michael@0 25 // ### function get ()
michael@0 26 // Returns pair from pool or a new one
michael@0 27 //
michael@0 28 Pool.prototype.get = function get(version, callback) {
michael@0 29 if (this.pool[version].length > 0) {
michael@0 30 return this.pool[version].pop();
michael@0 31 } else {
michael@0 32 var id = version.split('/', 2)[1];
michael@0 33
michael@0 34 return {
michael@0 35 version: version,
michael@0 36 deflate: spdy.utils.createDeflate(id),
michael@0 37 inflate: spdy.utils.createInflate(id)
michael@0 38 };
michael@0 39 }
michael@0 40 };
michael@0 41
michael@0 42 //
michael@0 43 // ### function put (pair)
michael@0 44 // Puts pair into pool
michael@0 45 //
michael@0 46 Pool.prototype.put = function put(pair) {
michael@0 47 var self = this,
michael@0 48 waiting = 2;
michael@0 49
michael@0 50 spdy.utils.resetZlibStream(pair.inflate, done);
michael@0 51 spdy.utils.resetZlibStream(pair.deflate, done);
michael@0 52
michael@0 53 function done() {
michael@0 54 if (--waiting === 0) {
michael@0 55 self.pool[pair.version].push(pair);
michael@0 56 }
michael@0 57 }
michael@0 58 };

mercurial