Lazy load modules in net.js
authorRyan Dahl <ry@tinyclouds.org>
Thu, 28 Oct 2010 20:15:53 +0000 (13:15 -0700)
committerRyan Dahl <ry@tinyclouds.org>
Thu, 28 Oct 2010 20:15:53 +0000 (13:15 -0700)
lib/net.js

index e81d827..88e1925 100644 (file)
@@ -1,8 +1,6 @@
 var util = require("util");
-var fs = require("fs");
 var events = require("events");
 var stream = require("stream");
-var dns = require('dns');
 
 var kMinPoolSpace = 128;
 var kPoolSize = 40*1024;
@@ -796,7 +794,7 @@ Stream.prototype.connect = function () {
     doConnect(self, arguments[0]);
   } else {
     // TCP
-    dns.lookup(arguments[1], function (err, ip, addressType) {
+    require('dns').lookup(arguments[1], function (err, ip, addressType) {
       if (err) {
         self.emit('error', err);
       } else {
@@ -1085,7 +1083,7 @@ Server.prototype.listen = function () {
     var path = arguments[0];
     self.path = path;
     // unlink sockfile if it exists
-    fs.stat(path, function (err, r) {
+    require('fs').stat(path, function (err, r) {
       if (err) {
         if (err.errno == ENOENT) {
           self._doListen(path);
@@ -1111,7 +1109,7 @@ Server.prototype.listen = function () {
     self._doListen(port);
   } else {
     // the first argument is the port, the second an IP
-    dns.lookup(arguments[1], function (err, ip, addressType) {
+    require('dns').lookup(arguments[1], function (err, ip, addressType) {
       if (err) {
         self.emit('error', err);
       } else {
@@ -1192,7 +1190,7 @@ Server.prototype.close = function () {
   }
 
   if (self.type === "unix") {
-    fs.unlink(self.path, function () {
+    require('fs').unlink(self.path, function () {
       self.emit("close");
     });
   } else {