{"action":"created","comment":{"url":"https://api.github.com/repos/libuv/libuv/pulls/comments/194889300","pull_request_review_id":128149233,"id":194889300,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE5NDg4OTMwMA==","diff_hunk":"@@ -284,24 +284,87 @@ int uv_tcp_connect(uv_connect_t* req,\n }\n \n \n-int uv_udp_send(uv_udp_send_t* req,\n-                uv_udp_t* handle,\n-                const uv_buf_t bufs[],\n-                unsigned int nbufs,\n-                const struct sockaddr* addr,\n-                uv_udp_send_cb send_cb) {\n+int uv_udp_connect(uv_udp_t* handle, const struct sockaddr* addr) {\n   unsigned int addrlen;\n \n   if (handle->type != UV_UDP)\n     return UV_EINVAL;\n \n+  /* Disconnect the handle */\n+  if (addr == NULL) {\n+    if (!(handle->flags & UV__UDP_CONNECTED))\n+      return UV_ENOTCONN;\n+\n+    return uv__udp_disconnect(handle);\n+  }\n+\n   if (addr->sa_family == AF_INET)\n     addrlen = sizeof(struct sockaddr_in);\n   else if (addr->sa_family == AF_INET6)\n     addrlen = sizeof(struct sockaddr_in6);\n   else\n     return UV_EINVAL;\n \n+  if (handle->flags & UV__UDP_CONNECTED)\n+    return UV_EISCONN;\n+\n+  return uv__udp_connect(handle, addr, addrlen);\n+}\n+\n+\n+int uv__udp_is_connected(uv_udp_t* handle) {\n+  struct sockaddr_storage addr;\n+  int addrlen;\n+  if (handle->type != UV_UDP)\n+    return 0;\n+\n+  addrlen = sizeof(addr);\n+  if (uv_udp_getpeername(handle, (struct sockaddr*) &addr, &addrlen) != 0)\n+    return 0;\n+\n+  return addrlen > 0;\n+}\n+\n+\n+int uv__udp_check_before_send(uv_udp_t* handle, const struct sockaddr* addr) {\n+  unsigned int addrlen;\n+\n+  if (handle->type != UV_UDP)\n+    return UV_EINVAL;\n+\n+  if (addr != NULL && (handle->flags & UV__UDP_CONNECTED))\n+    return UV_EISCONN;\n+\n+  if (addr == NULL && !(handle->flags & UV__UDP_CONNECTED))\n+    return UV_EDESTADDRREQ;\n+\n+  if (addr != NULL) {\n+    if (addr->sa_family == AF_INET)\n+      addrlen = sizeof(struct sockaddr_in);\n+    else if (addr->sa_family == AF_INET6)\n+      addrlen = sizeof(struct sockaddr_in6);\n+    else\n+      return UV_EINVAL;","path":"src/uv-common.c","position":70,"original_position":70,"commit_id":"015d1830c89adda8dfdc9f18b0cd2f0cdb02dfcd","original_commit_id":"94adb2020490b9774f7b1c12bf4bf7745dd2be72","user":{"login":"cjihrig","id":2512748,"node_id":"MDQ6VXNlcjI1MTI3NDg=","avatar_url":"https://avatars1.githubusercontent.com/u/2512748?v=4","gravatar_id":"","url":"https://api.github.com/users/cjihrig","html_url":"https://github.com/cjihrig","followers_url":"https://api.github.com/users/cjihrig/followers","following_url":"https://api.github.com/users/cjihrig/following{/other_user}","gists_url":"https://api.github.com/users/cjihrig/gists{/gist_id}","starred_url":"https://api.github.com/users/cjihrig/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cjihrig/subscriptions","organizations_url":"https://api.github.com/users/cjihrig/orgs","repos_url":"https://api.github.com/users/cjihrig/repos","events_url":"https://api.github.com/users/cjihrig/events{/privacy}","received_events_url":"https://api.github.com/users/cjihrig/received_events","type":"User","site_admin":false},"body":"Sorry, you're right. `UV__ERR()` only negates errors on platforms where they are positive.","created_at":"2018-06-12T21:07:15Z","updated_at":"2018-06-12T21:07:16Z","html_url":"https://github.com/libuv/libuv/pull/1872#discussion_r194889300","pull_request_url":"https://api.github.com/repos/libuv/libuv/pulls/1872","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/libuv/libuv/pulls/comments/194889300"},"html":{"href":"https://github.com/libuv/libuv/pull/1872#discussion_r194889300"},"pull_request":{"href":"https://api.github.com/repos/libuv/libuv/pulls/1872"}},"in_reply_to_id":194257286},"pull_request":{"url":"https://api.github.com/repos/libuv/libuv/pulls/1872","id":193529395,"node_id":"MDExOlB1bGxSZXF1ZXN0MTkzNTI5Mzk1","html_url":"https://github.com/libuv/libuv/pull/1872","diff_url":"https://github.com/libuv/libuv/pull/1872.diff","patch_url":"https://github.com/libuv/libuv/pull/1872.patch","issue_url":"https://api.github.com/repos/libuv/libuv/issues/1872","number":1872,"state":"open","locked":false,"title":"udp: add support for UDP connected sockets","user":{"login":"santigimeno","id":1084056,"node_id":"MDQ6VXNlcjEwODQwNTY=","avatar_url":"https://avatars2.githubusercontent.com/u/1084056?v=4","gravatar_id":"","url":"https://api.github.com/users/santigimeno","html_url":"https://github.com/santigimeno","followers_url":"https://api.github.com/users/santigimeno/followers","following_url":"https://api.github.com/users/santigimeno/following{/other_user}","gists_url":"https://api.github.com/users/santigimeno/gists{/gist_id}","starred_url":"https://api.github.com/users/santigimeno/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/santigimeno/subscriptions","organizations_url":"https://api.github.com/users/santigimeno/orgs","repos_url":"https://api.github.com/users/santigimeno/repos","events_url":"https://api.github.com/users/santigimeno/events{/privacy}","received_events_url":"https://api.github.com/users/santigimeno/received_events","type":"User","site_admin":false},"body":"Following the conversation at https://github.com/libuv/leps/pull/10, I've implemented the API as @saghul suggested. Also I've targeted the PR to `v1.x` but could be easily retargeted to `master`.\r\n\r\nI've split it into 3 different commits:\r\n\r\n- unix: refactor getsockname/getpeername methods\r\n- win,udp: allow to use uv_udp_open on bound sockets\r\n- udp: add support for UDP connected sockets\r\n    \r\n    Add two new methods:\r\n    \r\n    `uv_udp_connect()` to connect / disconnect an UDP handle.\r\n    `uv_udp_getpeername()` to get the remote peer address of a connected UDP\r\n    handle.\r\n    \r\n    Modify `uv_udp_send()` and `uv_udp_try_send()` to accept a `NULL` `addr`\r\n    to send messages over an \"UDP connection\".\r\n\r\nCI: https://ci.nodejs.org/view/libuv/job/libuv-test-commit/913/","created_at":"2018-06-08T07:23:58Z","updated_at":"2018-06-12T21:07:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4f80ef5c768e2bb87220271e528628ac6664b537","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/libuv/libuv/pulls/1872/commits","review_comments_url":"https://api.github.com/repos/libuv/libuv/pulls/1872/comments","review_comment_url":"https://api.github.com/repos/libuv/libuv/pulls/comments{/number}","comments_url":"https://api.github.com/repos/libuv/libuv/issues/1872/comments","statuses_url":"https://api.github.com/repos/libuv/libuv/statuses/015d1830c89adda8dfdc9f18b0cd2f0cdb02dfcd","head":{"label":"santigimeno:udp_udp","ref":"udp_udp","sha":"015d1830c89adda8dfdc9f18b0cd2f0cdb02dfcd","user":{"login":"santigimeno","id":1084056,"node_id":"MDQ6VXNlcjEwODQwNTY=","avatar_url":"https://avatars2.githubusercontent.com/u/1084056?v=4","gravatar_id":"","url":"https://api.github.com/users/santigimeno","html_url":"https://github.com/santigimeno","followers_url":"https://api.github.com/users/santigimeno/followers","following_url":"https://api.github.com/users/santigimeno/following{/other_user}","gists_url":"https://api.github.com/users/santigimeno/gists{/gist_id}","starred_url":"https://api.github.com/users/santigimeno/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/santigimeno/subscriptions","organizations_url":"https://api.github.com/users/santigimeno/orgs","repos_url":"https://api.github.com/users/santigimeno/repos","events_url":"https://api.github.com/users/santigimeno/events{/privacy}","received_events_url":"https://api.github.com/users/santigimeno/received_events","type":"User","site_admin":false},"repo":{"id":32668466,"node_id":"MDEwOlJlcG9zaXRvcnkzMjY2ODQ2Ng==","name":"libuv","full_name":"santigimeno/libuv","owner":{"login":"santigimeno","id":1084056,"node_id":"MDQ6VXNlcjEwODQwNTY=","avatar_url":"https://avatars2.githubusercontent.com/u/1084056?v=4","gravatar_id":"","url":"https://api.github.com/users/santigimeno","html_url":"https://github.com/santigimeno","followers_url":"https://api.github.com/users/santigimeno/followers","following_url":"https://api.github.com/users/santigimeno/following{/other_user}","gists_url":"https://api.github.com/users/santigimeno/gists{/gist_id}","starred_url":"https://api.github.com/users/santigimeno/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/santigimeno/subscriptions","organizations_url":"https://api.github.com/users/santigimeno/orgs","repos_url":"https://api.github.com/users/santigimeno/repos","events_url":"https://api.github.com/users/santigimeno/events{/privacy}","received_events_url":"https://api.github.com/users/santigimeno/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/santigimeno/libuv","description":"Cross-platform asychronous I/O","fork":true,"url":"https://api.github.com/repos/santigimeno/libuv","forks_url":"https://api.github.com/repos/santigimeno/libuv/forks","keys_url":"https://api.github.com/repos/santigimeno/libuv/keys{/key_id}","collaborators_url":"https://api.github.com/repos/santigimeno/libuv/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/santigimeno/libuv/teams","hooks_url":"https://api.github.com/repos/santigimeno/libuv/hooks","issue_events_url":"https://api.github.com/repos/santigimeno/libuv/issues/events{/number}","events_url":"https://api.github.com/repos/santigimeno/libuv/events","assignees_url":"https://api.github.com/repos/santigimeno/libuv/assignees{/user}","branches_url":"https://api.github.com/repos/santigimeno/libuv/branches{/branch}","tags_url":"https://api.github.com/repos/santigimeno/libuv/tags","blobs_url":"https://api.github.com/repos/santigimeno/libuv/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/santigimeno/libuv/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/santigimeno/libuv/git/refs{/sha}","trees_url":"https://api.github.com/repos/santigimeno/libuv/git/trees{/sha}","statuses_url":"https://api.github.com/repos/santigimeno/libuv/statuses/{sha}","languages_url":"https://api.github.com/repos/santigimeno/libuv/languages","stargazers_url":"https://api.github.com/repos/santigimeno/libuv/stargazers","contributors_url":"https://api.github.com/repos/santigimeno/libuv/contributors","subscribers_url":"https://api.github.com/repos/santigimeno/libuv/subscribers","subscription_url":"https://api.github.com/repos/santigimeno/libuv/subscription","commits_url":"https://api.github.com/repos/santigimeno/libuv/commits{/sha}","git_commits_url":"https://api.github.com/repos/santigimeno/libuv/git/commits{/sha}","comments_url":"https://api.github.com/repos/santigimeno/libuv/comments{/number}","issue_comment_url":"https://api.github.com/repos/santigimeno/libuv/issues/comments{/number}","contents_url":"https://api.github.com/repos/santigimeno/libuv/contents/{+path}","compare_url":"https://api.github.com/repos/santigimeno/libuv/compare/{base}...{head}","merges_url":"https://api.github.com/repos/santigimeno/libuv/merges","archive_url":"https://api.github.com/repos/santigimeno/libuv/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/santigimeno/libuv/downloads","issues_url":"https://api.github.com/repos/santigimeno/libuv/issues{/number}","pulls_url":"https://api.github.com/repos/santigimeno/libuv/pulls{/number}","milestones_url":"https://api.github.com/repos/santigimeno/libuv/milestones{/number}","notifications_url":"https://api.github.com/repos/santigimeno/libuv/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/santigimeno/libuv/labels{/name}","releases_url":"https://api.github.com/repos/santigimeno/libuv/releases{/id}","deployments_url":"https://api.github.com/repos/santigimeno/libuv/deployments","created_at":"2015-03-22T08:50:59Z","updated_at":"2016-09-12T06:34:41Z","pushed_at":"2018-06-12T20:20:17Z","git_url":"git://github.com/santigimeno/libuv.git","ssh_url":"git@github.com:santigimeno/libuv.git","clone_url":"https://github.com/santigimeno/libuv.git","svn_url":"https://github.com/santigimeno/libuv","homepage":"http://libuv.org/","size":13311,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"v1.x"}},"base":{"label":"libuv:v1.x","ref":"v1.x","sha":"0cdb4a5b4b706d0e09413d9270da28f9a88dc083","user":{"login":"libuv","id":4030929,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQwMzA5Mjk=","avatar_url":"https://avatars1.githubusercontent.com/u/4030929?v=4","gravatar_id":"","url":"https://api.github.com/users/libuv","html_url":"https://github.com/libuv","followers_url":"https://api.github.com/users/libuv/followers","following_url":"https://api.github.com/users/libuv/following{/other_user}","gists_url":"https://api.github.com/users/libuv/gists{/gist_id}","starred_url":"https://api.github.com/users/libuv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/libuv/subscriptions","organizations_url":"https://api.github.com/users/libuv/orgs","repos_url":"https://api.github.com/users/libuv/repos","events_url":"https://api.github.com/users/libuv/events{/privacy}","received_events_url":"https://api.github.com/users/libuv/received_events","type":"Organization","site_admin":false},"repo":{"id":14812739,"node_id":"MDEwOlJlcG9zaXRvcnkxNDgxMjczOQ==","name":"libuv","full_name":"libuv/libuv","owner":{"login":"libuv","id":4030929,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQwMzA5Mjk=","avatar_url":"https://avatars1.githubusercontent.com/u/4030929?v=4","gravatar_id":"","url":"https://api.github.com/users/libuv","html_url":"https://github.com/libuv","followers_url":"https://api.github.com/users/libuv/followers","following_url":"https://api.github.com/users/libuv/following{/other_user}","gists_url":"https://api.github.com/users/libuv/gists{/gist_id}","starred_url":"https://api.github.com/users/libuv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/libuv/subscriptions","organizations_url":"https://api.github.com/users/libuv/orgs","repos_url":"https://api.github.com/users/libuv/repos","events_url":"https://api.github.com/users/libuv/events{/privacy}","received_events_url":"https://api.github.com/users/libuv/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/libuv/libuv","description":"Cross-platform asynchronous I/O","fork":false,"url":"https://api.github.com/repos/libuv/libuv","forks_url":"https://api.github.com/repos/libuv/libuv/forks","keys_url":"https://api.github.com/repos/libuv/libuv/keys{/key_id}","collaborators_url":"https://api.github.com/repos/libuv/libuv/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/libuv/libuv/teams","hooks_url":"https://api.github.com/repos/libuv/libuv/hooks","issue_events_url":"https://api.github.com/repos/libuv/libuv/issues/events{/number}","events_url":"https://api.github.com/repos/libuv/libuv/events","assignees_url":"https://api.github.com/repos/libuv/libuv/assignees{/user}","branches_url":"https://api.github.com/repos/libuv/libuv/branches{/branch}","tags_url":"https://api.github.com/repos/libuv/libuv/tags","blobs_url":"https://api.github.com/repos/libuv/libuv/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/libuv/libuv/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/libuv/libuv/git/refs{/sha}","trees_url":"https://api.github.com/repos/libuv/libuv/git/trees{/sha}","statuses_url":"https://api.github.com/repos/libuv/libuv/statuses/{sha}","languages_url":"https://api.github.com/repos/libuv/libuv/languages","stargazers_url":"https://api.github.com/repos/libuv/libuv/stargazers","contributors_url":"https://api.github.com/repos/libuv/libuv/contributors","subscribers_url":"https://api.github.com/repos/libuv/libuv/subscribers","subscription_url":"https://api.github.com/repos/libuv/libuv/subscription","commits_url":"https://api.github.com/repos/libuv/libuv/commits{/sha}","git_commits_url":"https://api.github.com/repos/libuv/libuv/git/commits{/sha}","comments_url":"https://api.github.com/repos/libuv/libuv/comments{/number}","issue_comment_url":"https://api.github.com/repos/libuv/libuv/issues/comments{/number}","contents_url":"https://api.github.com/repos/libuv/libuv/contents/{+path}","compare_url":"https://api.github.com/repos/libuv/libuv/compare/{base}...{head}","merges_url":"https://api.github.com/repos/libuv/libuv/merges","archive_url":"https://api.github.com/repos/libuv/libuv/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/libuv/libuv/downloads","issues_url":"https://api.github.com/repos/libuv/libuv/issues{/number}","pulls_url":"https://api.github.com/repos/libuv/libuv/pulls{/number}","milestones_url":"https://api.github.com/repos/libuv/libuv/milestones{/number}","notifications_url":"https://api.github.com/repos/libuv/libuv/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/libuv/libuv/labels{/name}","releases_url":"https://api.github.com/repos/libuv/libuv/releases{/id}","deployments_url":"https://api.github.com/repos/libuv/libuv/deployments","created_at":"2013-11-30T00:29:56Z","updated_at":"2018-06-12T17:49:19Z","pushed_at":"2018-06-12T20:20:21Z","git_url":"git://github.com/libuv/libuv.git","ssh_url":"git@github.com:libuv/libuv.git","clone_url":"https://github.com/libuv/libuv.git","svn_url":"https://github.com/libuv/libuv","homepage":"http://libuv.org/","size":13080,"stargazers_count":9542,"watchers_count":9542,"language":"C","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1581,"mirror_url":null,"archived":false,"open_issues_count":145,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":1581,"open_issues":145,"watchers":9542,"default_branch":"v1.x"}},"_links":{"self":{"href":"https://api.github.com/repos/libuv/libuv/pulls/1872"},"html":{"href":"https://github.com/libuv/libuv/pull/1872"},"issue":{"href":"https://api.github.com/repos/libuv/libuv/issues/1872"},"comments":{"href":"https://api.github.com/repos/libuv/libuv/issues/1872/comments"},"review_comments":{"href":"https://api.github.com/repos/libuv/libuv/pulls/1872/comments"},"review_comment":{"href":"https://api.github.com/repos/libuv/libuv/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/libuv/libuv/pulls/1872/commits"},"statuses":{"href":"https://api.github.com/repos/libuv/libuv/statuses/015d1830c89adda8dfdc9f18b0cd2f0cdb02dfcd"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"cjihrig"}}