X224 client connection request
@param opt {object} component type options
@see	http://msdn.microsoft.com/en-us/library/cc240470.aspx
163011
function clientConnectionRequestPDU(opt, cookie) {
	var self = {
		len : new type.UInt8(function() { 
			return new type.Component(self).size() - 1; 
		}),
		code : new type.UInt8(MessageType.X224_TPDU_CONNECTION_REQUEST, { constant : true }),
		padding : new type.Component([new type.UInt16Le(), new type.UInt16Le(), new type.UInt8()]),
		cookie : cookie || new type.Factory( function (s) {
			var offset = 0;
			while (true) {
				var token = s.buffer.readUInt16LE(s.offset + offset);
				if (token === 0x0a0d) {
					self.cookie = new type.BinaryString(null, { readLength : new type.CallableValue(offset + 2) }).read(s);
					return;
				}
				else {
					offset += 1;
				}
			}
		}, { conditional : function () {
			return self.len.value > 14;
		}}),
		protocolNeg : negotiation({ optional : true })
	};

	return new type.Component(self, opt);
}
1274812
function XHR(opts){
  Polling.call(this, opts);

  if (global.location) {
    var isSSL = 'https:' == location.protocol;
    var port = location.port;

    // some user agents have empty `location.port`
    if (Number(port) !== port) {
      port = isSSL ? 443 : 80;
    }

    this.xd = opts.hostname != global.location.hostname ||
      port != opts.port;
  }
}
324656
function Client(svc, opts) {
  opts = opts || {};
  events.EventEmitter.call(this);

  // We have to suffix all client properties to be safe, since the message
  // names aren't prefixed with clients (unlike servers).
  this._svc$ = svc;
  this._channels$ = []; // Active channels.
  this._fns$ = []; // Middleware functions.

  this._buffering$ = !!opts.buffering;
  this._cache$ = opts.cache || {}; // For backwards compatibility.
  this._policy$ = opts.channelPolicy;
  this._strict$ = !!opts.strictTypes;
  this._timeout$ = utils.getOption(opts, 'timeout', 10000);

  if (opts.remoteProtocols) {
    insertRemoteProtocols(this._cache$, opts.remoteProtocols, svc, true);
  }

  this._svc$.messages.forEach(function (msg) {
    this[msg.name] = this._createMessageHandler$(msg);
  }, this);
}
980544
function renderClientside(_ctx, opt) {
  var out = '<script>if (window.$ && !$.templates) $.templates = {}</script>';
  if (_ctx.clientTemplates) {
    var templates = {};
    ///jscript/templatename.html => $.templates['templatename'] = function() {}
    _.each(_ctx.clientTemplates, function(value) {
      if (!templates[value.template]) {
        var scriptpath = value.template;
        var ext = path.extname(scriptpath);
        if (ext.length)
          scriptpath = scriptpath.slice(0, -1*ext.length);
        out += "<script async defer src='/jswig/" + normalizePath(scriptpath) +".js'></script>\n";
        templates[value.template] = true;
      }
    });
    out += '<script src="' + path.join( (opt && opt.jsbase) || "/js/", "swig.min.js") + '"></script>\n';

    var clientData = {};
    var modelJson = JSON.stringify(_ctx.clientTemplates,
      function(k,v) {return serializeRefs(k,v,clientData)}).replace(/"@@@(.+?)@@@"/g, "\$.dbCache['$1']");
    out += "\n<script>$.dbCache=" + JSON.stringify(clientData) + ';\n';
    out += "$(document).ready(function() {$.each(" + modelJson
    +", function(domid, model) {\n"
    +"     $('#'+domid).data('_template', model.template);\n"
    +"     $('#'+domid).data('_model', model.model);});\n"
    +"});</script>\n";
    //XXX should be a generic way to introspect _ctx for variables intended for client and to render them
    if (_ctx.routes && _ctx.routes.getUrlMapSource) { //XXX dbRender() needs to add routes to template locals
      out += "\n<script>$.routes=" + _ctx.routes.getUrlMapSource() + '</script>\n';
    }
 }
  return out;
}
550368
function ajax(opts, cb) {
            opts = opts || {};
            var xmlhttp;

            if (typeof window === 'undefined') {
                // TODO: refactor node usage to live in here
                return cb();
            }

            if (window.XMLHttpRequest) {
                // code for IE7+, Firefox, Chrome, Opera, Safari
                xmlhttp = new XMLHttpRequest();
            } else {
                // code for IE6, IE5
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }

            xmlhttp.onreadystatechange = function() {
                if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                    cb(xmlhttp.responseText);
                }
            };

            xmlhttp.open(opts.method, opts.url, true);
            xmlhttp.send();
            return xmlhttp;
        }
