summaryrefslogtreecommitdiff
path: root/test/parallel/test-dgram-send-callback-recursive.js
diff options
context:
space:
mode:
authorYosuke Furukawa <yosuke.furukawa@gmail.com>2015-04-01 23:32:48 +0900
committerYosuke Furukawa <yosuke.furukawa@gmail.com>2015-05-10 12:03:21 +0900
commit18d457bd3408557a48b453f13b2b99e1ab5e7159 (patch)
treebc0bece749bfac62be77dbd9f4ed2e86b7c5888b /test/parallel/test-dgram-send-callback-recursive.js
parentaed6bce9064915bda28237b1a5fbf7fcdbf439ef (diff)
downloadandroid-node-v8-18d457bd3408557a48b453f13b2b99e1ab5e7159.tar.gz
android-node-v8-18d457bd3408557a48b453f13b2b99e1ab5e7159.tar.bz2
android-node-v8-18d457bd3408557a48b453f13b2b99e1ab5e7159.zip
dgram: call send callback asynchronously
dgram#send callback was changed synchronously. The PR-URL is here https://github.com/joyent/libuv/pull/1358 This commit is temporary fix until libuv issue is resolved. https://github.com/libuv/libuv/issues/301 PR-URL: https://github.com/iojs/io.js/pull/1313 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Diffstat (limited to 'test/parallel/test-dgram-send-callback-recursive.js')
-rw-r--r--test/parallel/test-dgram-send-callback-recursive.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/test/parallel/test-dgram-send-callback-recursive.js b/test/parallel/test-dgram-send-callback-recursive.js
new file mode 100644
index 0000000000..b1c9745fe8
--- /dev/null
+++ b/test/parallel/test-dgram-send-callback-recursive.js
@@ -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);