dgram: fix double implicit bind error
authorBen Noordhuis <info@bnoordhuis.nl>
Mon, 31 Dec 2012 16:42:54 +0000 (17:42 +0100)
committerBen Noordhuis <info@bnoordhuis.nl>
Mon, 31 Dec 2012 16:53:00 +0000 (17:53 +0100)
commit9e32c2ef3ede29ba0ae2086bdf658f6cd44182df
tree01a1e283245baa1de7888700d3cf389ed899a6d8
parent30bd774fbd379c86dd4e1bbaecd593b56112ddc3
dgram: fix double implicit bind error

Calling send() on an unbound socket forces an implicit bind to
a random port.

332fea5 made the 'listening' event asynchronous. Unfortunately,
it also introduced a bug where the implicit bind was tried more
than once if send() was called again before the first bind operation
completed.

Address that by keeping track of the bind status and making sure that
bind() is called only once.

Fixes #4499.
lib/dgram.js
test/simple/test-dgram-implicit-bind.js [new file with mode: 0644]