Showing with 49 additions and 19 deletions.
  1. +8 −3 doc/api/dgram.markdown
  2. +3 −5 lib/dgram.js
  3. +2 −8 src/udp_wrap.cc
  4. +35 −0 test/simple/test-dgram-msgsize.js
  5. +1 −3 test/simple/test-dgram-udp4.js
@@ -48,8 +48,13 @@ should be created via `dgram.createSocket(type, [callback])`.
* `msg` Buffer object. The message
* `rinfo` Object. Remote address information

Emitted when a new datagram is available on a socket. `msg` is a `Buffer` and `rinfo` is
an object with the sender's address information and the number of bytes in the datagram.
Emitted when a new datagram is available on a socket. `msg` is a `Buffer` and
`rinfo` is an object with the sender's address information:

socket.on('message', function(msg, rinfo) {
console.log('Received %d bytes from %s:%d\n',
msg.length, rinfo.address, rinfo.port);
});

### Event: 'listening'

@@ -93,7 +98,7 @@ Example of sending a UDP packet to a random port on `localhost`;
var dgram = require('dgram');
var message = new Buffer("Some bytes");
var client = dgram.createSocket("udp4");
client.send(message, 0, message.length, 41234, "localhost", function(err, bytes) {
client.send(message, 0, message.length, 41234, "localhost", function(err) {
client.close();
});

@@ -302,11 +302,9 @@ Socket.prototype.send = function(buffer,
};


function afterSend(status, handle, req, buffer) {
var self = handle.owner;

if (req.cb)
req.cb(null, buffer.length); // compatibility with dgram_legacy.js
function afterSend(err) {
if (this.cb)
this.cb(err ? errnoException(err, 'send') : null);
}


@@ -341,14 +341,8 @@ void UDPWrap::OnSend(uv_udp_send_t* req, int status) {
assert(wrap->persistent().IsEmpty() == false);

Local<Object> req_wrap_obj = req_wrap->object();
Local<Value> argv[] = {
Integer::New(status, node_isolate),
wrap->object(),
req_wrap_obj,
req_wrap_obj->GetHiddenValue(buffer_sym),
};

MakeCallback(req_wrap_obj, oncomplete_sym, ARRAY_SIZE(argv), argv);
Local<Value> arg = Integer::New(status, node_isolate);
MakeCallback(req_wrap_obj, oncomplete_sym, 1, &arg);
delete req_wrap;
}

@@ -0,0 +1,35 @@
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

var common = require('../common');
var assert = require('assert');
var dgram = require('dgram');

// Send a too big datagram. The destination doesn't matter because it's
// not supposed to get sent out anyway.
var buf = Buffer(256 * 1024);
var sock = dgram.createSocket('udp4');
sock.send(buf, 0, buf.length, 12345, '127.0.0.1', common.mustCall(cb));
function cb(err) {
assert(err instanceof Error);
assert.equal(err.code, 'EMSGSIZE');
sock.close();
}
@@ -54,13 +54,11 @@ server.on('listening', function() {
server.close();
});
client.send(message_to_send, 0, message_to_send.length,
server_port, 'localhost', function(err, bytes) {
server_port, 'localhost', function(err) {
if (err) {
console.log('Caught error in client send.');
throw err;
}
console.log('client wrote ' + bytes + ' bytes.');
assert.strictEqual(bytes, message_to_send.length);
});
client.on('close',
function() {