Comparing version 0.1.3 to 0.1.4
@@ -42,3 +42,5 @@ /*! | ||
async bind() { | ||
this.emit('listening'); | ||
const address = this.address(); | ||
this.emit('listening', address); | ||
return address; | ||
} | ||
@@ -55,9 +57,13 @@ | ||
getRecvBufferSize() { | ||
return 0; | ||
return 512; | ||
} | ||
getSendBufferSize() { | ||
return 0; | ||
return 512; | ||
} | ||
hasBufferSize() { | ||
return true; | ||
} | ||
ref() { | ||
@@ -64,0 +70,0 @@ return this; |
@@ -30,2 +30,3 @@ /*! | ||
this.socket = socket; | ||
this._reject = null; | ||
@@ -37,2 +38,10 @@ this.socket.on('close', () => { | ||
this.socket.on('error', (err) => { | ||
const reject = this._reject; | ||
if (reject) { | ||
this._reject = null; | ||
reject(err); | ||
return; | ||
} | ||
this.emit('error', err); | ||
@@ -42,3 +51,3 @@ }); | ||
this.socket.on('listening', () => { | ||
this.emit('listening'); | ||
this.emit('listening', this.address()); | ||
}); | ||
@@ -62,4 +71,15 @@ | ||
return new Promise((resolve, reject) => { | ||
args.push(wrap(resolve, reject)); | ||
this.socket.bind(...args); | ||
this._reject = reject; | ||
args.push(() => { | ||
this._reject = null; | ||
resolve(this.address()); | ||
}); | ||
try { | ||
this.socket.bind(...args); | ||
} catch (e) { | ||
this._reject = null; | ||
reject(e); | ||
} | ||
}); | ||
@@ -70,3 +90,15 @@ } | ||
return new Promise((resolve, reject) => { | ||
this.socket.close(wrap(resolve, reject)); | ||
this._reject = reject; | ||
const cb = () => { | ||
this._reject = null; | ||
resolve(); | ||
}; | ||
try { | ||
this.socket.close(cb); | ||
} catch (e) { | ||
this._reject = null; | ||
reject(e); | ||
} | ||
}); | ||
@@ -81,2 +113,4 @@ } | ||
getRecvBufferSize() { | ||
if (!this.socket.getRecvBufferSize) | ||
return 512; | ||
return this.socket.getRecvBufferSize(); | ||
@@ -86,5 +120,11 @@ } | ||
getSendBufferSize() { | ||
if (!this.socket.getSendBufferSize) | ||
return 512; | ||
return this.socket.getSendBufferSize(); | ||
} | ||
hasBufferSize() { | ||
return typeof this.socket.setRecvBufferSize === 'function'; | ||
} | ||
ref() { | ||
@@ -112,3 +152,4 @@ this.socket.ref(); | ||
setMulticastInterface(iface) { | ||
this.socket.setMulticastInterface(iface); | ||
if (this.socket.setMulticastInterface) | ||
this.socket.setMulticastInterface(iface); | ||
return this; | ||
@@ -128,3 +169,4 @@ } | ||
setRecvBufferSize(size) { | ||
this.socket.setRecvBufferSize(size); | ||
if (this.socket.setRecvBufferSize) | ||
this.socket.setRecvBufferSize(size); | ||
return this; | ||
@@ -134,3 +176,4 @@ } | ||
setSendBufferSize(size) { | ||
this.socket.setSendBufferSize(size); | ||
if (this.socket.setSendBufferSize) | ||
this.socket.setSendBufferSize(size); | ||
return this; | ||
@@ -167,15 +210,1 @@ } | ||
}; | ||
/* | ||
* Helpers | ||
*/ | ||
function wrap(resolve, reject) { | ||
return function(err, result) { | ||
if (err) { | ||
reject(err); | ||
return; | ||
} | ||
resolve(result); | ||
}; | ||
} |
{ | ||
"name": "budp", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "UDP wrapper for node.js", | ||
@@ -22,3 +22,3 @@ "keywords": [ | ||
"devDependencies": { | ||
"bmocha": "^0.1.0" | ||
"bmocha": "^1.0.0" | ||
}, | ||
@@ -25,0 +25,0 @@ "engines": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10348
358
7