aboutsummaryrefslogtreecommitdiff
path: root/lib/net.js
diff options
context:
space:
mode:
authorJames Hight <james@zavoo.com>2012-12-31 21:01:42 -0500
committerBen Noordhuis <info@bnoordhuis.nl>2013-01-05 17:05:13 +0100
commit3f76419a04da48b92b50b51450685b8565886200 (patch)
treebd54345f89f9e8399e48fca0d6bdab93bdb29305 /lib/net.js
parent5664dd2fc1e872a850c2891ee11f86e98b69106d (diff)
downloadandroid-node-v8-3f76419a04da48b92b50b51450685b8565886200.tar.gz
android-node-v8-3f76419a04da48b92b50b51450685b8565886200.tar.bz2
android-node-v8-3f76419a04da48b92b50b51450685b8565886200.zip
net: add localAddress and localPort to Socket
Diffstat (limited to 'lib/net.js')
-rw-r--r--lib/net.js24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/net.js b/lib/net.js
index fc56918eba..a347c08507 100644
--- a/lib/net.js
+++ b/lib/net.js
@@ -526,6 +526,30 @@ Socket.prototype.__defineGetter__('remotePort', function() {
});
+Socket.prototype._getsockname = function() {
+ if (!this._handle || !this._handle.getsockname) {
+ return {};
+ }
+ if (!this._sockname) {
+ this._sockname = this._handle.getsockname();
+ if (this._sockname === null) {
+ return {};
+ }
+ }
+ return this._sockname;
+};
+
+
+Socket.prototype.__defineGetter__('localAddress', function() {
+ return this._getsockname().address;
+});
+
+
+Socket.prototype.__defineGetter__('localPort', function() {
+ return this._getsockname().port;
+});
+
+
Socket.prototype.write = function(chunk, encoding, cb) {
if (typeof chunk !== 'string' && !Buffer.isBuffer(chunk))
throw new TypeError('invalid data');