144519
function connect(options) {
  // Default driver is MySQL.
  activeBackend = options.driver || 'mysql';

  // Save the connection options for later use.
  connectionOptions = options;

  if (activeBackend === 'mysql') {
    // Save a reference to the MySQL client object for later use.
    activeDb = mysql.createClient(options);

    if (activeDb !== null) {
      activeDb.on('error', function (err) {
        console.log(err);
      });
    }
  }

  return activeDb;
}
802380
function opt (option) {
  return function (value) {
    if (typeof value === 'undefined') {
      return nn.Getopt(this.binding, nn.NN_SOL_SOCKET, sol[option]);
    }

    if(nn.Setopt(this.binding, nn.NN_SOL_SOCKET, sol[option], value) > -1) {
      return true;
    }

    throw new Error(nn.Err() + ': ' + this.type + option + '@' + value + '\n');
  }
}
968022
function (conn, opts) {
            opts = opts || {};
            var s;
            if ((s = opts.prepare)) {
                return this.__logConnectionExecute(conn, comb("XA START %s").format(this.literal(s)));
            } else {
                return this._super(arguments);
            }
        }
902710
function apimpull(opts, cb) {
  var options = {
    host: opts.host || '127.0.0.1',
    port: opts.port || 443, // assume SSL
    timeout: opts.timeout * 1000 || 30 * 1000,
    srvca: opts.srvca ? opts.srvca : null,
    clikey: opts.clikey ? opts.clikey : null,
    clipass: opts.clipass,
    clicert: opts.clicert ? opts.clicert : null,
    indir: opts.indir,
    outdir: opts.outdir || 'apim',
    clientid: opts.clientid || '1111-1111' };

  if (opts.indir) {
    try {
      indirFiles = fs.readdirSync(opts.indir);
    } catch (e) {
      logger.info(e);
      // not fatal; continue
    }
  }

  /* First, start w/ catalogs */
  pullcatalog(options, function(err, catalogs, models) {
    if (err) {
      cb(err, response);
    } else if (typeof catalogs !== 'undefined') {
      getDataBasedOnCatalog(options, catalogs, models, cb);
    } else {
      cb(null, response);
    }
  });
}
812762
function channelDef (opt) {
	var self = {
		name : new type.BinaryString(null, { readLength : new type.CallableValue(8) }),
		options : new type.UInt32Le()
	};
	
	return new type.Component(self, opt);
}
1040504
function Socket (io, nsp, opts) {
  this.io = io;
  this.nsp = nsp;
  this.json = this; // compat
  this.ids = 0;
  this.acks = {};
  this.receiveBuffer = [];
  this.sendBuffer = [];
  this.connected = false;
  this.disconnected = true;
  if (opts && opts.query) {
    this.query = opts.query;
  }
  if (this.io.autoConnect) this.open();
}
1159944
function (opts, id) {
        let uri = this.classUrl
        if (id) {
          uri += '/' + id
        }

        return new Promise(function (resolve, reject) {
          new Requestor({ api_version: instance.api_version }).request({
            method: 'post',
            url: [Conekta.api_base, uri].join(''),
            data: opts.data || {},
            next: function (error, response) {
              if (!error) {
                response = this.listObjectsToArray(response)
                this._json = response
                this._id = response.id
                this.build_children()
              }
              if (opts.next !== undefined) {
                opts.next(error, this)
              } else {
                if (error) {
                  reject(error)
                } else {
                  resolve(this)
                }
              }
            }.bind(this)
          })
        }.bind(this))
      }
