{"action":"created","comment":{"url":"https://api.github.com/repos/openresty/lua-nginx-module/pulls/comments/47978777","id":47978777,"diff_hunk":"@@ -0,0 +1,353 @@\n+/*\n+ * Copyright (C) 2014-2015 Daurnimator\n+ */\n+\n+/* need to include DDEBUG so that ngx_http_lua_util.h works */\n+#ifndef DDEBUG\n+#define DDEBUG 0\n+#endif\n+#include \"ddebug.h\"\n+\n+#include \"ngx_http_lua_connection.h\"\n+\n+#include <math.h> /* HUGE_VAL */\n+#include <poll.h> /* POLLIN, POLLOUT */\n+\n+#include <lua.h>\n+#include <lauxlib.h>\n+\n+#include \"ngx_core.h\"\n+#include \"ngx_alloc.h\" /* ngx_alloc, ngx_free */\n+#include \"ngx_http.h\" /* ngx_http_request_t, ngx_http_run_posted_requests */\n+#include \"ngx_http_lua_common.h\" /* ngx_http_lua_module, ngx_http_lua_co_ctx_t */\n+\n+#include \"ngx_http_lua_util.h\" /* ngx_http_lua_get_lua_vm, ngx_http_lua_run_thread, ngx_http_lua_finalize_request */\n+#include \"ngx_http_lua_contentby.h\" /* ngx_http_lua_content_wev_handler */\n+\n+\n+typedef struct {\n+    ngx_http_request_t    *request;\n+    ngx_http_lua_co_ctx_t *co_ctx;\n+    ngx_connection_t      *conn;\n+} ngx_http_lua_udata_t;\n+\n+\n+static ngx_int_t\n+ngx_http_lua_fd_resume_request(ngx_http_request_t *r)\n+{\n+    ngx_http_lua_ctx_t *ctx;\n+    lua_State          *vm;\n+    ngx_int_t           rc;\n+    if ((ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module)) == NULL) {\n+        return NGX_ERROR;\n+    }\n+    /* restore normal resume handler */\n+    ctx->resume_handler = ngx_http_lua_wev_handler;\n+    /* resume lua thread */\n+    vm = ngx_http_lua_get_lua_vm(r, ctx);","path":"src/ngx_http_lua_connection.c","position":47,"original_position":47,"commit_id":"c426237414f3321e0469c9648c2222f67269b279","original_commit_id":"c426237414f3321e0469c9648c2222f67269b279","user":{"login":"daurnimator","id":127971,"avatar_url":"https://avatars.githubusercontent.com/u/127971?v=3","gravatar_id":"","url":"https://api.github.com/users/daurnimator","html_url":"https://github.com/daurnimator","followers_url":"https://api.github.com/users/daurnimator/followers","following_url":"https://api.github.com/users/daurnimator/following{/other_user}","gists_url":"https://api.github.com/users/daurnimator/gists{/gist_id}","starred_url":"https://api.github.com/users/daurnimator/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daurnimator/subscriptions","organizations_url":"https://api.github.com/users/daurnimator/orgs","repos_url":"https://api.github.com/users/daurnimator/repos","events_url":"https://api.github.com/users/daurnimator/events{/privacy}","received_events_url":"https://api.github.com/users/daurnimator/received_events","type":"User","site_admin":false},"body":"The whole point of this API is that it will only *wait* for the event. it's up to the libraries to consume the event.\r\n\r\nIt's cleaned up eventually by calling `ngx_del_con` in the cleanup handler.","created_at":"2015-12-17T23:53:36Z","updated_at":"2015-12-17T23:53:36Z","html_url":"https://github.com/openresty/lua-nginx-module/pull/450#discussion_r47978777","pull_request_url":"https://api.github.com/repos/openresty/lua-nginx-module/pulls/450","_links":{"self":{"href":"https://api.github.com/repos/openresty/lua-nginx-module/pulls/comments/47978777"},"html":{"href":"https://github.com/openresty/lua-nginx-module/pull/450#discussion_r47978777"},"pull_request":{"href":"https://api.github.com/repos/openresty/lua-nginx-module/pulls/450"}}},"pull_request":{"url":"https://api.github.com/repos/openresty/lua-nginx-module/pulls/450","id":27447400,"html_url":"https://github.com/openresty/lua-nginx-module/pull/450","diff_url":"https://github.com/openresty/lua-nginx-module/pull/450.diff","patch_url":"https://github.com/openresty/lua-nginx-module/pull/450.patch","issue_url":"https://api.github.com/repos/openresty/lua-nginx-module/issues/450","number":450,"state":"open","locked":false,"title":"Wait for fd API","user":{"login":"daurnimator","id":127971,"avatar_url":"https://avatars.githubusercontent.com/u/127971?v=3","gravatar_id":"","url":"https://api.github.com/users/daurnimator","html_url":"https://github.com/daurnimator","followers_url":"https://api.github.com/users/daurnimator/followers","following_url":"https://api.github.com/users/daurnimator/following{/other_user}","gists_url":"https://api.github.com/users/daurnimator/gists{/gist_id}","starred_url":"https://api.github.com/users/daurnimator/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daurnimator/subscriptions","organizations_url":"https://api.github.com/users/daurnimator/orgs","repos_url":"https://api.github.com/users/daurnimator/repos","events_url":"https://api.github.com/users/daurnimator/events{/privacy}","received_events_url":"https://api.github.com/users/daurnimator/received_events","type":"User","site_admin":false},"body":"Following on from https://groups.google.com/d/msg/openresty-en/T81159uj0y4/ZDckUrpUH30J\r\n\r\nThe short term goal here is a simple API that allows an advanced user to yield their request until an fd polls ready, or a timeout elapses. An fd polling ready is a primitive used across the majority of unix APIs, and is commonly exposed by (e.g.) database client libraries.\r\n\r\nThe single function added is: `ngx.wait(fd, events, timeout)`\r\n  - `fd` is the numeric file descriptor to wait on\r\n  - `events` is a string containing \"r\" and/or \"w\" indicating to wait for readability vs writability\r\n  - `timeout` is the maximum amount of time (in seconds) to wait.","created_at":"2015-01-15T17:45:09Z","updated_at":"2015-12-17T23:53:36Z","closed_at":null,"merged_at":null,"merge_commit_sha":"15d16b39abe725e6ee246fa8f936c7940b45d975","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/openresty/lua-nginx-module/pulls/450/commits","review_comments_url":"https://api.github.com/repos/openresty/lua-nginx-module/pulls/450/comments","review_comment_url":"https://api.github.com/repos/openresty/lua-nginx-module/pulls/comments{/number}","comments_url":"https://api.github.com/repos/openresty/lua-nginx-module/issues/450/comments","statuses_url":"https://api.github.com/repos/openresty/lua-nginx-module/statuses/c426237414f3321e0469c9648c2222f67269b279","head":{"label":"daurnimator:fd-api","ref":"fd-api","sha":"c426237414f3321e0469c9648c2222f67269b279","user":{"login":"daurnimator","id":127971,"avatar_url":"https://avatars.githubusercontent.com/u/127971?v=3","gravatar_id":"","url":"https://api.github.com/users/daurnimator","html_url":"https://github.com/daurnimator","followers_url":"https://api.github.com/users/daurnimator/followers","following_url":"https://api.github.com/users/daurnimator/following{/other_user}","gists_url":"https://api.github.com/users/daurnimator/gists{/gist_id}","starred_url":"https://api.github.com/users/daurnimator/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daurnimator/subscriptions","organizations_url":"https://api.github.com/users/daurnimator/orgs","repos_url":"https://api.github.com/users/daurnimator/repos","events_url":"https://api.github.com/users/daurnimator/events{/privacy}","received_events_url":"https://api.github.com/users/daurnimator/received_events","type":"User","site_admin":false},"repo":{"id":29306681,"name":"lua-nginx-module","full_name":"daurnimator/lua-nginx-module","owner":{"login":"daurnimator","id":127971,"avatar_url":"https://avatars.githubusercontent.com/u/127971?v=3","gravatar_id":"","url":"https://api.github.com/users/daurnimator","html_url":"https://github.com/daurnimator","followers_url":"https://api.github.com/users/daurnimator/followers","following_url":"https://api.github.com/users/daurnimator/following{/other_user}","gists_url":"https://api.github.com/users/daurnimator/gists{/gist_id}","starred_url":"https://api.github.com/users/daurnimator/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daurnimator/subscriptions","organizations_url":"https://api.github.com/users/daurnimator/orgs","repos_url":"https://api.github.com/users/daurnimator/repos","events_url":"https://api.github.com/users/daurnimator/events{/privacy}","received_events_url":"https://api.github.com/users/daurnimator/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/daurnimator/lua-nginx-module","description":"Embed the Power of Lua into NGINX","fork":true,"url":"https://api.github.com/repos/daurnimator/lua-nginx-module","forks_url":"https://api.github.com/repos/daurnimator/lua-nginx-module/forks","keys_url":"https://api.github.com/repos/daurnimator/lua-nginx-module/keys{/key_id}","collaborators_url":"https://api.github.com/repos/daurnimator/lua-nginx-module/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/daurnimator/lua-nginx-module/teams","hooks_url":"https://api.github.com/repos/daurnimator/lua-nginx-module/hooks","issue_events_url":"https://api.github.com/repos/daurnimator/lua-nginx-module/issues/events{/number}","events_url":"https://api.github.com/repos/daurnimator/lua-nginx-module/events","assignees_url":"https://api.github.com/repos/daurnimator/lua-nginx-module/assignees{/user}","branches_url":"https://api.github.com/repos/daurnimator/lua-nginx-module/branches{/branch}","tags_url":"https://api.github.com/repos/daurnimator/lua-nginx-module/tags","blobs_url":"https://api.github.com/repos/daurnimator/lua-nginx-module/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/daurnimator/lua-nginx-module/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/daurnimator/lua-nginx-module/git/refs{/sha}","trees_url":"https://api.github.com/repos/daurnimator/lua-nginx-module/git/trees{/sha}","statuses_url":"https://api.github.com/repos/daurnimator/lua-nginx-module/statuses/{sha}","languages_url":"https://api.github.com/repos/daurnimator/lua-nginx-module/languages","stargazers_url":"https://api.github.com/repos/daurnimator/lua-nginx-module/stargazers","contributors_url":"https://api.github.com/repos/daurnimator/lua-nginx-module/contributors","subscribers_url":"https://api.github.com/repos/daurnimator/lua-nginx-module/subscribers","subscription_url":"https://api.github.com/repos/daurnimator/lua-nginx-module/subscription","commits_url":"https://api.github.com/repos/daurnimator/lua-nginx-module/commits{/sha}","git_commits_url":"https://api.github.com/repos/daurnimator/lua-nginx-module/git/commits{/sha}","comments_url":"https://api.github.com/repos/daurnimator/lua-nginx-module/comments{/number}","issue_comment_url":"https://api.github.com/repos/daurnimator/lua-nginx-module/issues/comments{/number}","contents_url":"https://api.github.com/repos/daurnimator/lua-nginx-module/contents/{+path}","compare_url":"https://api.github.com/repos/daurnimator/lua-nginx-module/compare/{base}...{head}","merges_url":"https://api.github.com/repos/daurnimator/lua-nginx-module/merges","archive_url":"https://api.github.com/repos/daurnimator/lua-nginx-module/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/daurnimator/lua-nginx-module/downloads","issues_url":"https://api.github.com/repos/daurnimator/lua-nginx-module/issues{/number}","pulls_url":"https://api.github.com/repos/daurnimator/lua-nginx-module/pulls{/number}","milestones_url":"https://api.github.com/repos/daurnimator/lua-nginx-module/milestones{/number}","notifications_url":"https://api.github.com/repos/daurnimator/lua-nginx-module/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/daurnimator/lua-nginx-module/labels{/name}","releases_url":"https://api.github.com/repos/daurnimator/lua-nginx-module/releases{/id}","created_at":"2015-01-15T16:35:04Z","updated_at":"2015-01-15T16:35:07Z","pushed_at":"2015-12-16T14:23:20Z","git_url":"git://github.com/daurnimator/lua-nginx-module.git","ssh_url":"git@github.com:daurnimator/lua-nginx-module.git","clone_url":"https://github.com/daurnimator/lua-nginx-module.git","svn_url":"https://github.com/daurnimator/lua-nginx-module","homepage":"http://openresty.org","size":14730,"stargazers_count":0,"watchers_count":0,"language":"Perl","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":"openresty:master","ref":"master","sha":"1d9a77169e5b327ba6146afefd3dd1caa3c24a0e","user":{"login":"openresty","id":7390180,"avatar_url":"https://avatars.githubusercontent.com/u/7390180?v=3","gravatar_id":"","url":"https://api.github.com/users/openresty","html_url":"https://github.com/openresty","followers_url":"https://api.github.com/users/openresty/followers","following_url":"https://api.github.com/users/openresty/following{/other_user}","gists_url":"https://api.github.com/users/openresty/gists{/gist_id}","starred_url":"https://api.github.com/users/openresty/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openresty/subscriptions","organizations_url":"https://api.github.com/users/openresty/orgs","repos_url":"https://api.github.com/users/openresty/repos","events_url":"https://api.github.com/users/openresty/events{/privacy}","received_events_url":"https://api.github.com/users/openresty/received_events","type":"Organization","site_admin":false},"repo":{"id":613829,"name":"lua-nginx-module","full_name":"openresty/lua-nginx-module","owner":{"login":"openresty","id":7390180,"avatar_url":"https://avatars.githubusercontent.com/u/7390180?v=3","gravatar_id":"","url":"https://api.github.com/users/openresty","html_url":"https://github.com/openresty","followers_url":"https://api.github.com/users/openresty/followers","following_url":"https://api.github.com/users/openresty/following{/other_user}","gists_url":"https://api.github.com/users/openresty/gists{/gist_id}","starred_url":"https://api.github.com/users/openresty/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openresty/subscriptions","organizations_url":"https://api.github.com/users/openresty/orgs","repos_url":"https://api.github.com/users/openresty/repos","events_url":"https://api.github.com/users/openresty/events{/privacy}","received_events_url":"https://api.github.com/users/openresty/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/openresty/lua-nginx-module","description":"Embed the Power of Lua into NGINX HTTP servers","fork":false,"url":"https://api.github.com/repos/openresty/lua-nginx-module","forks_url":"https://api.github.com/repos/openresty/lua-nginx-module/forks","keys_url":"https://api.github.com/repos/openresty/lua-nginx-module/keys{/key_id}","collaborators_url":"https://api.github.com/repos/openresty/lua-nginx-module/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/openresty/lua-nginx-module/teams","hooks_url":"https://api.github.com/repos/openresty/lua-nginx-module/hooks","issue_events_url":"https://api.github.com/repos/openresty/lua-nginx-module/issues/events{/number}","events_url":"https://api.github.com/repos/openresty/lua-nginx-module/events","assignees_url":"https://api.github.com/repos/openresty/lua-nginx-module/assignees{/user}","branches_url":"https://api.github.com/repos/openresty/lua-nginx-module/branches{/branch}","tags_url":"https://api.github.com/repos/openresty/lua-nginx-module/tags","blobs_url":"https://api.github.com/repos/openresty/lua-nginx-module/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/openresty/lua-nginx-module/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/openresty/lua-nginx-module/git/refs{/sha}","trees_url":"https://api.github.com/repos/openresty/lua-nginx-module/git/trees{/sha}","statuses_url":"https://api.github.com/repos/openresty/lua-nginx-module/statuses/{sha}","languages_url":"https://api.github.com/repos/openresty/lua-nginx-module/languages","stargazers_url":"https://api.github.com/repos/openresty/lua-nginx-module/stargazers","contributors_url":"https://api.github.com/repos/openresty/lua-nginx-module/contributors","subscribers_url":"https://api.github.com/repos/openresty/lua-nginx-module/subscribers","subscription_url":"https://api.github.com/repos/openresty/lua-nginx-module/subscription","commits_url":"https://api.github.com/repos/openresty/lua-nginx-module/commits{/sha}","git_commits_url":"https://api.github.com/repos/openresty/lua-nginx-module/git/commits{/sha}","comments_url":"https://api.github.com/repos/openresty/lua-nginx-module/comments{/number}","issue_comment_url":"https://api.github.com/repos/openresty/lua-nginx-module/issues/comments{/number}","contents_url":"https://api.github.com/repos/openresty/lua-nginx-module/contents/{+path}","compare_url":"https://api.github.com/repos/openresty/lua-nginx-module/compare/{base}...{head}","merges_url":"https://api.github.com/repos/openresty/lua-nginx-module/merges","archive_url":"https://api.github.com/repos/openresty/lua-nginx-module/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/openresty/lua-nginx-module/downloads","issues_url":"https://api.github.com/repos/openresty/lua-nginx-module/issues{/number}","pulls_url":"https://api.github.com/repos/openresty/lua-nginx-module/pulls{/number}","milestones_url":"https://api.github.com/repos/openresty/lua-nginx-module/milestones{/number}","notifications_url":"https://api.github.com/repos/openresty/lua-nginx-module/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/openresty/lua-nginx-module/labels{/name}","releases_url":"https://api.github.com/repos/openresty/lua-nginx-module/releases{/id}","created_at":"2010-04-16T15:59:01Z","updated_at":"2015-12-17T16:28:33Z","pushed_at":"2015-12-17T20:28:42Z","git_url":"git://github.com/openresty/lua-nginx-module.git","ssh_url":"git@github.com:openresty/lua-nginx-module.git","clone_url":"https://github.com/openresty/lua-nginx-module.git","svn_url":"https://github.com/openresty/lua-nginx-module","homepage":"http://openresty.org","size":18542,"stargazers_count":2107,"watchers_count":2107,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":485,"mirror_url":null,"open_issues_count":95,"forks":485,"open_issues":95,"watchers":2107,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/openresty/lua-nginx-module/pulls/450"},"html":{"href":"https://github.com/openresty/lua-nginx-module/pull/450"},"issue":{"href":"https://api.github.com/repos/openresty/lua-nginx-module/issues/450"},"comments":{"href":"https://api.github.com/repos/openresty/lua-nginx-module/issues/450/comments"},"review_comments":{"href":"https://api.github.com/repos/openresty/lua-nginx-module/pulls/450/comments"},"review_comment":{"href":"https://api.github.com/repos/openresty/lua-nginx-module/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/openresty/lua-nginx-module/pulls/450/commits"},"statuses":{"href":"https://api.github.com/repos/openresty/lua-nginx-module/statuses/c426237414f3321e0469c9648c2222f67269b279"}}}}