summaryrefslogtreecommitdiff
path: root/lib/dgram.js
AgeCommit message (Collapse)AuthorFilesLines
2015-09-08cluster: allow shared reused dgram socketsFedor Indutny1-8/+15
Allow listening on reused dgram ports in cluster workers. Fix: https://github.com/joyent/node/issues/9261 PR-URL: https://github.com/nodejs/node/pull/2548 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-08-04dgram: make send cb act as "error" event handlerMatteo Collina1-5/+1
Modifies the dgram send() method to not emit errors when a DNS lookup fails if there is a callback. Given that the same UDP socket can be used to send messages to different hosts, the socket can be reused even if one of those send() fails. This slightly changes the behavior of a stable API, so that it behaves as users would expect to. This is based on https://github.com/joyent/node/pull/7738, which landed in 77266d7fadd8dfefb107ccb1e3fe97f9620f1288. Fixes: https://github.com/joyent/node/issues/4846 Refs: https://github.com/joyent/node/pull/7738 PR-URL: https://github.com/nodejs/io.js/pull/1796 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-08-04dgram: make send cb act as "error" event handlerChris Dickinson1-1/+9
This allows users to provide a callback that handles potential errors resulting from a `socket.send` call. The original behavior of emitting the error event on the socket is preserved. Fixes: https://github.com/joyent/node/issues/4846 PR-URL: https://github.com/joyent/node/pull/7738 PR-URL: https://github.com/nodejs/io.js/pull/1796 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-06-11lib: don't use global BufferRoman Reiss1-0/+1
Port of https://github.com/joyent/node/pull/8603 The race condition present in the original PR didn't occur, so no workaround was needed. PR-URL: https://github.com/nodejs/io.js/pull/1794 Reviewed-By: Trevor Norris <trev.norris@gmail.com>
2015-06-04dgram: partially revert 18d457bSaúl Ibarra Corretgé1-4/+1
Revert "dgram: call send callback asynchronously" partially, since the fix is now done in libuv. Refs: https://github.com/nodejs/io.js/pull/1313 Refs: https://github.com/libuv/libuv/pull/371 PR-URL: https://github.com/nodejs/io.js/pull/1889 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2015-05-25lib: simplify nextTick() usageBrian White1-7/+2
This commit removes unnecessary nextTick() closures and adds some shared nextTick() callbacks for better re-use. PR-URL: https://github.com/nodejs/io.js/pull/1612 Reviewed-By: Yosuke Furukawa <yosuke.furukawa@gmail.com> Reviewed-By: Brendan Ashworth <brendan.ashworth@me.com>
2015-05-23net,dgram: return this from ref and unref methodsRoman Reiss1-0/+4
Modifies the following methods to return the instance instead of undefined, to allow for chaining these methods: - net.Server.ref - net.Server.unref - net.Socket.ref - net.Socket.unref - dgram.Socket.ref - dgram.Socket.unref PR-URL: https://github.com/nodejs/io.js/pull/1768 Reviewed-By: Evan Lucas <evanlucas@me.com>
2015-05-10dgram: call send callback asynchronouslyYosuke Furukawa1-1/+4
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>
2015-05-09lib: fix eslint stylesYosuke Furukawa1-4/+3
PR-URL: https://github.com/iojs/io.js/pull/1539 Fixes: https://github.com/iojs/io.js/issues/1253 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com> Reviewed-By: Johan Bergström <bugs@bergstroem.nu> Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
2015-04-15node: allow multiple arguments passed to nextTickTrevor Norris1-7/+13
PR-URL: https://github.com/iojs/io.js/pull/1077 Reviewed-by: Colin Ihrig <cjihrig@gmail.com>
2015-04-09lib: reduce process.binding() callsBrendan Ashworth1-1/+0
This commit better handles calls to process.binding() in lib/ by no longer lazy loading the bindings (the load times themselves are rather miniscule compared to the load time of V8) and never reloading the bindings (which is 172 times slower than referencing a variable with the same value). PR-URL: https://github.com/iojs/io.js/pull/1367 Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-02-02dgram: check close callback is functionYosuke Furukawa1-1/+1
PR-URL: https://github.com/iojs/io.js/pull/609 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Evan Lucas <evanlucas@me.com>
2015-01-31lib: reduce util.is*() usagecjihrig1-12/+12
Many of the util.is*() methods used to check data types simply compare against a single value or the result of typeof. This commit replaces calls to these methods with equivalent checks. This commit does not touch calls to the more complex methods (isRegExp(), isDate(), etc.). Fixes: https://github.com/iojs/io.js/issues/607 PR-URL: https://github.com/iojs/io.js/pull/647 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-01-31dgram: implicit binds should be exclusiveSam Roberts1-1/+1
Server sockets should be shared by default, and client sockets should be exclusive by default. For net/TCP, this is how it is, for dgram/UDP, its a little less clear what a client socket is, but a socket that is auto-bound during a dgram.send() is not usefully shared among cluster workers, any more than an outgoing TCP connection would be usefully shared. Since implicit binds become exclusive, implicit/client dgram sockets can now be used with cluster on Windows. Before, neither explicit nor implicitly bound sockets could be used, causing dgram to be completely unsupported with cluster on Windows. After this change, they become half supported. PR: https://github.com/iojs/io.js/pull/325 PR: https://github.com/joyent/node/pull/8643 Reviewed-by: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-by: Bert Belder <bertbelder@gmail.com>
2015-01-21lib: use const to define constantscjihrig1-12/+12
This commit replaces a number of var statements throughout the lib code with const statements. PR-URL: https://github.com/iojs/io.js/pull/541 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-01-12Remove excessive copyright/license boilerplateisaacs1-21/+0
The copyright and license notice is already in the LICENSE file. There is no justifiable reason to also require that it be included in every file, since the individual files are not individually distributed except as part of the entire package.
2015-01-10Revert "dgram: implicit binds should be exclusive"Ben Noordhuis1-1/+1
This reverts commit a32b92dbcfc8a3a8b2409bb2ace2233ebe327888. Reverted for breaking the parallel/test-cluster-dgram-2 test on all platforms. PR-URL: https://github.com/iojs/io.js/pull/279 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rod Vagg <rod@vagg.org>
2015-01-10dgram: implicit binds should be exclusiveSam Roberts1-1/+1
Server sockets should be shared by default, and client sockets should be exclusive by default. For net/TCP, this is how it is, for dgram/UDP, its a little less clear what a client socket is, but a socket that is auto-bound during a dgram.send() is not usefully shared among cluster workers, any more than an outgoing TCP connection would be usefully shared. Since implicit binds become exclusive, implicit/client dgram sockets can now be used with cluster on Windows. Before, neither explicit nor implicitly bound sockets could be used, causing dgram to be completely unsupported with cluster on Windows. After this change, they become half supported. PR-URL: https://github.com/joyent/node/pull/8643 Reviewed-by: Bert Belder <bertbelder@gmail.com>
2015-01-08dgram: make error messages more informativeEvan Lucas1-4/+13
PR-URL: https://github.com/iojs/io.js/pull/250 Reviewed-By: Bert Belder <bertbelder@gmail.com>
2014-12-30dgram: close() should accept a callbackSam Roberts1-1/+3
Like net, http, and https server.close, and socket.end(), etc. PR-URL: https://github.com/iojs/io.js/pull/217 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2014-12-30dgram: make 'close' event asyncSam Roberts1-1/+4
Emit the close event asynchronously, after the close, as it is with the net/http close events. PR-URL: https://github.com/iojs/io.js/pull/217 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2014-12-29dgram: changes Socket.close() to return itselfBrendan Ashworth1-0/+2
This commit adds a return statement to the dgram.Socket.close() function that returns itself after it finishes. This follows along the functionality of the more popular and, dare I say, father-library `lib/net.js`. PR-URL: https://github.com/iojs/io.js/pull/214 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2014-12-29dgram: change Socket.bind() to return itselfBrendan Ashworth1-1/+3
This commit changes `lib/dgram.js` Sockets to, when they are bound to a port / IP, return themselves. This is done in order to allow chaining of methods and be in accordance with the `lib/net.js` library. PR-URL: https://github.com/iojs/io.js/pull/214 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2014-12-09src: all wraps now use actual FunctionTemplateTrevor Norris1-1/+4
Instead of simply creating a new v8::Object to contain the connection information, instantiate a new instance of a FunctionTemplate. This will allow future improvements for debugging and performance probes. Additionally, the "provider" argument in the ReqWrap constructor is no longer optional. PR-URL: https://github.com/joyent/node/pull/8110 Signed-off-by: Trevor Norris <trev.norris@gmail.com> Reviewed-by: Fedor Indutny <fedor@indutny.com> Reviewed-by: Alexis Campailla <alexis@janeasystems.com> Reviewed-by: Julien Gilli <julien.gilli@joyent.com>
2014-11-22lib: turn on strict modeBen Noordhuis1-0/+2
Turn on strict mode for the files in the lib/ directory. It helps catch bugs and can have a positive effect on performance. PR-URL: https://github.com/node-forward/node/pull/64 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Fedor Indutny <fedor@indutny.com>
2014-09-03net,dgram: workers can listen on exclusive portscjihrig1-7/+15
Allow cluster workers to listen on exclusive ports for TCP and UDP, instead of forcing all calls to go through the cluster master. Fixes: #3856 Reviewed-by: Trevor Norris <trev.norris@gmail.com> Reviewed-by: Fedor Indutny <fedor@indutny.com>
2014-08-12dgram: remove new keyword from errnoExceptionJackson Tian1-2/+2
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
2014-07-02udp: make it possible to receive empty udp packetsAndrius Bentkus1-3/+4
A udp packet can have 0 content. In that case nread will be equal to 0, but addr != NULL. Add test case for empty data gram packets and fixed test that checked for OOB when length == 0. Signed-off-by: Trevor Norris <trev.norris@gmail.com>
2014-04-10dgram: introduce `reuseAddr` optionFedor Indutny1-1/+14
Introduce new signature for both `dgram.createSocket` method and `dgram.Socket` constructor: dgram.createSocket(options, [listener]) Options should contain `type` property and may contain `reuseAddr` property. When `reuseAddr` is `true` - SO_REUSEADDR will be issued on socket on bind. fix #7415 Signed-off-by: Fedor Indutny <fedor@indutny.com>
2014-02-15dgram: pass the bytes sent to the send callbackTimothy J Fontaine1-1/+1
Fixes #6953
2013-10-28dgram: send() can accept stringsTrevor Norris1-1/+4
Strings passed to Socket#send() will be passed to Buffer and parsed as UTF8.
2013-08-15lib: remove unused variables and functionsBrian White1-9/+0
2013-08-09src: don't call v8::Object::SetHiddenValue()Ben Noordhuis1-1/+1
Don't use v8::Object::SetHiddenValue() to keep a reference alive to the buffer, we can just as easily do that from JS land and it's a lot faster to boot. Because the buffer is now a visible property of the write request object, it's essential that we do *not* log it - we'd be effectively serializing the whole buffer to a pretty-printed string.
2013-08-09dgram: don't call into js when send cb is omittedBen Noordhuis1-11/+18
Speed up dgram.Socket#send()-heavy code a little by omitting the call into JS land when the user doesn't pass us a completion callback.
2013-08-09dgram: fix regression in string argument handlingBen Noordhuis1-2/+16
v0.10 allows strings for the offset, length and port arguments to dgram.send() and dgram.sendto() but master before this commit would abort with the following assert: node: ../../src/udp_wrap.cc:227: static void node::UDPWrap::DoSend(const v8::FunctionCallbackInfo<v8::Value>&, int): Assertion `args[2]->IsUint32()' failed. Go beyond what v0.10 does and also add range checks: offset and length should be >= 0, port should be between 1 and 65535. That particular change needs to be back-ported to v0.10 because passing a negative offset or length number aborts with the following assertions: node: ../../src/udp_wrap.cc:264: static v8::Handle<v8::Value> node::UDPWrap::DoSend(const v8::Arguments&, int): Assertion `offset < Buffer::Length(buffer_obj)' failed. Or: node: ../../src/udp_wrap.cc:265: static v8::Handle<v8::Value> node::UDPWrap::DoSend(const v8::Arguments&, int): Assertion `length <= Buffer::Length(buffer_obj) - offset' failed. Interestingly enough, a negative port number is accepted in v0.10 but is silently ignored. This commit exposed a bug in the simple/test-dgram-close test which has also been fixed.
2013-08-01src: Replace macros with util functionsisaacs1-9/+9
2013-07-29dgram: report send errors to cb, don't pass bytesBen Noordhuis1-5/+3
Passing the number of sent bytes to the callback is superfluous; datagram sockets operate in atomic mode: either the sendmsg() system call succeeds or it fails but it never does partial writes. Instead, report send errors to the callback. UDP error reporting is fairly haphazard on most platforms. You should not expect reliable delivery of anything besides EMSGSIZE and (possibly) ENETDOWN and ENETUNREACH. Fixes #2608.
2013-07-28cluster: fix shared handle bind error propagationBen Noordhuis1-1/+7
A failed bind() was already being correctly reported in round-robin mode. This commit fixes bind() error reporting in shared handle mode. Fixes #5774.
2013-07-24lib: macro-ify type checksBen Noordhuis1-9/+9
Increases the grep factor. Makes it easier to harmonize type checks across the code base.
2013-07-20src, lib: update after internal api changeBen Noordhuis1-38/+41
Libuv now returns errors directly. Make everything in src/ and lib/ follow suit. The changes to lib/ are not strictly necessary but they remove the need for the abominations that are process._errno and node::SetErrno().
2013-07-20src, lib: deduplicate errnoExceptionBen Noordhuis1-8/+1
2013-07-03{stream,udp,tls}_wrap: remove unused offset/lengthTrevor Norris1-4/+4
The function arguments offset and length are now no longer used since all I/O requests now use discretely allocated memory.
2013-04-18dgram: fix no address bind()Ben Noordhuis1-0/+1
I broke dgram.Socket#bind(port, cb) almost a year ago in 332fea5a but it wasn't until today that someone complained and none of the tests caught it because they all either specify the address or omit the callback. Anyway, now it works again and does what you expect: it binds the socket to the "any" address ("0.0.0.0" for IPv4 and "::" for IPv6.)
2013-03-07child_process: support sending dgram socketAndreas Madsen1-13/+26
child.send can send net servers and sockets. Now that we have support for dgram clusters this functionality should be extended to include dgram sockets.
2013-02-28lib, src: remove errno globalBen Noordhuis1-10/+12
Remove the errno global. It's a property on the process object now. Fixes #3095.
2013-01-28dgram: avoid EventEmitter leak warningBert Belder1-3/+14
When a datagram socket hasn't been bound yet, node will defer `send()` operations until binding has completed. Before this patch a `listening` listener would be installed every time `send` was called. This triggered an EventEmitter leak warning when more than 10 packets were sent in a tight loop. Therefore switch to using a single `listening` listener, and use an array to enqueue outbound packets.
2013-01-28cluster: support datagram socketsBert Belder1-18/+72
2013-01-11Merge remote-tracking branch 'ry/v0.8' into masterisaacs1-0/+3
Conflicts: AUTHORS ChangeLog Makefile src/node_version.h
2013-01-08dgram: don't assert on send('string')Ben Noordhuis1-0/+3
Raise a TypeError when the argument to send() or sendto() is anything but a Buffer. Fixes the following assertion: $ node -e 'require("dgram").createSocket("udp4").send("BAM")' node: ../../src/udp_wrap.cc:220: static v8::Handle<v8::Value> node::UDPWrap::DoSend(const v8::Arguments&, int): Assertion `Buffer::HasInstance(args[0])' failed. Aborted (core dumped) Fixes #4496.
2012-12-31dgram: fix double implicit bind errorBen Noordhuis1-3/+13
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.