Skip to content

Commit

Permalink
workaround for node bug nodejs/node-v0.x-archive#8195
Browse files Browse the repository at this point in the history
  • Loading branch information
parisholley committed Jul 9, 2015
1 parent 5d9b18a commit c590f89
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
26 changes: 17 additions & 9 deletions gelfling.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,30 @@ Gelfling.prototype.send = function(data, callback) {
that.send(chunks, callback)
})

function doSend(){
remaining = data.length
function checkDone(err) {
if (err || --remaining === 0) {
if (!that.keepAlive) udpClient.close()
callback(err)
}
}
for (i = 0; i < data.length; i++)
udpClient.send(data[i], 0, data[i].length, that.port, that.host, checkDone)
}

if (!this.keepAlive || !this.udpClient) {
udpClient = dgram.createSocket('udp4')
udpClient.on('error', this.errHandler)
if (this.keepAlive) this.udpClient = udpClient

udpClient.bind({exclusive: true}, function() {
doSend();
});
} else {
udpClient = this.udpClient
doSend();
}
remaining = data.length
function checkDone(err) {
if (err || --remaining === 0) {
if (!that.keepAlive) udpClient.close()
callback(err)
}
}
for (i = 0; i < data.length; i++)
udpClient.send(data[i], 0, data[i].length, this.port, this.host, checkDone)
}

Gelfling.prototype.close = function() {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gelfling",
"version": "0.2.0",
"version": "0.2.1",
"description": "Create and send GELF (Graylog2) messages, including chunking",
"author": "Michael Hart <michael.hart.au@gmail.com> (http://github.com/mhart)",
"main": "gelfling.js",
Expand Down

0 comments on commit c590f89

Please sign in to comment.