Skip to content

Commit

Permalink
adding exclusive.bind
Browse files Browse the repository at this point in the history
  • Loading branch information
jphaas committed Aug 7, 2015
1 parent f39628a commit b5e9771
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion graphite-udp.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ function Client(options) {
interval: 5000,
type: 'udp4'
}

var bound = false;

function init() {
options = util._extend(defaults, options)
socket = dgram.createSocket(options.type)

socket.bind({exclusive: true}, function() { bound = true; })

socket.on('close', function () {
log('UDP socket closed')
Expand Down Expand Up @@ -63,6 +67,11 @@ function Client(options) {
}

function send(callback) {
if (!bound) {
setTimeout(function() {send(callback);}, 100);
return;
}

if(Object.keys(queue).length === 0) {
log('Queue is empty. Nothing to send')
return
Expand Down Expand Up @@ -96,4 +105,4 @@ module.exports = {
createClient: function(options) {
return new Client(options)
}
}
}

0 comments on commit b5e9771

Please sign in to comment.