-
Notifications
You must be signed in to change notification settings - Fork 15
Postgres #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Postgres #57
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
3c81ece
started on creating a postgres connection
dietmarkuehl 2030284
saving current intermediate state
dietmarkuehl d22b028
made some progress on the poll() implementation
dietmarkuehl ecabdc4
fixed the code to have poll() work for the poll_context
dietmarkuehl 5d39b75
making progress on querying the database in a nice way
dietmarkuehl aa136c7
added sync_run to run a local run_loop
dietmarkuehl 958a6ee
trying to fix the run_loop existing on a timer
dietmarkuehl 35bd5dc
made some progress on fixing async_run
dietmarkuehl 846e5e9
a first cut at an asynchronous postgres demo
dietmarkuehl 7e5a81c
clang-format and some refinement to improve set_error completions
dietmarkuehl fdb0cf5
added an initial print completions function
dietmarkuehl 31b182d
adding an example and building postgresql binding
dietmarkuehl cd4444c
Merge branch 'main' into postgres
dietmarkuehl 1a57468
fixed the CMakeLists.txt to conditionally include postgres
dietmarkuehl a12f7f3
some clean-up and better prepration for the postgres presentation
dietmarkuehl 4c80cb8
minor usability improvement for socket creation
dietmarkuehl 5c3aba0
started adding a simple HTTP server
dietmarkuehl f3ee267
added an async in-memory stream
dietmarkuehl ae1058e
added an in-memory stream
dietmarkuehl e8ce047
a bit more progress on the HTTP support
dietmarkuehl 1ffb393
fixed noexcept of repeat_effect_until::connect
dietmarkuehl 56bf564
improved the completion signature of repeat_effect_until
dietmarkuehl e6e6db2
fixed when_any version to actually stop
dietmarkuehl 593329c
clang format
dietmarkuehl 361c877
restored building examples
dietmarkuehl 48857e6
fix/work around issues located by CI
dietmarkuehl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| // examples/demo_http.hpp -*-C++-*- | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| #ifndef INCLUDED_EXAMPLES_DEMO_HTTP | ||
| #define INCLUDED_EXAMPLES_DEMO_HTTP | ||
|
|
||
| #include <beman/execution/execution.hpp> | ||
| #include <beman/execution/task.hpp> | ||
| #include <beman/net/net.hpp> | ||
| #include "demo_stream.hpp" | ||
| #include <algorithm> | ||
| #include <array> | ||
| #include <cstddef> | ||
| #include <string_view> | ||
| #include <vector> | ||
|
|
||
| // ---------------------------------------------------------------------------- | ||
|
|
||
| namespace demo::http { | ||
| namespace ex = ::beman::execution; | ||
| namespace net = ::beman::net; | ||
|
|
||
| struct request { | ||
| std::string method; | ||
| std::string url; | ||
| std::string version; | ||
| std::vector<std::string> headers; | ||
| }; | ||
|
|
||
| template <typename Stream> | ||
| struct http_client { | ||
| Stream stream; | ||
|
|
||
| public: | ||
| http_client(Stream s) : stream{std::move(s)} {} | ||
| auto request() -> ex::task<> { | ||
| std::vector<char> method, url, version; | ||
| if (!(co_await stream.read(method, ' '))) { | ||
| co_return; | ||
| } | ||
| std::cout << "read method='" << std::string_view(method) << "'\n"; | ||
|
|
||
| if (!(co_await stream.read(url, ' '))) { | ||
| co_return; | ||
| } | ||
| std::cout << "read url='" << std::string_view(url) << "'\n"; | ||
|
|
||
| if (!(co_await stream.read(version, "\r\n"))) { | ||
| co_return; | ||
| } | ||
| std::cout << "read version='" << std::string_view(version) << "'\n"; | ||
|
|
||
| std::vector<char> header; | ||
| while (co_await stream.read(header, "\r\n") && !header.empty()) { | ||
| std::cout << "read header line='" << std::string_view(header) << "'\n"; | ||
| header.clear(); | ||
| } | ||
| std::cout << "read HTTP GET request\n"; | ||
|
|
||
| co_return; | ||
| } | ||
| }; | ||
|
|
||
| struct no_error_env { | ||
| using error_types = ::beman::execution::completion_signatures<>; | ||
| }; | ||
|
|
||
| template <typename SenderFactory> | ||
| ::beman::execution::task<void, demo::http::no_error_env> | ||
| http_server(::beman::net::io_context& io, unsigned short port, SenderFactory fun) { | ||
| ::beman::net::ip::tcp::endpoint ep(::beman::net::ip::address_v4::any(), port); | ||
| ::beman::net::ip::tcp::acceptor server(io, ep); | ||
| while (true) { | ||
| auto [client, addr] = co_await ::beman::net::async_accept(server); | ||
| std::cout << "connection from " << addr << "\n"; | ||
| fun(demo::http::http_client(demo::tcp_stream(std::move(client)))); | ||
| } | ||
| } | ||
| } // namespace demo::http | ||
|
|
||
| namespace demo { | ||
| using http::http_client; | ||
| using http::http_server; | ||
| } // namespace demo | ||
|
|
||
| // ---------------------------------------------------------------------------- | ||
|
|
||
| #endif |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
POSTGRESROOTis hard-coded to/Library/PostgreSQL/18, which is platform- and install-specific. Make this configurable (CACHE PATH) and/or usefind_package(PostgreSQL)/pkg-configto locatelibpqin a cross-platform way; otherwise the build system will behave unexpectedly on non-macOS or different Postgres installs.