Skip to content

Commit 0f5f917

Browse files
committed
dgram: renamed buffer -> list in send
nits about variable names and push()
1 parent 1059d07 commit 0f5f917

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

lib/dgram.js

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,11 @@ function sliceBuffer(buffer, offset, length) {
263263
}
264264

265265

266-
function fixBuffer(buffer) {
267-
const newlist = new Array(buffer.length);
266+
function fixBufferList(list) {
267+
const newlist = new Array(list.length);
268268

269-
for (var i = 0, l = buffer.length; i < l; i++) {
270-
var buf = buffer[i];
269+
for (var i = 0, l = list.length; i < l; i++) {
270+
var buf = list[i];
271271
if (typeof buf === 'string')
272272
newlist[i] = Buffer.from(buf);
273273
else if (!(buf instanceof Buffer))
@@ -310,7 +310,8 @@ Socket.prototype.send = function(buffer,
310310
port,
311311
address,
312312
callback) {
313-
var self = this;
313+
const self = this;
314+
let list;
314315

315316
if (address || (port && typeof port !== 'function')) {
316317
buffer = sliceBuffer(buffer, offset, length);
@@ -322,13 +323,13 @@ Socket.prototype.send = function(buffer,
322323

323324
if (!Array.isArray(buffer)) {
324325
if (typeof buffer === 'string') {
325-
buffer = [ Buffer.from(buffer) ];
326+
list = [ Buffer.from(buffer) ];
326327
} else if (!(buffer instanceof Buffer)) {
327328
throw new TypeError('First argument must be a buffer or a string');
328329
} else {
329-
buffer = [ buffer ];
330+
list = [ buffer ];
330331
}
331-
} else if (!(buffer = fixBuffer(buffer))) {
332+
} else if (!(list = fixBufferList(buffer))) {
332333
throw new TypeError('Buffer list arguments must be buffers or strings');
333334
}
334335

@@ -346,23 +347,23 @@ Socket.prototype.send = function(buffer,
346347
if (self._bindState == BIND_STATE_UNBOUND)
347348
self.bind({port: 0, exclusive: true}, null);
348349

349-
if (buffer.length === 0)
350-
buffer[0] = Buffer.allocUnsafe(0);
350+
if (list.length === 0)
351+
list.push(Buffer.allocUnsafe(0));
351352

352353
// If the socket hasn't been bound yet, push the outbound packet onto the
353354
// send queue and send after binding is complete.
354355
if (self._bindState != BIND_STATE_BOUND) {
355-
enqueue(self, [buffer, port, address, callback]);
356+
enqueue(self, [list, port, address, callback]);
356357
return;
357358
}
358359

359360
self._handle.lookup(address, function afterDns(ex, ip) {
360-
doSend(ex, self, ip, buffer, address, port, callback);
361+
doSend(ex, self, ip, list, address, port, callback);
361362
});
362363
};
363364

364365

365-
function doSend(ex, self, ip, buffer, address, port, callback) {
366+
function doSend(ex, self, ip, list, address, port, callback) {
366367
if (ex) {
367368
if (typeof callback === 'function') {
368369
callback(ex);
@@ -376,16 +377,16 @@ function doSend(ex, self, ip, buffer, address, port, callback) {
376377
}
377378

378379
var req = new SendWrap();
379-
req.buffer = buffer; // Keep reference alive.
380+
req.list = list; // Keep reference alive.
380381
req.address = address;
381382
req.port = port;
382383
if (callback) {
383384
req.callback = callback;
384385
req.oncomplete = afterSend;
385386
}
386387
var err = self._handle.send(req,
387-
buffer,
388-
buffer.length,
388+
list,
389+
list.length,
389390
port,
390391
ip,
391392
!!callback);

src/udp_wrap.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ void UDPWrap::DoSend(const FunctionCallbackInfo<Value>& args, int family) {
257257
args.Holder(),
258258
args.GetReturnValue().Set(UV_EBADF));
259259

260-
// send(req, buffer, port, address, hasCallback)
260+
// send(req, list, port, address, hasCallback)
261261
CHECK(args[0]->IsObject());
262262
CHECK(args[1]->IsArray());
263263
CHECK(args[2]->IsUint32());

0 commit comments

Comments
 (0)