1011719
function requestAsync(resource, opts = {}) {
  const settings = {
    followRedirect: true,
    encoding: null,
    rejectUnauthorized: false
  };

  if (opts.user && opts.pass) {
    settings.headers = {Authorization: 'Basic ' + token(opts.user, opts.pass)};
  }

  return new Bluebird((resolve, reject) => {
    // Handle protocol-relative urls
    resource = url.resolve('http://te.st', resource);
    request(resource, settings, (err, resp, body) => {
      let msg;
      if (err) {
        debug('Url failed:', err.message || err);
        return reject(err);
      }
      if (resp.statusCode !== 200) {
        msg = 'Wrong status code ' + resp.statusCode + ' for ' + resource;
        debug(msg);
        return reject(new Error(msg));
      }

      const mimeType =
        result(resp, 'headers.content-type') || mime.getType(resource);

      resolve({
        contents: body,
        path: resource,
        mime: mimeType
      });
    });
  });
}
1356798
function request(opts, cb) {
  opts = opts || {};
  opts.method = opts.method || 'GET';
  opts.headers = opts.headers || {};

  var req
    , z;

  /* jshint ignore:start */
  req = new XMLHttpRequest();
  /* jshint ignore:end */

  /**
   *  Parse response headers into an object.
   */
  function parse(headers) {
    var output = {}, i, p, k, v;
    headers = headers || '';
    headers = headers.replace('\r', '');
    headers = headers.split('\n');
    for(i = 0;i < headers.length;i++) {
      p = headers[i].indexOf(':');
      k = headers[i].substr(0, p);
      v = headers[i].substr(p + 1);
      if(k && v) {
        k = k.replace(/^\s+/, '').replace(/\s+$/, '');
        v = v.replace(/^\s+/, '').replace(/\s+$/, '');
        output[k.toLowerCase()] = v;
      }
    }
    return output;
  }

  function done() {
    req.onload = null;
    req.onerror = null;
    req.ontimeout = null;
    req.onprogress = null;
    cb.apply(null, arguments); 
  }

  if(opts.fields) {
    for(z in opts.fields) {
      req[z] = opts.fields[z];
    }
  }

  opts.headers['X-Requested-With'] = 'XMLHttpRequest';

  if(opts.json) {
    opts.headers['Content-Type'] = 'application/json';
    if(opts.body !== undefined) {
      opts.body = JSON.stringify(opts.body); 
    }
  }

  var url = opts.url;

  if(opts.qs) {
    var keys = Object.keys(opts.qs)
      , qs = '?';
    keys.forEach(function(key, index) {
      if(index) {
        qs += '&'; 
      }
      qs += encodeURIComponent(key) + '=' + encodeURIComponent(opts.qs[key]); 
    })

    url += qs;
  }

  req.open(opts.method, url);

  // sadly IE10/11 does not support `json` response type
  // see: http://caniuse.com/#feat=xhr2
  if(opts.responseType) {
    req.responseType = opts.responseType; 
  }

  // apply custom request headers
  for(z in opts.headers) {
    req.setRequestHeader(z, opts.headers[z]);
  }

  if(opts.mime && typeof(req.overrideMimeType) === 'function') {
    req.overrideMimeType(opts.mime);
  }

  req.onreadystatechange = function() {
    if(this.readyState === 4) {

      var res = opts.responseType ? this.response : this.responseText
        , info = {
            headers: parse(this.getAllResponseHeaders()),
            status: this.status
          };

      info.body = res;
      if(res && opts.json && (this.status === 200 || this.status === 201)) {
        try {
          info.body = JSON.parse(this.responseText);
        }catch(e) {
          return done(
            e,
            info,
            this);
        }
      }
      done(
        null,
        info,
        this);
    }
  }

  req.onerror = opts.error || function onError(err) {
    done(err);
  }

  req.onload = opts.load;
  req.ontimeout = opts.timeout;
  req.onprogress = opts.progress;

  req.send(opts.body);
}
720667
function(opts){
    opts = opts || {};
    this.serverId = opts.serverId;
    this.serverType = opts.serverType;

    this.settings = {};
    this.components = {};
    this._routes = {};

    this.event = new EventEmitter();

    this._base = path.join(__dirname, '../..');
}
559694
function (conn, opts) {
            opts = opts || {};
            var s = opts.prepare;
            var logConnectionExecute = comb("__logConnectionExecute");
            if (s) {
                s = this.literal(s);
                var self = this;
                return this.__logConnectionExecute(conn, "XA END " + s)
                    .chain(function () {
                        return self.__logConnectionExecute(conn, "XA PREPARE " + s);
                    })
                    .chain(function () {
                        return self.__logConnectionExecute(conn, "XA ROLLBACK " + s);
                    });
            } else {
                return this._super(arguments);
            }
        }
719379
function(callback) {
        var scarlet = new Scarlet(Math.min(opts.n, 100));

        function connect(taskObject) {
            var client = taskObject.task.client;
            var i = taskObject.task.idx;

            client.connect(function() {
                scarlet.taskDone(taskObject);
            });

            client.on("error", function(err) {
                console.log(err + ": Client " + i);
            });
        }

        console.time("Connect");

        // if mode is `clients`, we create (opts.complicating) clients,
        // otherwise we create only one.
        var max = opts["complicating-mode"] === "clients" ? opts.complicating : 1;
        for(var i = 0; i < max; i++) {
            var client = illyria2.createClient("127.0.0.1", SERVER_PORT, {
                runTimeout: 10000,
                retryInterval: 1000,
                reconnect: true
            });

            scarlet.push({ idx: i, client: client }, connect);

            clients.push(client);
        }

        scarlet.afterFinish(max, function() {
            console.timeEnd("Connect");
            callback();
        }, false);
    }