{"action":"created","issue":{"url":"https://api.github.com/repos/crystal-lang/crystal/issues/6929","repository_url":"https://api.github.com/repos/crystal-lang/crystal","labels_url":"https://api.github.com/repos/crystal-lang/crystal/issues/6929/labels{/name}","comments_url":"https://api.github.com/repos/crystal-lang/crystal/issues/6929/comments","events_url":"https://api.github.com/repos/crystal-lang/crystal/issues/6929/events","html_url":"https://github.com/crystal-lang/crystal/pull/6929","id":369066809,"node_id":"MDExOlB1bGxSZXF1ZXN0MjIyMDk0Nzg3","number":6929,"title":"(WIP) Refactor protocol sockets (TCP, UDP, UNIX)","user":{"login":"straight-shoota","id":466378,"node_id":"MDQ6VXNlcjQ2NjM3OA==","avatar_url":"https://avatars0.githubusercontent.com/u/466378?v=4","gravatar_id":"","url":"https://api.github.com/users/straight-shoota","html_url":"https://github.com/straight-shoota","followers_url":"https://api.github.com/users/straight-shoota/followers","following_url":"https://api.github.com/users/straight-shoota/following{/other_user}","gists_url":"https://api.github.com/users/straight-shoota/gists{/gist_id}","starred_url":"https://api.github.com/users/straight-shoota/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/straight-shoota/subscriptions","organizations_url":"https://api.github.com/users/straight-shoota/orgs","repos_url":"https://api.github.com/users/straight-shoota/repos","events_url":"https://api.github.com/users/straight-shoota/events{/privacy}","received_events_url":"https://api.github.com/users/straight-shoota/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":16,"created_at":"2018-10-11T11:01:16Z","updated_at":"2018-10-16T10:51:34Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/crystal-lang/crystal/pulls/6929","html_url":"https://github.com/crystal-lang/crystal/pull/6929","diff_url":"https://github.com/crystal-lang/crystal/pull/6929.diff","patch_url":"https://github.com/crystal-lang/crystal/pull/6929.patch"},"body":"Closes #5778\r\n\r\nThe protocol socket implementations previously all inherited `Socket` (and hence `IO`) which leads to problems in the type hierarchy. This is more detailed in the issue.\r\n\r\nThis PR splits the Sockets library into a lower level API `Socket::Raw` (previously `Socket`) which gives full access to the underlying OS socket implementation. Protocol sockets only wrap an instance of this raw socket and provide a protocol-specific API wrapper.Old type hierarchy:\r\n\r\nOld type hierarchy:\r\n\r\n* IO\r\n  * Socket < IO::Buffered\r\n    * TCPSocket\r\n       * TCPServer < Server::Socket\r\n    * UNIXSocket\r\n      * UNIXServer < Server::Socket\r\n    * UDPSocket\r\n\r\nNew type hierarchy:\r\n\r\n* IO\r\n  * Socket::Raw < IO::Buffered\r\n  * TCPSocket\r\n  * UNIXSocket\r\n* TCPServer < Server::Socket\r\n* UNIXServer < Server::Socket\r\n* UDPSocket\r\n\r\n**Implementation**\r\n\r\nThe protocol sockets are simply wrapping a `Socket::Raw` and delegating all socket interaction to that. They are immutable and could just be structs to be super-lightweight.\r\nHowever, since `IO` is a class, and `TCPSocket` and `UNIXSocket` need to inherit `IO`, they have to be classes (for this use case we could think about revisting #4901 or something else).\r\nAll other implementations (server sockets and `UDPSocket`) are structs.\r\n\r\nThey sometimes share similar behaviour in delegating IO operations, TCP settings etc. but there is not really a point in creating a subordinate hierarchy for this. Instead, `src/socket/delegates.cr` provides a few macros that define common methods in the socket implementations. This is perhaps not really elegant, but the best solution I could come up with. They could later be expanded directly into the respective types to avoid macro calls in favour of a little bit code duplication, once we're settled on the general design.\r\n\r\nBased on #6717"},"comment":{"url":"https://api.github.com/repos/crystal-lang/crystal/issues/comments/430192147","html_url":"https://github.com/crystal-lang/crystal/pull/6929#issuecomment-430192147","issue_url":"https://api.github.com/repos/crystal-lang/crystal/issues/6929","id":430192147,"node_id":"MDEyOklzc3VlQ29tbWVudDQzMDE5MjE0Nw==","user":{"login":"asterite","id":209371,"node_id":"MDQ6VXNlcjIwOTM3MQ==","avatar_url":"https://avatars0.githubusercontent.com/u/209371?v=4","gravatar_id":"","url":"https://api.github.com/users/asterite","html_url":"https://github.com/asterite","followers_url":"https://api.github.com/users/asterite/followers","following_url":"https://api.github.com/users/asterite/following{/other_user}","gists_url":"https://api.github.com/users/asterite/gists{/gist_id}","starred_url":"https://api.github.com/users/asterite/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/asterite/subscriptions","organizations_url":"https://api.github.com/users/asterite/orgs","repos_url":"https://api.github.com/users/asterite/repos","events_url":"https://api.github.com/users/asterite/events{/privacy}","received_events_url":"https://api.github.com/users/asterite/received_events","type":"User","site_admin":false},"created_at":"2018-10-16T10:51:34Z","updated_at":"2018-10-16T10:51:34Z","author_association":"CONTRIBUTOR","body":"Is `Socket::Raw` exposed to the user? If not then the name doesn't mater. Otherwise, maybe it can be named `Socket::Base` or something like that."}}
{"actor":{"display_login":"asterite"}}