-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dgram: call send callback asynchronously
dgram#send callback was changed synchronously. The PR-URL is here joyent/libuv#1358 This commit is temporary fix until libuv issue is resolved. libuv/libuv#301 PR-URL: #1313 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Trevor Norris <[email protected]>
- Loading branch information
1 parent
aed6bce
commit 18d457b
Showing
2 changed files
with
42 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
const dgram = require('dgram'); | ||
const client = dgram.createSocket('udp4'); | ||
const chunk = 'abc'; | ||
var recursiveCount = 0; | ||
var received = 0; | ||
const limit = 10; | ||
|
||
function onsend() { | ||
if (recursiveCount > limit) { | ||
throw new Error('infinite loop detected'); | ||
} | ||
if (received < limit) { | ||
client.send( | ||
chunk, 0, chunk.length, common.PORT, common.localhostIPv4, onsend); | ||
} | ||
recursiveCount++; | ||
} | ||
|
||
client.on('listening', function() { | ||
onsend(); | ||
}); | ||
|
||
client.on('message', function(buf, info) { | ||
received++; | ||
if (received === limit) { | ||
client.close(); | ||
} | ||
}); | ||
|
||
client.on('close', common.mustCall(function() { | ||
assert.equal(received, limit); | ||
})); | ||
|
||
client.bind(common.PORT); |