From 7bd94712a8592d8d53596c727a0456db742dc5ed Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Tue, 28 Sep 2010 11:14:24 -0700 Subject: [PATCH] lazy load crypto binding --- lib/net.js | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/lib/net.js b/lib/net.js index 440a36e1ed..4f32dc1eba 100644 --- a/lib/net.js +++ b/lib/net.js @@ -47,15 +47,7 @@ var EINPROGRESS = binding.EINPROGRESS; var ENOENT = binding.ENOENT; var EMFILE = binding.EMFILE; var END_OF_FILE = 42; - -// Do we have openssl crypto? -try { - var SecureContext = process.binding('crypto').SecureContext; - var SecureStream = process.binding('crypto').SecureStream; - var haveCrypto = true; -} catch (e) { - var haveCrypto = false; -} +var SecureContext, SecureStream; // lazy loaded // IDLE TIMEOUTS // @@ -544,11 +536,17 @@ function Stream (fd, type) { sys.inherits(Stream, events.EventEmitter); exports.Stream = Stream; + Stream.prototype.setSecure = function (credentials) { - if (!haveCrypto) { + // Do we have openssl crypto? + try { + SecureContext = process.binding('crypto').SecureContext; + SecureStream = process.binding('crypto').SecureStream; + } catch (e) { throw new Error('node.js not compiled with openssl crypto support.'); } - var crypto= require("crypto"); + + var crypto = require("crypto"); this.secure = true; this.secureEstablished = false; // If no credentials given, create a new one for just this Stream