{"action":"created","comment":{"url":"https://api.github.com/repos/dotnet/corefx/pulls/comments/77870618","id":77870618,"diff_hunk":"@@ -2071,6 +2071,51 @@ extern \"C\" Error SystemNative_GetSockOpt(\n \n     int fd = ToFileDescriptor(socket);\n \n+    //\n+    // Handle some special cases for compatibility with Windows\n+    //\n+    if (socketOptionLevel == PAL_SOL_SOCKET)\n+    {\n+        if (socketOptionName == PAL_SO_EXCLUSIVEADDRUSE)\n+        {\n+            //\n+            // SO_EXCLUSIVEADDRUSE makes Windows behave like Unix platforms do WRT the SO_REUSEADDR option.\n+            // So, for non-Windows platforms, we act as if SO_EXCLUSIVEADDRUSE is always enabled.\n+            //\n+            if (*optionLen != sizeof(int32_t))\n+            {\n+                return PAL_EINVAL;\n+            }\n+\n+            *reinterpret_cast<int32_t*>(optionValue) = 1;\n+            return PAL_SUCCESS;\n+        }\n+        else if (socketOptionName == PAL_SO_REUSEADDR)\n+        {\n+            //\n+            // On Windows, SO_REUSEADDR allows the address *and* port to be reused.  It's equivalent to \n+            // SO_REUSEADDR + SO_REUSEPORT other systems.  Se we only return \"true\" if both of those options are true.\n+            //\n+            auto optLen = static_cast<socklen_t>(*optionLen);\n+\n+            int err = getsockopt(fd, SOL_SOCKET, SO_REUSEADDR, optionValue, &optLen);\n+\n+            if (err == 0 && *reinterpret_cast<uint32_t*>(optionValue) != 0)\n+            {\n+                err = getsockopt(fd, SOL_SOCKET, SO_REUSEPORT, optionValue, &optLen);","path":"src/Native/Unix/System.Native/pal_networking.cpp","position":35,"original_position":35,"commit_id":"aa4c736675e60ce769bed07b8d79a4ab6f6248f9","original_commit_id":"aa4c736675e60ce769bed07b8d79a4ab6f6248f9","user":{"login":"CIPop","id":8635911,"avatar_url":"https://avatars.githubusercontent.com/u/8635911?v=3","gravatar_id":"","url":"https://api.github.com/users/CIPop","html_url":"https://github.com/CIPop","followers_url":"https://api.github.com/users/CIPop/followers","following_url":"https://api.github.com/users/CIPop/following{/other_user}","gists_url":"https://api.github.com/users/CIPop/gists{/gist_id}","starred_url":"https://api.github.com/users/CIPop/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CIPop/subscriptions","organizations_url":"https://api.github.com/users/CIPop/orgs","repos_url":"https://api.github.com/users/CIPop/repos","events_url":"https://api.github.com/users/CIPop/events{/privacy}","received_events_url":"https://api.github.com/users/CIPop/received_events","type":"User","site_admin":false},"body":"As pointed out in the design discussion, this could be confusing: what if on *NIX I only want to set `SO_REUSEPORT` but not `SO_REUSEADDR`? \r\nIs that a a valid *NIX scenario? If yes, is there a way to achieve that somehow?","created_at":"2016-09-07T17:43:01Z","updated_at":"2016-09-07T17:43:01Z","html_url":"https://github.com/dotnet/corefx/pull/11509#discussion_r77870618","pull_request_url":"https://api.github.com/repos/dotnet/corefx/pulls/11509","_links":{"self":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/comments/77870618"},"html":{"href":"https://github.com/dotnet/corefx/pull/11509#discussion_r77870618"},"pull_request":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/11509"}}},"pull_request":{"url":"https://api.github.com/repos/dotnet/corefx/pulls/11509","id":84342034,"html_url":"https://github.com/dotnet/corefx/pull/11509","diff_url":"https://github.com/dotnet/corefx/pull/11509.diff","patch_url":"https://github.com/dotnet/corefx/pull/11509.patch","issue_url":"https://api.github.com/repos/dotnet/corefx/issues/11509","number":11509,"state":"open","locked":false,"title":"Rework ExclusiveAddressUse and ReuseAddress on non-Windows platforms","user":{"login":"ericeil","id":7407587,"avatar_url":"https://avatars.githubusercontent.com/u/7407587?v=3","gravatar_id":"","url":"https://api.github.com/users/ericeil","html_url":"https://github.com/ericeil","followers_url":"https://api.github.com/users/ericeil/followers","following_url":"https://api.github.com/users/ericeil/following{/other_user}","gists_url":"https://api.github.com/users/ericeil/gists{/gist_id}","starred_url":"https://api.github.com/users/ericeil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ericeil/subscriptions","organizations_url":"https://api.github.com/users/ericeil/orgs","repos_url":"https://api.github.com/users/ericeil/repos","events_url":"https://api.github.com/users/ericeil/events{/privacy}","received_events_url":"https://api.github.com/users/ericeil/received_events","type":"User","site_admin":false},"body":"The ExclusiveAddressUse socket option is a Windows-specific option that, when set to \"true,\" tells Windows not to allow another socket to use the same local address as this socket.  This is only needed on Windows because it otherwise (at least in some versions/configurations) allows any socket with the ReuseAddress option set to \"steal\" the address from a socket that did not have *any* options set.\r\n\r\nOn Unix, we previously treated this as an \"unsupported\" option.  However, it is recommended to set this option to \"true\" on Windows, to avoid malicious theft of a service's address, so we need to support the option, in some fashion, on Unix, so that it's possible to write portable code that works reliably everywhere.  Since the *only* behavior on Linux/OSX is equivalent to \"ExclusiveAddressUse=true\" on Windows, we implement this option as a no-op if it's set to \"true,\" and as an unsupported option if set to \"false.\"  (It's possible that we could come up with a better failure for the \"false\" case, but I'm treating it as \"unsupported\" for compatiblity with the 1.0 release).\r\n\r\nAnother related option is ReuseAddress.  On Windows, this option allows a socket's address *and* port to be reused.  It's equivalent to *two* native options on Unix: SO_REUSEADDR and SO_REUSEPORT.  Again, for portability, we need an option that will work roughly the same way on all platforms.  We could introduce a new option (ReuseAddressAndPort?) but existing code is already using the current ReuseAddress option.  So this change makes ReuseAddress set both SO_REUSEADDR and SO_REUSEPORT on Unix.  If we need to support these options individually, on Unix only, in the future, we'll need to introduce two new options (maybe ReuseAddressOnly and ReusePort) which will likely need to be treated as \"unsupported\" options on Windows.  For now, no need for managed support for more fine-grained options has been demonstrated.\r\n\r\nFor more information on the underlying native options on Windows, Linux, OSX, etc., see this great writeup [on stackoverflow](http://stackoverflow.com/questions/14388706/socket-options-so-reuseaddr-and-so-reuseport-how-do-they-differ-do-they-mean-t).  Also, the Windows docs [discuss the SO_EXCLUSIVEADDR option](https://msdn.microsoft.com/en-us/library/windows/desktop/cc150667(v=vs.85).aspx) in depth.\r\n\r\nCloses #11292.\r\n\r\n@stephentoub @CIPop ","created_at":"2016-09-07T17:31:24Z","updated_at":"2016-09-07T17:43:01Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c641f0a29aeb39cbb6c011c305a39ad48392469a","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/dotnet/corefx/pulls/11509/commits","review_comments_url":"https://api.github.com/repos/dotnet/corefx/pulls/11509/comments","review_comment_url":"https://api.github.com/repos/dotnet/corefx/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dotnet/corefx/issues/11509/comments","statuses_url":"https://api.github.com/repos/dotnet/corefx/statuses/aa4c736675e60ce769bed07b8d79a4ab6f6248f9","head":{"label":"ericeil:ExclusiveAddrUse","ref":"ExclusiveAddrUse","sha":"aa4c736675e60ce769bed07b8d79a4ab6f6248f9","user":{"login":"ericeil","id":7407587,"avatar_url":"https://avatars.githubusercontent.com/u/7407587?v=3","gravatar_id":"","url":"https://api.github.com/users/ericeil","html_url":"https://github.com/ericeil","followers_url":"https://api.github.com/users/ericeil/followers","following_url":"https://api.github.com/users/ericeil/following{/other_user}","gists_url":"https://api.github.com/users/ericeil/gists{/gist_id}","starred_url":"https://api.github.com/users/ericeil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ericeil/subscriptions","organizations_url":"https://api.github.com/users/ericeil/orgs","repos_url":"https://api.github.com/users/ericeil/repos","events_url":"https://api.github.com/users/ericeil/events{/privacy}","received_events_url":"https://api.github.com/users/ericeil/received_events","type":"User","site_admin":false},"repo":{"id":43165675,"name":"corefx","full_name":"ericeil/corefx","owner":{"login":"ericeil","id":7407587,"avatar_url":"https://avatars.githubusercontent.com/u/7407587?v=3","gravatar_id":"","url":"https://api.github.com/users/ericeil","html_url":"https://github.com/ericeil","followers_url":"https://api.github.com/users/ericeil/followers","following_url":"https://api.github.com/users/ericeil/following{/other_user}","gists_url":"https://api.github.com/users/ericeil/gists{/gist_id}","starred_url":"https://api.github.com/users/ericeil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ericeil/subscriptions","organizations_url":"https://api.github.com/users/ericeil/orgs","repos_url":"https://api.github.com/users/ericeil/repos","events_url":"https://api.github.com/users/ericeil/events{/privacy}","received_events_url":"https://api.github.com/users/ericeil/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ericeil/corefx","description":"This repo contains the .NET Core foundational libraries, called CoreFX. It includes classes for collections, file systems, console, XML, async and many others.","fork":true,"url":"https://api.github.com/repos/ericeil/corefx","forks_url":"https://api.github.com/repos/ericeil/corefx/forks","keys_url":"https://api.github.com/repos/ericeil/corefx/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ericeil/corefx/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ericeil/corefx/teams","hooks_url":"https://api.github.com/repos/ericeil/corefx/hooks","issue_events_url":"https://api.github.com/repos/ericeil/corefx/issues/events{/number}","events_url":"https://api.github.com/repos/ericeil/corefx/events","assignees_url":"https://api.github.com/repos/ericeil/corefx/assignees{/user}","branches_url":"https://api.github.com/repos/ericeil/corefx/branches{/branch}","tags_url":"https://api.github.com/repos/ericeil/corefx/tags","blobs_url":"https://api.github.com/repos/ericeil/corefx/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ericeil/corefx/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ericeil/corefx/git/refs{/sha}","trees_url":"https://api.github.com/repos/ericeil/corefx/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ericeil/corefx/statuses/{sha}","languages_url":"https://api.github.com/repos/ericeil/corefx/languages","stargazers_url":"https://api.github.com/repos/ericeil/corefx/stargazers","contributors_url":"https://api.github.com/repos/ericeil/corefx/contributors","subscribers_url":"https://api.github.com/repos/ericeil/corefx/subscribers","subscription_url":"https://api.github.com/repos/ericeil/corefx/subscription","commits_url":"https://api.github.com/repos/ericeil/corefx/commits{/sha}","git_commits_url":"https://api.github.com/repos/ericeil/corefx/git/commits{/sha}","comments_url":"https://api.github.com/repos/ericeil/corefx/comments{/number}","issue_comment_url":"https://api.github.com/repos/ericeil/corefx/issues/comments{/number}","contents_url":"https://api.github.com/repos/ericeil/corefx/contents/{+path}","compare_url":"https://api.github.com/repos/ericeil/corefx/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ericeil/corefx/merges","archive_url":"https://api.github.com/repos/ericeil/corefx/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ericeil/corefx/downloads","issues_url":"https://api.github.com/repos/ericeil/corefx/issues{/number}","pulls_url":"https://api.github.com/repos/ericeil/corefx/pulls{/number}","milestones_url":"https://api.github.com/repos/ericeil/corefx/milestones{/number}","notifications_url":"https://api.github.com/repos/ericeil/corefx/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ericeil/corefx/labels{/name}","releases_url":"https://api.github.com/repos/ericeil/corefx/releases{/id}","deployments_url":"https://api.github.com/repos/ericeil/corefx/deployments","created_at":"2015-09-25T17:47:32Z","updated_at":"2016-01-12T19:24:17Z","pushed_at":"2016-09-07T17:30:26Z","git_url":"git://github.com/ericeil/corefx.git","ssh_url":"git@github.com:ericeil/corefx.git","clone_url":"https://github.com/ericeil/corefx.git","svn_url":"https://github.com/ericeil/corefx","homepage":"http://dotnet.github.io/core/","size":83739,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"dotnet:master","ref":"master","sha":"9468430945296357ec9c30aa792fc5546d752691","user":{"login":"dotnet","id":9141961,"avatar_url":"https://avatars.githubusercontent.com/u/9141961?v=3","gravatar_id":"","url":"https://api.github.com/users/dotnet","html_url":"https://github.com/dotnet","followers_url":"https://api.github.com/users/dotnet/followers","following_url":"https://api.github.com/users/dotnet/following{/other_user}","gists_url":"https://api.github.com/users/dotnet/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnet/subscriptions","organizations_url":"https://api.github.com/users/dotnet/orgs","repos_url":"https://api.github.com/users/dotnet/repos","events_url":"https://api.github.com/users/dotnet/events{/privacy}","received_events_url":"https://api.github.com/users/dotnet/received_events","type":"Organization","site_admin":false},"repo":{"id":26295345,"name":"corefx","full_name":"dotnet/corefx","owner":{"login":"dotnet","id":9141961,"avatar_url":"https://avatars.githubusercontent.com/u/9141961?v=3","gravatar_id":"","url":"https://api.github.com/users/dotnet","html_url":"https://github.com/dotnet","followers_url":"https://api.github.com/users/dotnet/followers","following_url":"https://api.github.com/users/dotnet/following{/other_user}","gists_url":"https://api.github.com/users/dotnet/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnet/subscriptions","organizations_url":"https://api.github.com/users/dotnet/orgs","repos_url":"https://api.github.com/users/dotnet/repos","events_url":"https://api.github.com/users/dotnet/events{/privacy}","received_events_url":"https://api.github.com/users/dotnet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dotnet/corefx","description":"This repo contains the .NET Core foundational libraries, called CoreFX. It includes classes for collections, file systems, console, XML, async and many others.","fork":false,"url":"https://api.github.com/repos/dotnet/corefx","forks_url":"https://api.github.com/repos/dotnet/corefx/forks","keys_url":"https://api.github.com/repos/dotnet/corefx/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dotnet/corefx/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dotnet/corefx/teams","hooks_url":"https://api.github.com/repos/dotnet/corefx/hooks","issue_events_url":"https://api.github.com/repos/dotnet/corefx/issues/events{/number}","events_url":"https://api.github.com/repos/dotnet/corefx/events","assignees_url":"https://api.github.com/repos/dotnet/corefx/assignees{/user}","branches_url":"https://api.github.com/repos/dotnet/corefx/branches{/branch}","tags_url":"https://api.github.com/repos/dotnet/corefx/tags","blobs_url":"https://api.github.com/repos/dotnet/corefx/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dotnet/corefx/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dotnet/corefx/git/refs{/sha}","trees_url":"https://api.github.com/repos/dotnet/corefx/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dotnet/corefx/statuses/{sha}","languages_url":"https://api.github.com/repos/dotnet/corefx/languages","stargazers_url":"https://api.github.com/repos/dotnet/corefx/stargazers","contributors_url":"https://api.github.com/repos/dotnet/corefx/contributors","subscribers_url":"https://api.github.com/repos/dotnet/corefx/subscribers","subscription_url":"https://api.github.com/repos/dotnet/corefx/subscription","commits_url":"https://api.github.com/repos/dotnet/corefx/commits{/sha}","git_commits_url":"https://api.github.com/repos/dotnet/corefx/git/commits{/sha}","comments_url":"https://api.github.com/repos/dotnet/corefx/comments{/number}","issue_comment_url":"https://api.github.com/repos/dotnet/corefx/issues/comments{/number}","contents_url":"https://api.github.com/repos/dotnet/corefx/contents/{+path}","compare_url":"https://api.github.com/repos/dotnet/corefx/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dotnet/corefx/merges","archive_url":"https://api.github.com/repos/dotnet/corefx/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dotnet/corefx/downloads","issues_url":"https://api.github.com/repos/dotnet/corefx/issues{/number}","pulls_url":"https://api.github.com/repos/dotnet/corefx/pulls{/number}","milestones_url":"https://api.github.com/repos/dotnet/corefx/milestones{/number}","notifications_url":"https://api.github.com/repos/dotnet/corefx/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dotnet/corefx/labels{/name}","releases_url":"https://api.github.com/repos/dotnet/corefx/releases{/id}","deployments_url":"https://api.github.com/repos/dotnet/corefx/deployments","created_at":"2014-11-06T23:42:48Z","updated_at":"2016-09-07T16:41:48Z","pushed_at":"2016-09-07T17:41:26Z","git_url":"git://github.com/dotnet/corefx.git","ssh_url":"git@github.com:dotnet/corefx.git","clone_url":"https://github.com/dotnet/corefx.git","svn_url":"https://github.com/dotnet/corefx","homepage":"https://docs.microsoft.com/dotnet/","size":136170,"stargazers_count":10491,"watchers_count":10491,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2598,"mirror_url":null,"open_issues_count":1452,"forks":2598,"open_issues":1452,"watchers":10491,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/11509"},"html":{"href":"https://github.com/dotnet/corefx/pull/11509"},"issue":{"href":"https://api.github.com/repos/dotnet/corefx/issues/11509"},"comments":{"href":"https://api.github.com/repos/dotnet/corefx/issues/11509/comments"},"review_comments":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/11509/comments"},"review_comment":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/11509/commits"},"statuses":{"href":"https://api.github.com/repos/dotnet/corefx/statuses/aa4c736675e60ce769bed07b8d79a4ab6f6248f9"}}}}
{"actor":{"display_login":"CIPop"}}