{"action":"created","comment":{"url":"https://api.github.com/repos/ripple/rippled/pulls/comments/59629635","id":59629635,"diff_hunk":"@@ -113,153 +133,405 @@ class basic_parser\n     }\n \n     /** Write data to the parser.\n-        @param data A buffer containing the data to write\n-        @param bytes The size of the buffer pointed to by data.\n-        @return A pair with bool success, and the number of bytes consumed.\n+        \n+        @param data A pointer to a buffer representing the input sequence.\n+        @param size The number of bytes in the buffer pointed to by data.\n+\n+        @throws boost::system::system_error Thrown on failure.\n+\n+        @return The number of bytes consumed in the input sequence.\n     */\n-    std::pair <error_code, std::size_t>\n-    write (void const* data, std::size_t bytes);\n-\n-    /** Write a set of buffer data to the parser.\n-        The return value includes the error code if any,\n-        and the number of bytes consumed in the input sequence.\n-        @param buffers The buffers to write. These must meet the\n-                       requirements of ConstBufferSequence.\n-        @return A pair with bool success, and the number of bytes consumed.\n+    std::size_t\n+    write(void const* data, std::size_t size)\n+    {\n+        error_code ec;\n+        auto const used = write(data, size, ec);\n+        if(ec)\n+            throw boost::system::system_error{ec};\n+        return used;\n+    }\n+\n+    /** Write data to the parser.\n+\n+        @param data A pointer to a buffer representing the input sequence.\n+        @param size The number of bytes in the buffer pointed to by data.\n+        @param ec Set to the error, if any error occurred.\n+\n+        @return The number of bytes consumed in the input sequence.\n+    */\n+    std::size_t\n+    write(void const* data, std::size_t size,\n+        error_code& ec);\n+\n+    /** Write data to the parser.\n+\n+        @param buffers An object meeting the requirements of\n+        ConstBufferSequence that represents the input sequence.\n+\n+        @throws boost::system::system_error Thrown on failure.\n+\n+        @return The number of bytes consumed in the input sequence.\n+    */\n+    template<class ConstBufferSequence>\n+    std::size_t\n+    write(ConstBufferSequence const& buffers)\n+    {\n+        error_code ec;\n+        auto const used = write(buffers, ec);\n+        if(ec)\n+            throw boost::system::system_error{ec};\n+        return used;\n+    }\n+\n+    /** Write data to the parser.\n+\n+        @param buffers An object meeting the requirements of\n+        ConstBufferSequence that represents the input sequence.\n+        @param ec Set to the error, if any error occurred.\n+\n+        @return The number of bytes consumed in the input sequence.\n     */\n-    template <class ConstBufferSequence>\n-    std::pair <error_code, std::size_t>\n-    write (ConstBufferSequence const& buffers);\n+    template<class ConstBufferSequence>\n+    std::size_t\n+    write(ConstBufferSequence const& buffers,\n+        error_code& ec);\n \n     /** Called to indicate the end of file.\n+        \n         HTTP needs to know where the end of the stream is. For example,\n         sometimes servers send responses without Content-Length and\n         expect the client to consume input (for the body) until EOF.\n         Callbacks and errors will still be processed as usual.\n+        \n         @note This is typically called when a socket read returns eof.\n-        @return `true` if the message is complete.\n+        \n+        @throws boost::system::system_error Thrown on failure.\n     */\n-    error_code\n-    write_eof();\n+    void\n+    write_eof()\n+    {\n+        error_code ec;\n+        write_eof(ec);\n+        if(ec)\n+            throw boost::system::system_error{ec};\n+    }\n \n-protected:\n-    /** Called once when a new message begins. */\n-    virtual\n+    /** Called to indicate the end of file.\n+        \n+        HTTP needs to know where the end of the stream is. For example,\n+        sometimes servers send responses without Content-Length and\n+        expect the client to consume input (for the body) until EOF.\n+        Callbacks and errors will still be processed as usual.\n+        \n+        @note This is typically called when a socket read returns eof.\n+        \n+        @param ec Set to the error, if any error occurred.\n+    */\n     void\n-    on_start() = 0;\n+    write_eof(error_code& ec);\n+\n+private:\n+    Derived&\n+    impl()\n+    {\n+        return *static_cast<Derived*>(this);\n+    }\n+\n+    template<class C>\n+    class has_on_start_t\n+    {\n+        template<class T, class R =\n+            decltype(std::declval<T>().on_start(), std::true_type{})>\n+        static R check(int);\n+        template <class>\n+        static std::false_type check(...);\n+        using type = decltype(check<C>(0));\n+    public:\n+        static bool const value = type::value;\n+    };\n+    template<class C>\n+    using has_on_start =\n+        std::bool_constant<has_on_start_t<C>::value>;\n \n-    /** Called for each header field. */\n-    virtual\n     void\n-    on_field (std::string const& field, std::string const& value) = 0;\n+    call_on_start(std::true_type)\n+    {\n+        impl().on_start();\n+    }\n+\n+    void\n+    call_on_start(std::false_type)\n+    {\n+    }\n+\n+    template<class C>\n+    class has_on_field_t\n+    {\n+        template<class T, class R =\n+            decltype(std::declval<T>().on_field(\n+                std::declval<std::string>(), std::declval<std::string>()),\n+                    std::true_type{})>\n+        static R check(int);\n+        template <class>\n+        static std::false_type check(...);\n+        using type = decltype(check<C>(0));\n+    public:\n+        static bool const value = type::value;\n+    };\n+    template<class C>\n+    using has_on_field =\n+        std::bool_constant<has_on_field_t<C>::value>;\n+\n+    void\n+    call_on_field(std::string field, std::string value,","path":"src/beast/beast/http/basic_parser.h","position":null,"original_position":341,"commit_id":"06e358526fe4b9c167a86ae722ea900af70b4b26","original_commit_id":"6fdaa454b7bb29fec78b68c8e0ae6ce73a0b27ed","user":{"login":"HowardHinnant","id":6708789,"avatar_url":"https://avatars.githubusercontent.com/u/6708789?v=3","gravatar_id":"","url":"https://api.github.com/users/HowardHinnant","html_url":"https://github.com/HowardHinnant","followers_url":"https://api.github.com/users/HowardHinnant/followers","following_url":"https://api.github.com/users/HowardHinnant/following{/other_user}","gists_url":"https://api.github.com/users/HowardHinnant/gists{/gist_id}","starred_url":"https://api.github.com/users/HowardHinnant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HowardHinnant/subscriptions","organizations_url":"https://api.github.com/users/HowardHinnant/orgs","repos_url":"https://api.github.com/users/HowardHinnant/repos","events_url":"https://api.github.com/users/HowardHinnant/events{/privacy}","received_events_url":"https://api.github.com/users/HowardHinnant/received_events","type":"User","site_admin":false},"body":"Looks like `const&` is the way to go.  And so the test in `has_on_field_t` should be changed to:\r\n````\r\nstd::declval<std::string const&>(), std::declval<std::string const&>()),\r\n````","created_at":"2016-04-13T21:31:38Z","updated_at":"2016-04-13T21:31:38Z","html_url":"https://github.com/ripple/rippled/pull/1637#discussion_r59629635","pull_request_url":"https://api.github.com/repos/ripple/rippled/pulls/1637","_links":{"self":{"href":"https://api.github.com/repos/ripple/rippled/pulls/comments/59629635"},"html":{"href":"https://github.com/ripple/rippled/pull/1637#discussion_r59629635"},"pull_request":{"href":"https://api.github.com/repos/ripple/rippled/pulls/1637"}}},"pull_request":{"url":"https://api.github.com/repos/ripple/rippled/pulls/1637","id":65845819,"html_url":"https://github.com/ripple/rippled/pull/1637","diff_url":"https://github.com/ripple/rippled/pull/1637.diff","patch_url":"https://github.com/ripple/rippled/pull/1637.patch","issue_url":"https://api.github.com/repos/ripple/rippled/issues/1637","number":1637,"state":"open","locked":false,"title":"WebSocket Protocol / Universal Port","user":{"login":"vinniefalco","id":1503976,"avatar_url":"https://avatars.githubusercontent.com/u/1503976?v=3","gravatar_id":"","url":"https://api.github.com/users/vinniefalco","html_url":"https://github.com/vinniefalco","followers_url":"https://api.github.com/users/vinniefalco/followers","following_url":"https://api.github.com/users/vinniefalco/following{/other_user}","gists_url":"https://api.github.com/users/vinniefalco/gists{/gist_id}","starred_url":"https://api.github.com/users/vinniefalco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vinniefalco/subscriptions","organizations_url":"https://api.github.com/users/vinniefalco/orgs","repos_url":"https://api.github.com/users/vinniefalco/repos","events_url":"https://api.github.com/users/vinniefalco/events{/privacy}","received_events_url":"https://api.github.com/users/vinniefalco/received_events","type":"User","site_admin":false},"body":"New classes are introduced to represent HTTP messages and their associated bodies. The parser interface is reworked to use CRTP, error codes, and trait checks. Beast.WSProto provides developers with a robust WebSocket implementation built on Boost.Asio with a consistent asynchronous model using a modern C++ approach.\r\n\r\nA new Universal Port protocol configuration option is provided, **ws2** which uses a new from-scratch WebSocket implementation.\r\n\r\nReviewers: @JoelKatz @seelabs @HowardHinnant \r\n","created_at":"2016-04-08T20:53:15Z","updated_at":"2016-04-13T21:31:38Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8de8b8d17e446c82666220d0adf657eadbc57c78","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ripple/rippled/pulls/1637/commits","review_comments_url":"https://api.github.com/repos/ripple/rippled/pulls/1637/comments","review_comment_url":"https://api.github.com/repos/ripple/rippled/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ripple/rippled/issues/1637/comments","statuses_url":"https://api.github.com/repos/ripple/rippled/statuses/06e358526fe4b9c167a86ae722ea900af70b4b26","head":{"label":"vinniefalco:server-pr","ref":"server-pr","sha":"06e358526fe4b9c167a86ae722ea900af70b4b26","user":{"login":"vinniefalco","id":1503976,"avatar_url":"https://avatars.githubusercontent.com/u/1503976?v=3","gravatar_id":"","url":"https://api.github.com/users/vinniefalco","html_url":"https://github.com/vinniefalco","followers_url":"https://api.github.com/users/vinniefalco/followers","following_url":"https://api.github.com/users/vinniefalco/following{/other_user}","gists_url":"https://api.github.com/users/vinniefalco/gists{/gist_id}","starred_url":"https://api.github.com/users/vinniefalco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vinniefalco/subscriptions","organizations_url":"https://api.github.com/users/vinniefalco/orgs","repos_url":"https://api.github.com/users/vinniefalco/repos","events_url":"https://api.github.com/users/vinniefalco/events{/privacy}","received_events_url":"https://api.github.com/users/vinniefalco/received_events","type":"User","site_admin":false},"repo":{"id":10961863,"name":"rippled","full_name":"vinniefalco/rippled","owner":{"login":"vinniefalco","id":1503976,"avatar_url":"https://avatars.githubusercontent.com/u/1503976?v=3","gravatar_id":"","url":"https://api.github.com/users/vinniefalco","html_url":"https://github.com/vinniefalco","followers_url":"https://api.github.com/users/vinniefalco/followers","following_url":"https://api.github.com/users/vinniefalco/following{/other_user}","gists_url":"https://api.github.com/users/vinniefalco/gists{/gist_id}","starred_url":"https://api.github.com/users/vinniefalco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vinniefalco/subscriptions","organizations_url":"https://api.github.com/users/vinniefalco/orgs","repos_url":"https://api.github.com/users/vinniefalco/repos","events_url":"https://api.github.com/users/vinniefalco/events{/privacy}","received_events_url":"https://api.github.com/users/vinniefalco/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/vinniefalco/rippled","description":"Ripple peer-to-peer network daemon","fork":true,"url":"https://api.github.com/repos/vinniefalco/rippled","forks_url":"https://api.github.com/repos/vinniefalco/rippled/forks","keys_url":"https://api.github.com/repos/vinniefalco/rippled/keys{/key_id}","collaborators_url":"https://api.github.com/repos/vinniefalco/rippled/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/vinniefalco/rippled/teams","hooks_url":"https://api.github.com/repos/vinniefalco/rippled/hooks","issue_events_url":"https://api.github.com/repos/vinniefalco/rippled/issues/events{/number}","events_url":"https://api.github.com/repos/vinniefalco/rippled/events","assignees_url":"https://api.github.com/repos/vinniefalco/rippled/assignees{/user}","branches_url":"https://api.github.com/repos/vinniefalco/rippled/branches{/branch}","tags_url":"https://api.github.com/repos/vinniefalco/rippled/tags","blobs_url":"https://api.github.com/repos/vinniefalco/rippled/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/vinniefalco/rippled/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/vinniefalco/rippled/git/refs{/sha}","trees_url":"https://api.github.com/repos/vinniefalco/rippled/git/trees{/sha}","statuses_url":"https://api.github.com/repos/vinniefalco/rippled/statuses/{sha}","languages_url":"https://api.github.com/repos/vinniefalco/rippled/languages","stargazers_url":"https://api.github.com/repos/vinniefalco/rippled/stargazers","contributors_url":"https://api.github.com/repos/vinniefalco/rippled/contributors","subscribers_url":"https://api.github.com/repos/vinniefalco/rippled/subscribers","subscription_url":"https://api.github.com/repos/vinniefalco/rippled/subscription","commits_url":"https://api.github.com/repos/vinniefalco/rippled/commits{/sha}","git_commits_url":"https://api.github.com/repos/vinniefalco/rippled/git/commits{/sha}","comments_url":"https://api.github.com/repos/vinniefalco/rippled/comments{/number}","issue_comment_url":"https://api.github.com/repos/vinniefalco/rippled/issues/comments{/number}","contents_url":"https://api.github.com/repos/vinniefalco/rippled/contents/{+path}","compare_url":"https://api.github.com/repos/vinniefalco/rippled/compare/{base}...{head}","merges_url":"https://api.github.com/repos/vinniefalco/rippled/merges","archive_url":"https://api.github.com/repos/vinniefalco/rippled/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/vinniefalco/rippled/downloads","issues_url":"https://api.github.com/repos/vinniefalco/rippled/issues{/number}","pulls_url":"https://api.github.com/repos/vinniefalco/rippled/pulls{/number}","milestones_url":"https://api.github.com/repos/vinniefalco/rippled/milestones{/number}","notifications_url":"https://api.github.com/repos/vinniefalco/rippled/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/vinniefalco/rippled/labels{/name}","releases_url":"https://api.github.com/repos/vinniefalco/rippled/releases{/id}","deployments_url":"https://api.github.com/repos/vinniefalco/rippled/deployments","created_at":"2013-06-26T07:51:04Z","updated_at":"2016-04-11T17:52:30Z","pushed_at":"2016-04-13T19:13:13Z","git_url":"git://github.com/vinniefalco/rippled.git","ssh_url":"git@github.com:vinniefalco/rippled.git","clone_url":"https://github.com/vinniefalco/rippled.git","svn_url":"https://github.com/vinniefalco/rippled","homepage":"https://ripple.com","size":62869,"stargazers_count":4,"watchers_count":4,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":4,"default_branch":"develop"}},"base":{"label":"ripple:develop","ref":"develop","sha":"64a005565d8b87a86a4c01a48cb1286d0b24db60","user":{"login":"ripple","id":3165523,"avatar_url":"https://avatars.githubusercontent.com/u/3165523?v=3","gravatar_id":"","url":"https://api.github.com/users/ripple","html_url":"https://github.com/ripple","followers_url":"https://api.github.com/users/ripple/followers","following_url":"https://api.github.com/users/ripple/following{/other_user}","gists_url":"https://api.github.com/users/ripple/gists{/gist_id}","starred_url":"https://api.github.com/users/ripple/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ripple/subscriptions","organizations_url":"https://api.github.com/users/ripple/orgs","repos_url":"https://api.github.com/users/ripple/repos","events_url":"https://api.github.com/users/ripple/events{/privacy}","received_events_url":"https://api.github.com/users/ripple/received_events","type":"Organization","site_admin":false},"repo":{"id":2724167,"name":"rippled","full_name":"ripple/rippled","owner":{"login":"ripple","id":3165523,"avatar_url":"https://avatars.githubusercontent.com/u/3165523?v=3","gravatar_id":"","url":"https://api.github.com/users/ripple","html_url":"https://github.com/ripple","followers_url":"https://api.github.com/users/ripple/followers","following_url":"https://api.github.com/users/ripple/following{/other_user}","gists_url":"https://api.github.com/users/ripple/gists{/gist_id}","starred_url":"https://api.github.com/users/ripple/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ripple/subscriptions","organizations_url":"https://api.github.com/users/ripple/orgs","repos_url":"https://api.github.com/users/ripple/repos","events_url":"https://api.github.com/users/ripple/events{/privacy}","received_events_url":"https://api.github.com/users/ripple/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ripple/rippled","description":"Ripple peer-to-peer network daemon","fork":false,"url":"https://api.github.com/repos/ripple/rippled","forks_url":"https://api.github.com/repos/ripple/rippled/forks","keys_url":"https://api.github.com/repos/ripple/rippled/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ripple/rippled/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ripple/rippled/teams","hooks_url":"https://api.github.com/repos/ripple/rippled/hooks","issue_events_url":"https://api.github.com/repos/ripple/rippled/issues/events{/number}","events_url":"https://api.github.com/repos/ripple/rippled/events","assignees_url":"https://api.github.com/repos/ripple/rippled/assignees{/user}","branches_url":"https://api.github.com/repos/ripple/rippled/branches{/branch}","tags_url":"https://api.github.com/repos/ripple/rippled/tags","blobs_url":"https://api.github.com/repos/ripple/rippled/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ripple/rippled/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ripple/rippled/git/refs{/sha}","trees_url":"https://api.github.com/repos/ripple/rippled/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ripple/rippled/statuses/{sha}","languages_url":"https://api.github.com/repos/ripple/rippled/languages","stargazers_url":"https://api.github.com/repos/ripple/rippled/stargazers","contributors_url":"https://api.github.com/repos/ripple/rippled/contributors","subscribers_url":"https://api.github.com/repos/ripple/rippled/subscribers","subscription_url":"https://api.github.com/repos/ripple/rippled/subscription","commits_url":"https://api.github.com/repos/ripple/rippled/commits{/sha}","git_commits_url":"https://api.github.com/repos/ripple/rippled/git/commits{/sha}","comments_url":"https://api.github.com/repos/ripple/rippled/comments{/number}","issue_comment_url":"https://api.github.com/repos/ripple/rippled/issues/comments{/number}","contents_url":"https://api.github.com/repos/ripple/rippled/contents/{+path}","compare_url":"https://api.github.com/repos/ripple/rippled/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ripple/rippled/merges","archive_url":"https://api.github.com/repos/ripple/rippled/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ripple/rippled/downloads","issues_url":"https://api.github.com/repos/ripple/rippled/issues{/number}","pulls_url":"https://api.github.com/repos/ripple/rippled/pulls{/number}","milestones_url":"https://api.github.com/repos/ripple/rippled/milestones{/number}","notifications_url":"https://api.github.com/repos/ripple/rippled/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ripple/rippled/labels{/name}","releases_url":"https://api.github.com/repos/ripple/rippled/releases{/id}","deployments_url":"https://api.github.com/repos/ripple/rippled/deployments","created_at":"2011-11-07T04:40:15Z","updated_at":"2016-04-12T06:14:06Z","pushed_at":"2016-04-13T19:17:28Z","git_url":"git://github.com/ripple/rippled.git","ssh_url":"git@github.com:ripple/rippled.git","clone_url":"https://github.com/ripple/rippled.git","svn_url":"https://github.com/ripple/rippled","homepage":"https://ripple.com","size":111577,"stargazers_count":1080,"watchers_count":1080,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":326,"mirror_url":null,"open_issues_count":115,"forks":326,"open_issues":115,"watchers":1080,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/ripple/rippled/pulls/1637"},"html":{"href":"https://github.com/ripple/rippled/pull/1637"},"issue":{"href":"https://api.github.com/repos/ripple/rippled/issues/1637"},"comments":{"href":"https://api.github.com/repos/ripple/rippled/issues/1637/comments"},"review_comments":{"href":"https://api.github.com/repos/ripple/rippled/pulls/1637/comments"},"review_comment":{"href":"https://api.github.com/repos/ripple/rippled/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ripple/rippled/pulls/1637/commits"},"statuses":{"href":"https://api.github.com/repos/ripple/rippled/statuses/06e358526fe4b9c167a86ae722ea900af70b4b26"}}}}