Skip to content

Conversation

@santigimeno
Copy link
Member

Added the dgram.connect() and dgram.disconnect() methods that
associate/disassociate a udp socket to/from a remote address.
It optimizes for cases where lots of packets are sent to the same
address.
Also added the dgram.remoteAddress() method to retrieve the associated
remote address.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

Would like some feedback as I'm not sure about some decisions I made:

  • Should a disconnect event be added?
  • I'm throwing on the ENOTCONN and EISCONN errors. Should I be emitting an event instead?
  • The send() is now more overloaded than ever.

Thanks

@nodejs-github-botnodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. labels Mar 22, 2019
@santigimeno
Copy link
MemberAuthor

/cc @cjihrig

@santigimenosantigimeno added the dgram Issues and PRs related to the dgram subsystem / UDP. label Mar 22, 2019
@reklatsmasters
Copy link
Contributor

I think this API shouldn't be a part of nodejs core. There may be some misunderstandings. Some developers may expect messages only from a connected socket, like in tcp, but it's not. You may receive messages from anyone but may send only to an associated address. It's important.

Almost a year ago i solved this problem by creating unicast. This module provided real 1:1 association (for incoming and outgoing messages) and streaming interface.

@santigimeno
Copy link
MemberAuthor

@reklatsmasters I think that's actually how a connected UDP socket behaves (and tested locally in linux). From the linux connect(2) manual:

If the socket sockfd is of type SOCK_DGRAM, then addr is the address to which datagrams are sent by default, and the only address from which datagrams are received.

@reklatsmasters
Copy link
Contributor

@santigimeno Thanks for the explanation! I researched only the libuv sources.

It would be great to implement a connected UDP socket like a duplex stream.

@santigimeno
Copy link
MemberAuthor

Updated to add the review comments. Thanks!

@BridgeARBridgeAR added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Mar 27, 2019
@nodejs-github-bot
Copy link
Collaborator

Copy link
Contributor

@vsemozhetbytvsemozhetbyt left a comment

Choose a reason for hiding this comment

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

Some doc nits.

@santigimeno
Copy link
MemberAuthor

santigimeno commented Mar 29, 2019

Updated addressing docs comments. Thanks

@targos
Copy link
Member

this needs to be rebased.

/cc @nodejs/dgram

@targostargos removed the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Mar 30, 2019
@santigimeno
Copy link
MemberAuthor

Rebased to current master.

@nodejs-github-bot
Copy link
Collaborator

@danbev
Copy link
Contributor

Re-run of failing node-test-commit-linux

Copy link
Member

@mcollinamcollina left a comment

Choose a reason for hiding this comment

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

LGTM

@BridgeARBridgeAR added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Apr 1, 2019
@danbev
Copy link
Contributor

test/parallel/test-dgram-connect.js seems to be consistently failing on ubuntu.

test/osx failure looks unrelated

console output:

08:22:28 not ok 386 parallel/test-dgram-connect08:22:28 ---08:22:28 duration_ms: 0.7608:22:28 severity: fail08:22:28 exitcode: 108:22:28 stack: |-08:22:28 assert.js:8708:22:28 throw new AssertionError(obj);08:22:28 ^08:22:28 08:22:28 AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:08:22:28 + actual - expected08:22:28 08:22:28 + 'EAI_AGAIN'08:22:28 - 'ENOTFOUND'08:22:28 at /home/iojs/build/workspace/node-test-commit-linux/nodes/ubuntu1804-64/test/parallel/test-dgram-connect.js:40:1208:22:28 at /home/iojs/build/workspace/node-test-commit-linux/nodes/ubuntu1804-64/test/common/index.js:369:1508:22:28 at dgram.js:408:908:22:28 at processTicksAndRejections (internal/process/task_queues.js:79:9)08:22:28 ...

Added the `dgram.connect()` and `dgram.disconnect()` methods that associate/disassociate a udp socket to/from a remote address. It optimizes for cases where lots of packets are sent to the same address. Also added the `dgram.remoteAddress()` method to retrieve the associated remote address.
@santigimeno
Copy link
MemberAuthor

Updated with a test fixup. Thanks!

@nodejs-github-bot
Copy link
Collaborator

@danbev
Copy link
Contributor

Re-build of failing node-test-commit-linux (✔️)

@danbev
Copy link
Contributor

Landed in 9e96017.

@danbevdanbev closed this Apr 3, 2019
danbev pushed a commit that referenced this pull request Apr 3, 2019
Added the `dgram.connect()` and `dgram.disconnect()` methods that associate/disassociate a udp socket to/from a remote address. It optimizes for cases where lots of packets are sent to the same address. Also added the `dgram.remoteAddress()` method to retrieve the associated remote address. PR-URL: #26871 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
@santigimenosantigimeno deleted the udp_connect branch April 3, 2019 08:04
BethGriggs pushed a commit that referenced this pull request Apr 4, 2019
Added the `dgram.connect()` and `dgram.disconnect()` methods that associate/disassociate a udp socket to/from a remote address. It optimizes for cases where lots of packets are sent to the same address. Also added the `dgram.remoteAddress()` method to retrieve the associated remote address. PR-URL: #26871 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
@MylesBorinsMylesBorins added the semver-minor PRs that contain new features and should be released in the next minor version. label May 16, 2019
GaryGSC pushed a commit to GaryGSC/node that referenced this pull request Nov 14, 2019
Added the `dgram.connect()` and `dgram.disconnect()` methods that associate/disassociate a udp socket to/from a remote address. It optimizes for cases where lots of packets are sent to the same address. Also added the `dgram.remoteAddress()` method to retrieve the associated remote address. Backport-PR-URL: nodejs#30480 PR-URL: nodejs#26871 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Matteo Collina <[email protected]> (cherry picked from commit 9e96017)
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author readyPRs that have at least one approval, no pending requests for changes, and a CI started.c++Issues and PRs that require attention from people who are familiar with C++.dgramIssues and PRs related to the dgram subsystem / UDP.lib / srcIssues and PRs related to general changes in the lib or src directory.semver-minorPRs that contain new features and should be released in the next minor version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

11 participants

@santigimeno@nodejs-github-bot@reklatsmasters@targos@danbev@mcollina@cjihrig@vsemozhetbyt@MylesBorins@BethGriggs@BridgeAR