4 * Copyright(c) 2011 LearnBoost <dev@learnboost.com>
12 var HTTPTransport = require('./http');
15 * Exports the constructor.
18 exports = module.exports = HTTPPolling;
21 * HTTP polling constructor.
26 function HTTPPolling (mng, data, req) {
27 HTTPTransport.call(this, mng, data, req);
31 * Inherits from HTTPTransport.
36 HTTPPolling.prototype.__proto__ = HTTPTransport.prototype;
44 HTTPPolling.prototype.name = 'httppolling';
47 * Override setHandlers
52 HTTPPolling.prototype.setHandlers = function () {
53 HTTPTransport.prototype.setHandlers.call(this);
54 this.socket.removeListener('end', this.bound.end);
55 this.socket.removeListener('close', this.bound.close);
59 * Removes heartbeat timeouts for polling.
62 HTTPPolling.prototype.setHeartbeatInterval = function () {
72 HTTPPolling.prototype.handleRequest = function (req) {
73 HTTPTransport.prototype.handleRequest.call(this, req);
75 if (req.method == 'GET') {
78 this.pollTimeout = setTimeout(function () {
79 self.packet({ type: 'noop' });
80 self.log.debug(self.name + ' closed due to exceeded duration');
81 }, this.manager.get('polling duration') * 1000);
83 this.log.debug('setting poll timeout');
88 * Clears polling timeout
93 HTTPPolling.prototype.clearPollTimeout = function () {
94 if (this.pollTimeout) {
95 clearTimeout(this.pollTimeout);
96 this.pollTimeout = null;
97 this.log.debug('clearing poll timeout');
104 * Override clear timeouts to clear the poll timeout
109 HTTPPolling.prototype.clearTimeouts = function () {
110 HTTPTransport.prototype.clearTimeouts.call(this);
112 this.clearPollTimeout();
116 * doWrite to clear poll timeout
121 HTTPPolling.prototype.doWrite = function () {
122 this.clearPollTimeout();
131 HTTPPolling.prototype.write = function (data, close) {
143 HTTPPolling.prototype.end = function (reason) {
144 this.clearPollTimeout();
145 return HTTPTransport.prototype.end.call(this, reason);