{"action":"created","issue":{"url":"https://api.github.com/repos/libuv/libuv/issues/539","labels_url":"https://api.github.com/repos/libuv/libuv/issues/539/labels{/name}","comments_url":"https://api.github.com/repos/libuv/libuv/issues/539/comments","events_url":"https://api.github.com/repos/libuv/libuv/issues/539/events","html_url":"https://github.com/libuv/libuv/pull/539","id":107697714,"number":539,"title":"Make uv_guess_handle work properly for AIX","user":{"login":"gireeshpunathil","id":6447530,"avatar_url":"https://avatars.githubusercontent.com/u/6447530?v=3","gravatar_id":"","url":"https://api.github.com/users/gireeshpunathil","html_url":"https://github.com/gireeshpunathil","followers_url":"https://api.github.com/users/gireeshpunathil/followers","following_url":"https://api.github.com/users/gireeshpunathil/following{/other_user}","gists_url":"https://api.github.com/users/gireeshpunathil/gists{/gist_id}","starred_url":"https://api.github.com/users/gireeshpunathil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gireeshpunathil/subscriptions","organizations_url":"https://api.github.com/users/gireeshpunathil/orgs","repos_url":"https://api.github.com/users/gireeshpunathil/repos","events_url":"https://api.github.com/users/gireeshpunathil/events{/privacy}","received_events_url":"https://api.github.com/users/gireeshpunathil/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-09-22T11:41:59Z","updated_at":"2015-09-23T14:11:44Z","closed_at":"2015-09-23T14:11:44Z","pull_request":{"url":"https://api.github.com/repos/libuv/libuv/pulls/539","html_url":"https://github.com/libuv/libuv/pull/539","diff_url":"https://github.com/libuv/libuv/pull/539.diff","patch_url":"https://github.com/libuv/libuv/pull/539.patch"},"body":"On AIX, the getsockname API does not operate on the UNIX domain sockets\r\nPlease see: https://www-01.ibm.com/support/knowledgecenter/ssw_aix_61/com.ibm.aix.commtrf2/getsockname.htm\r\n\r\nThis means that the internal helper routine uv_guess_handle in tty.c\r\nfails in AIX, for common use cases.\r\n\r\nThere is no direct API support which helps identifying a UNIX domain\r\nsocket in AIX. getpeername() retrieves the information pertinent to\r\nconnected UNIX domain socket pairs, and using getpeername where\r\ngetsockname fails was a good workaround. However, there are edge cases\r\nwhere one end of a socketpair comes for introspection while the other\r\nend has been closed, which causes getpeername to fail.\r\n\r\nA better solution is derived based on these facts:\r\n\r\n1.getsockname() on a broken / un-broken socketpair does not actually\r\nfail with -1, instead it returns 0. However, the API does not modify\r\nthe socketaddr structure passed to it, with the socket information.\r\n\r\n2.This behavior of getsockname is observed only for UNIX domain socket,\r\namong all possible types of sockets which I tested - ~30 of them.\r\n\r\nSo a practical and stable workaround for AIX is to return\r\nUV_UNKNOWN_HANDLE if getsockname fails.  If it passes and the length\r\nof the structure returned is 0 then we know that the type is AF_UNIX\r\nand return UV_NAMED_PIPE , otherwise we inspect in the same way as for\r\nother platforms to derive the type.\r\n\r\nI have ran the relevant tests with this patch, and all tests passed."},"comment":{"url":"https://api.github.com/repos/libuv/libuv/issues/comments/142613810","html_url":"https://github.com/libuv/libuv/pull/539#issuecomment-142613810","issue_url":"https://api.github.com/repos/libuv/libuv/issues/539","id":142613810,"user":{"login":"saghul","id":317464,"avatar_url":"https://avatars.githubusercontent.com/u/317464?v=3","gravatar_id":"","url":"https://api.github.com/users/saghul","html_url":"https://github.com/saghul","followers_url":"https://api.github.com/users/saghul/followers","following_url":"https://api.github.com/users/saghul/following{/other_user}","gists_url":"https://api.github.com/users/saghul/gists{/gist_id}","starred_url":"https://api.github.com/users/saghul/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/saghul/subscriptions","organizations_url":"https://api.github.com/users/saghul/orgs","repos_url":"https://api.github.com/users/saghul/repos","events_url":"https://api.github.com/users/saghul/events{/privacy}","received_events_url":"https://api.github.com/users/saghul/received_events","type":"User","site_admin":false},"created_at":"2015-09-23T14:11:44Z","updated_at":"2015-09-23T14:11:44Z","body":"Landed in 25506bb, thanks Gireesh!"}}