Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
dgram: support for setting socket buffer size
setRecvBufferSize(int) and setSendBufferSize(int)
  • Loading branch information
DamienOReilly committed Sep 10, 2017
commit b84bf9579f87ed17f3fbfdfb42e5232e5634cb11
19 changes: 19 additions & 0 deletions lib/dgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,25 @@ Socket.prototype.unref = function() {
return this;
};


Socket.prototype.setRecvBufferSize = function(size) {
var err = this._handle.setRecvBufferSize(size);

if (err) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style nit: Core prefers no curly braces on single line ifs.

throw errnoException(err, 'setRecvBufferSize');
}
};


Socket.prototype.setSendBufferSize = function(size) {
var err = this._handle.setSendBufferSize(size);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because _handle.setSendBufferSize() includes a CHECK that will abort if size is not UInt32, these should do a proper type check in the js side. Otherwise users will not be happy.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we'd prefer a check in JS that will throw an internal/errors.TypeError
this is a good check Number.isFinite(num) && num <= Number.MAX_SAFE_INTEGER && num >= 0;
Ref: https://github.com/nodejs/node/blob/master/lib/internal/process.js#L31
Ref: https://github.com/nodejs/node/blob/master/lib/internal/process.js#L62

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a good check Number.isFinite(num) && num <= Number.MAX_SAFE_INTEGER && num >= 0;

It’s not an uint32 check, though. I think num >>> 0 === num would work.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, completely forgot about the existence of >>>
So much fun working with talented people 🕺


if (err) {
throw errnoException(err, 'setSendBufferSize');
}
};


module.exports = {
_createSocketHandle,
createSocket,
Expand Down