GitHub PullRequestReviewCommentEvent at 2014-11-27 08:40:52
Repository: leps
Actor: saghul
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/libuv/leps/pulls/comments/20983852","id":20983852,"diff_hunk":"@@ -0,0 +1,184 @@\n+| Title  | Request all the things  |\n+|--------|-------------------------|\n+| Author | @saghul                 |\n+| Status | DRAFT                   |\n+| Date   | 2014-11-27 07:43:59     |\n+\n+\n+## Overview\n+\n+This proposal describes a new approach for dealing with operations in libuv. As of\n+right now, handles define an entity which is capable of performing certain operations.\n+These operations are sometimes a result of a request being sent and some other times a\n+result of a callback (which was passed by the user) being called. This proposal aims\n+to make this behavior more consistent, by turning several operations that currently\n+just take a callback into a request form.\n+\n+\n+### uv_read\n+\n+(This was previously discussed, but it’s added here for completeness).\n+\n+Instead of using a callback passed to `uv_read_start`, the plan is to use a `uv_read`\n+function which performs a single read operation. The initial prototype was defined\n+as follows:\n+\n+~~~~\n+int uv_read(uv_read_t* req, uv_stream_t* handle, uv_buf_t[] bufs, unsigned int nbufs, uv_read_cb, cb)\n+~~~~\n+\n+The read callback is defined as:\n+\n+~~~~\n+typedef void (*uv_read_cb)(uv_read_t* req, int status)\n+~~~~\n+\n+This approach has one problem, though: memory for reading needs to be allocated upfront,\n+which might not be desirable in all cases. For this reason, a secondary version which takes\n+an allocation callback is also proposed:\n+\n+~~~~\n+int uv_read2(uv_read_t* req, uv_stream_t* handle, uv_alloc_cb alloc_cb, uv_read_cb cb)\n+~~~~\n+\n+Applications can use one or the other or mixed without problems.\n+\n+Implementation details: we probably will want to have some `bufsml` of size 4 where we\n+copy the structures when the request is created, like `uv_write` does. Thus, the user can\n+pass a `uv_buf_t` array which is allocated on the stack, as long as the memory in each `buf->base`\n+is valid until the request callback is called.\n+\n+Inline reading: if there are no conditions which would prevent otherwise, we could try to do\n+a read on the spot. This should work ok if the user provided preallocated buffers, because\n+we can hold on to them if we get EAGAIN. If `uv_read2` is used, instead, we won’t attempt\n+to read on the spot because the allocation callback would have to be called and we’d end\n+up holding on to the buffer for too long, thus defeating the purpose of deferred allocation.\n+A best effort inline reading function is also proposed:\n+\n+~~~~\n+int uv_try_read(uv_stream_t* handle, uv_buf_t[] bufs, int nbufs)\n+~~~~\n+\n+It does basically the analogous to `uv_try_write`, that is, attempt to read inline and\n+doesn’t queue a request if it doesn’t succeed.\n+\n+### uv_stream_poll\n+\n+In case `uv_read` and `uv_read2` are not enough, another way to read or write on streams\n+would be to get a callback when the stream is readable / writable, and use the `uv_try_*`\n+family of functions to perform the reads and writes inline. The proposed API for this:\n+\n+~~~~\n+int uv_stream_poll(uv_stream_poll_t* req, uv_stream_t* handle, int events, uv_stream_poll cb)\n+~~~~\n+\n+`events` would be a mask composed of `UV_READABLE` and / or `UV_WRITABLE`.\n+\n+The callback is defined as:\n+\n+~~~~\n+typedef void (*uv_stream_poll_cb)(uv_stream_poll_t* req, int status)\n+~~~~\n+\n+\n+### uv_timeout\n+\n+Currently libuv implements repeating timers in the form of a handle. The current implementation\n+does not account for the time taken during the callback, and this has caused some trouble\n+every now and then, since people have different expectations when it comes to repeating timers.\n+\n+This proposal removes the timer handle and makes timers a request, which gets its callback\n+called when the timeout is hit:\n+\n+~~~~\n+int uv_timeout(uv_timeout_t* req, uv_loop_t* loop, int timeout, uv_timeout_cb cb)\n+~~~~\n+\n+Timers are one shot, so no assumptions are made and repeating timers can be easily\n+implemented on top (by users).\n+\n+The callback takes the following form:\n+\n+~~~~\n+typedef void (*uv_timeout_cb)(uv_timeout_t* req, int status)\n+~~~~\n+\n+The status argument would indicate success or failure. One possible failure is cancellation,\n+which would make status == `UV_ECANCELED`.\n+\n+Implementation detail: Timers will be the first thing to be processed after polling for i/o.\n+\n+\n+### uv_callback\n+\n+In certain environments users would like to get a callback called by the event loop, but\n+scheduling this callback would happen from a different thread. This can be implemented using\n+`uv_async_t` handles in combination with some sort of thread safe queue, but it’s not\n+straightforward. Also, many have fallen in the trap of `uv_async_send` coalescing calls,\n+that is, calling the function X times does yield the callback being called X times; it’s","path":"XXX-request-all-the-things.md","position":118,"original_position":118,"commit_id":"a17c2f87ff1026cde768fe6a5d1e30ed8b63894a","original_commit_id":"a17c2f87ff1026cde768fe6a5d1e30ed8b63894a","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},"body":"Indeed.","created_at":"2014-11-27T08:40:52Z","updated_at":"2014-11-27T08:40:52Z","html_url":"https://github.com/libuv/leps/pull/2#discussion_r20983852","pull_request_url":"https://api.github.com/repos/libuv/leps/pulls/2","_links":{"self":{"href":"https://api.github.com/repos/libuv/leps/pulls/comments/20983852"},"html":{"href":"https://github.com/libuv/leps/pull/2#discussion_r20983852"},"pull_request":{"href":"https://api.github.com/repos/libuv/leps/pulls/2"}}},"pull_request":{"url":"https://api.github.com/repos/libuv/leps/pulls/2","id":25134475,"html_url":"https://github.com/libuv/leps/pull/2","diff_url":"https://github.com/libuv/leps/pull/2.diff","patch_url":"https://github.com/libuv/leps/pull/2.patch","issue_url":"https://api.github.com/repos/libuv/leps/issues/2","number":2,"state":"open","locked":false,"title":"lep: request all the things","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},"body":"","created_at":"2014-11-27T07:52:46Z","updated_at":"2014-11-27T08:40:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"bc572d0c017d42c62b18a199f5ef5cb3947b2fb8","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/libuv/leps/pulls/2/commits","review_comments_url":"https://api.github.com/repos/libuv/leps/pulls/2/comments","review_comment_url":"https://api.github.com/repos/libuv/leps/pulls/comments/{number}","comments_url":"https://api.github.com/repos/libuv/leps/issues/2/comments","statuses_url":"https://api.github.com/repos/libuv/leps/statuses/a17c2f87ff1026cde768fe6a5d1e30ed8b63894a","head":{"label":"saghul:request_all_the_things","ref":"request_all_the_things","sha":"a17c2f87ff1026cde768fe6a5d1e30ed8b63894a","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},"repo":{"id":27214729,"name":"leps","full_name":"saghul/leps","owner":{"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},"private":false,"html_url":"https://github.com/saghul/leps","description":"Libuv Enhancement Proposals","fork":true,"url":"https://api.github.com/repos/saghul/leps","forks_url":"https://api.github.com/repos/saghul/leps/forks","keys_url":"https://api.github.com/repos/saghul/leps/keys{/key_id}","collaborators_url":"https://api.github.com/repos/saghul/leps/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/saghul/leps/teams","hooks_url":"https://api.github.com/repos/saghul/leps/hooks","issue_events_url":"https://api.github.com/repos/saghul/leps/issues/events{/number}","events_url":"https://api.github.com/repos/saghul/leps/events","assignees_url":"https://api.github.com/repos/saghul/leps/assignees{/user}","branches_url":"https://api.github.com/repos/saghul/leps/branches{/branch}","tags_url":"https://api.github.com/repos/saghul/leps/tags","blobs_url":"https://api.github.com/repos/saghul/leps/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/saghul/leps/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/saghul/leps/git/refs{/sha}","trees_url":"https://api.github.com/repos/saghul/leps/git/trees{/sha}","statuses_url":"https://api.github.com/repos/saghul/leps/statuses/{sha}","languages_url":"https://api.github.com/repos/saghul/leps/languages","stargazers_url":"https://api.github.com/repos/saghul/leps/stargazers","contributors_url":"https://api.github.com/repos/saghul/leps/contributors","subscribers_url":"https://api.github.com/repos/saghul/leps/subscribers","subscription_url":"https://api.github.com/repos/saghul/leps/subscription","commits_url":"https://api.github.com/repos/saghul/leps/commits{/sha}","git_commits_url":"https://api.github.com/repos/saghul/leps/git/commits{/sha}","comments_url":"https://api.github.com/repos/saghul/leps/comments{/number}","issue_comment_url":"https://api.github.com/repos/saghul/leps/issues/comments/{number}","contents_url":"https://api.github.com/repos/saghul/leps/contents/{+path}","compare_url":"https://api.github.com/repos/saghul/leps/compare/{base}...{head}","merges_url":"https://api.github.com/repos/saghul/leps/merges","archive_url":"https://api.github.com/repos/saghul/leps/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/saghul/leps/downloads","issues_url":"https://api.github.com/repos/saghul/leps/issues{/number}","pulls_url":"https://api.github.com/repos/saghul/leps/pulls{/number}","milestones_url":"https://api.github.com/repos/saghul/leps/milestones{/number}","notifications_url":"https://api.github.com/repos/saghul/leps/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/saghul/leps/labels{/name}","releases_url":"https://api.github.com/repos/saghul/leps/releases{/id}","created_at":"2014-11-27T07:51:53Z","updated_at":"2014-11-27T07:51:48Z","pushed_at":"2014-11-27T08:07:07Z","git_url":"git://github.com/saghul/leps.git","ssh_url":"git@github.com:saghul/leps.git","clone_url":"https://github.com/saghul/leps.git","svn_url":"https://github.com/saghul/leps","homepage":null,"size":0,"stargazers_count":0,"watchers_count":0,"language":null,"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":"libuv:master","ref":"master","sha":"fa8443f4f9b9d6257d3da0268174d85e7d5d78a3","user":{"login":"libuv","id":4030929,"avatar_url":"https://avatars.githubusercontent.com/u/4030929?v=3","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":27196780,"name":"leps","full_name":"libuv/leps","owner":{"login":"libuv","id":4030929,"avatar_url":"https://avatars.githubusercontent.com/u/4030929?v=3","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/leps","description":"Libuv Enhancement Proposals","fork":false,"url":"https://api.github.com/repos/libuv/leps","forks_url":"https://api.github.com/repos/libuv/leps/forks","keys_url":"https://api.github.com/repos/libuv/leps/keys{/key_id}","collaborators_url":"https://api.github.com/repos/libuv/leps/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/libuv/leps/teams","hooks_url":"https://api.github.com/repos/libuv/leps/hooks","issue_events_url":"https://api.github.com/repos/libuv/leps/issues/events{/number}","events_url":"https://api.github.com/repos/libuv/leps/events","assignees_url":"https://api.github.com/repos/libuv/leps/assignees{/user}","branches_url":"https://api.github.com/repos/libuv/leps/branches{/branch}","tags_url":"https://api.github.com/repos/libuv/leps/tags","blobs_url":"https://api.github.com/repos/libuv/leps/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/libuv/leps/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/libuv/leps/git/refs{/sha}","trees_url":"https://api.github.com/repos/libuv/leps/git/trees{/sha}","statuses_url":"https://api.github.com/repos/libuv/leps/statuses/{sha}","languages_url":"https://api.github.com/repos/libuv/leps/languages","stargazers_url":"https://api.github.com/repos/libuv/leps/stargazers","contributors_url":"https://api.github.com/repos/libuv/leps/contributors","subscribers_url":"https://api.github.com/repos/libuv/leps/subscribers","subscription_url":"https://api.github.com/repos/libuv/leps/subscription","commits_url":"https://api.github.com/repos/libuv/leps/commits{/sha}","git_commits_url":"https://api.github.com/repos/libuv/leps/git/commits{/sha}","comments_url":"https://api.github.com/repos/libuv/leps/comments{/number}","issue_comment_url":"https://api.github.com/repos/libuv/leps/issues/comments/{number}","contents_url":"https://api.github.com/repos/libuv/leps/contents/{+path}","compare_url":"https://api.github.com/repos/libuv/leps/compare/{base}...{head}","merges_url":"https://api.github.com/repos/libuv/leps/merges","archive_url":"https://api.github.com/repos/libuv/leps/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/libuv/leps/downloads","issues_url":"https://api.github.com/repos/libuv/leps/issues{/number}","pulls_url":"https://api.github.com/repos/libuv/leps/pulls{/number}","milestones_url":"https://api.github.com/repos/libuv/leps/milestones{/number}","notifications_url":"https://api.github.com/repos/libuv/leps/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/libuv/leps/labels{/name}","releases_url":"https://api.github.com/repos/libuv/leps/releases{/id}","created_at":"2014-11-26T21:23:45Z","updated_at":"2014-11-27T07:51:48Z","pushed_at":"2014-11-27T07:41:42Z","git_url":"git://github.com/libuv/leps.git","ssh_url":"git@github.com:libuv/leps.git","clone_url":"https://github.com/libuv/leps.git","svn_url":"https://github.com/libuv/leps","homepage":null,"size":0,"stargazers_count":1,"watchers_count":1,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":4,"forks":1,"open_issues":4,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/libuv/leps/pulls/2"},"html":{"href":"https://github.com/libuv/leps/pull/2"},"issue":{"href":"https://api.github.com/repos/libuv/leps/issues/2"},"comments":{"href":"https://api.github.com/repos/libuv/leps/issues/2/comments"},"review_comments":{"href":"https://api.github.com/repos/libuv/leps/pulls/2/comments"},"review_comment":{"href":"https://api.github.com/repos/libuv/leps/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/libuv/leps/pulls/2/commits"},"statuses":{"href":"https://api.github.com/repos/libuv/leps/statuses/a17c2f87ff1026cde768fe6a5d1e30ed8b63894a"}}}}