From 129310676d276f2e6333d3af8f1122cdf7b9a634 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Fri, 2 Apr 2010 17:30:27 -0700 Subject: [PATCH] Fix style in SSL patch --- lib/net.js | 136 ++++++++++++++++++++++++++++------------------------- 1 file changed, 73 insertions(+), 63 deletions(-) diff --git a/lib/net.js b/lib/net.js index 7ef363a7d4..b60c15847f 100644 --- a/lib/net.js +++ b/lib/net.js @@ -45,7 +45,7 @@ var ENOENT = binding.ENOENT; var END_OF_FILE = 42; // Do we have openssl crypto? -try { +try { var SecureContext = process.binding('crypto').SecureContext; var SecureStream = process.binding('crypto').SecureStream; var crypto = true; @@ -257,6 +257,7 @@ var securePool = null; function allocNewSecurePool () { securePool = new Buffer(40*1024); } + var emptyBuffer = null; function allocEmptyBuffer () { emptyBuffer = new Buffer(1); @@ -292,25 +293,27 @@ function initStream (self) { try { if (self.secure) { - if (!securePool) allocNewSecurePool(); - secureBytesRead = read(self.fd, securePool, 0, securePool.length); - self.secureStream.readInject(securePool, 0, secureBytesRead); - bytesRead = self.secureStream.readExtract(pool, pool.used, pool.length - pool.used); - if(!self.secureEstablished) { - if (self.secureStream.isInitFinished()) { - self.secureEstablished = true; - if (self._events && self._events['secure']) self.emit('secure'); - } - } - if (secureBytesRead === null && !self.server) { - // Client needs to write as part of handshake - this._writeWatcher.start(); - } + if (!securePool) allocNewSecurePool(); + secureBytesRead = read(self.fd, securePool, 0, securePool.length); + self.secureStream.readInject(securePool, 0, secureBytesRead); + bytesRead = self.secureStream.readExtract(pool, + pool.used, + pool.length - pool.used); + if (!self.secureEstablished) { + if (self.secureStream.isInitFinished()) { + self.secureEstablished = true; + if (self._events && self._events['secure']) self.emit('secure'); + } + } + if (secureBytesRead === null && !self.server) { + // Client needs to write as part of handshake + this._writeWatcher.start(); + } } else { bytesRead = read(self.fd, pool, pool.used, - pool.length - pool.used); + pool.length - pool.used); } } catch (e) { if (this.forceClose) this.forceClose(e); @@ -319,14 +322,17 @@ function initStream (self) { //debug('bytesRead ' + bytesRead + '\n'); - if (self.secure && bytesRead == 0 && secureBytesRead >0){ - // Deal with SSL handshake - if (self.server) { - self._checkForSecureHandshake(); - } else { - if (self.secureEstablised) self.flush(); - else self._checkForSecureHandshake(); - } + if (self.secure && bytesRead == 0 && secureBytesRead > 0){ + // Deal with SSL handshake + if (self.server) { + self._checkForSecureHandshake(); + } else { + if (self.secureEstablised) { + self.flush(); + } else { + self._checkForSecureHandshake(); + } + } } else if (bytesRead === 0) { self.readable = false; self._readWatcher.stop(); @@ -398,12 +404,12 @@ exports.createCredentials = function(cred) { if (cred.key) c.context.setKey(cred.key); if (cred.cert) c.context.setCert(cred.cert); if (cred.ca) { - if ( (typeof(cred.ca) == 'object') && cred.ca.length ) { - for(var i=0; i