Created
May 25, 2010 09:42
-
-
Save billywhizz/412959 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| From 8c98d12474fbd9e17732ff84c47e48c0cc100928 Mon Sep 17 00:00:00 2001 | |
| From: Andrew Johnston <[email protected]> | |
| Date: Tue, 25 May 2010 10:30:58 +0100 | |
| Subject: [PATCH] datagram support for socket connect | |
| --- | |
| lib/net.js | 14 ++++++++++++-- | |
| src/node_net2.cc | 11 +++++++---- | |
| 2 files changed, 19 insertions(+), 6 deletions(-) | |
| mode change 100644 => 100755 lib/net.js | |
| mode change 100644 => 100755 src/node_net2.cc | |
| diff --git a/lib/net.js b/lib/net.js | |
| old mode 100644 | |
| new mode 100755 | |
| index 4c9c525..dcc37a6 | |
| --- a/lib/net.js | |
| +++ b/lib/net.js | |
| @@ -780,13 +780,23 @@ Stream.prototype.connect = function () { | |
| self.emit('error', err); | |
| } else { | |
| self.type = addressType == 4 ? 'tcp4' : 'tcp6'; | |
| - self.fd = socket(self.type); | |
| + if(arguments.length > 2) { | |
| + self.fd = socket(self.type, arguments[2]); | |
| + } | |
| + else { | |
| + self.fd = socket(self.type); | |
| + } | |
| doConnect(self, port, ip); | |
| } | |
| }); | |
| } else { | |
| // UNIX | |
| - self.fd = socket('unix'); | |
| + if(arguments.length > 2) { | |
| + self.fd = socket('unix', arguments[2]); | |
| + } | |
| + else { | |
| + self.fd = socket('unix'); | |
| + } | |
| self.type = 'unix'; | |
| doConnect(self, arguments[0]); | |
| } | |
| diff --git a/src/node_net2.cc b/src/node_net2.cc | |
| old mode 100644 | |
| new mode 100755 | |
| index 076951e..74510ac | |
| --- a/src/node_net2.cc | |
| +++ b/src/node_net2.cc | |
| @@ -132,21 +132,24 @@ static Handle<Value> Socket(const Arguments& args) { | |
| int domain = PF_INET; | |
| int type = SOCK_STREAM; | |
| + if (args.Length() > 1) { | |
| + String::Utf8Value t(args[1]->ToString()); | |
| + if (0 == strcasecmp(*t, "DGRAM")) { | |
| + type = SOCK_DGRAM; | |
| + } | |
| + } | |
| + | |
| if (args[0]->IsString()) { | |
| String::Utf8Value t(args[0]->ToString()); | |
| // FIXME optimize this cascade. | |
| if (0 == strcasecmp(*t, "TCP")) { | |
| domain = PF_INET; | |
| - type = SOCK_STREAM; | |
| } else if (0 == strcasecmp(*t, "TCP4")) { | |
| domain = PF_INET; | |
| - type = SOCK_STREAM; | |
| } else if (0 == strcasecmp(*t, "TCP6")) { | |
| domain = PF_INET6; | |
| - type = SOCK_STREAM; | |
| } else if (0 == strcasecmp(*t, "UNIX")) { | |
| domain = PF_UNIX; | |
| - type = SOCK_STREAM; | |
| } else if (0 == strcasecmp(*t, "UDP")) { | |
| domain = PF_INET6; | |
| type = SOCK_DGRAM; | |
| -- | |
| 1.6.6.1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var net = require("net"); | |
| var sys = require("sys"); | |
| var buff = require("buffer"); | |
| var msg = "nodetest[" + process.pid + "]: This is a test"; | |
| // Tests writing using datagrams over unix domain sockets to /dev/log if syslogd is running | |
| var s = new net.Stream(); | |
| s.connect("/dev/log", "0.0.0.0", "dgram"); | |
| s.setEncoding("ascii"); | |
| s.setTimeout(5000); | |
| s.addListener("drain", function() { | |
| sys.puts("drain"); | |
| }); | |
| s.addListener("connect", function() { | |
| sys.puts("connect"); | |
| }); | |
| s.addListener("error", function() { | |
| sys.puts("error"); | |
| }); | |
| s.addListener("close", function() { | |
| sys.puts("close"); | |
| }); | |
| s.addListener("end", function() { | |
| sys.puts("end"); | |
| }); | |
| var timer = setInterval(function() { | |
| var bytes = s.write(msg); | |
| sys.puts(bytes + " written."); | |
| }, 1000); | |
| setTimeout(function() { | |
| clearTimeout(timer); | |
| s.end() | |
| s.destroy(); | |
| }, 10000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment