bind on send if not bound

This commit is contained in:
Mark Vayngrib 2015-05-16 11:45:26 -04:00
parent 516530edbd
commit 7105b5f14d
1 changed files with 6 additions and 1 deletions

View File

@ -139,7 +139,12 @@ UdpSocket.prototype.send = function(buffer, offset, length, port, address, callb
if (offset !== 0) throw new Error('Non-zero offset not supported yet')
if (this._state === STATE.UNBOUND) {
throw new Error('bind before sending, seriously dude')
var args = [].slice.call(arguments)
return this.bind(0, function(err) {
if (err) return callback(err)
self.send.apply(self, args)
})
}
else if (this._state === STATE.BINDING) {
// we're ok, GCDAsync(Udp)Socket handles queueing internally