spdy-http2 / node-spdy

SPDY server on Node.js
2.81k stars 196 forks source link

Connection._handlePing() emits error event but has callback for successful ping? #170

Closed jeffreydwalter closed 10 years ago

jeffreydwalter commented 10 years ago

What's the rationale behind emitting an error event, but taking a callback for the success case? Why not just emit success?

Connection.prototype._handlePing = function handlePing(id) { var self = this; var state = this._spdyState;

var ours = state.isServer && (id % 2 === 0) || !state.isServer && (id % 2 === 1);

// Handle incoming PING if (!ours) { state.framer.pingFrame(id, function(err, frame) { if (err) return self.emit('error', err); self.write(frame); }); return; }

// Handle reply PING if (!state.pings[id]) return; var ping = state.pings[id]; delete state.pings[id];

if (ping.cb) ping.cb(null); };

indutny commented 10 years ago

The rationale here is that in case of framer failure there is no point of keeping connection alive. Also, this code emits error on incoming PING requests not responses, so we don't have any cb to execute in case of error.