From 6208a58a9f7b49618863c1db9259bf36281da1cb Mon Sep 17 00:00:00 2001 From: Geoffrey Yu Date: Sun, 23 Jun 2024 16:27:08 -0400 Subject: [PATCH] Fix baseline implementation, add simple experiment script --- cpp/experimental/proxy_socket.cc | 7 ++++--- experiments/18-proxy/odbc_noop.py | 33 +++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 experiments/18-proxy/odbc_noop.py diff --git a/cpp/experimental/proxy_socket.cc b/cpp/experimental/proxy_socket.cc index da4e9818..76768498 100644 --- a/cpp/experimental/proxy_socket.cc +++ b/cpp/experimental/proxy_socket.cc @@ -31,7 +31,7 @@ class Socket { serv_addr.sin_family = AF_INET; serv_addr.sin_port = htons(port); - if(inet_pton(AF_INET, host.c_str(), &serv_addr.sin_addr) <= 0) { + if(inet_pton(AF_INET, host.c_str(), &serv_addr.sin_addr) < 0) { perror("Host conversion."); throw std::runtime_error("Host conversion."); } @@ -95,7 +95,7 @@ class ServerSocket { Socket Accept() const { struct sockaddr_in address; - socklen_t addrlen; + socklen_t addrlen = sizeof(address); const int new_fd = accept(fd_, reinterpret_cast(&address), &addrlen); if (new_fd < 0) { perror("Accept failed"); @@ -210,13 +210,14 @@ int main(int argc, char* argv[]) { Buffer client_to_underlying(buffer_size), underlying_to_client(buffer_size), scratch(buffer_size); fd_set descriptors; + const int nfds = std::max(std::max(to_client.fd(), to_underlying.fd()), sentinel.read_fd()) + 1; while (true) { FD_ZERO(&descriptors); FD_SET(to_client.fd(), &descriptors); FD_SET(to_underlying.fd(), &descriptors); FD_SET(sentinel.read_fd(), &descriptors); - const int result = select(3, &descriptors, nullptr, nullptr, nullptr); + const int result = select(nfds, &descriptors, nullptr, nullptr, nullptr); if (result < 0) { perror("Select"); break; diff --git a/experiments/18-proxy/odbc_noop.py b/experiments/18-proxy/odbc_noop.py new file mode 100644 index 00000000..7963ac2a --- /dev/null +++ b/experiments/18-proxy/odbc_noop.py @@ -0,0 +1,33 @@ +import argparse + +from brad.config.engine import Engine +from brad.config.file import ConfigFile +from brad.connection.connection import Connection +from brad.connection.factory import ConnectionFactory +from brad.connection.odbc_connection import OdbcConnection + + +def main() -> None: + parser = argparse.ArgumentParser() + parser.add_argument("--address", type=str, required=True) + parser.add_argument("--port", type=str, required=True) + parser.add_argument("--physical-config-file", type=str, required=True) + args = parser.parse_args() + + config = ConfigFile.load_from_physical_config(args.physical_config_file) + cstr = ConnectionFactory._pg_aurora_odbc_connection_string( + args.address, + args.port, + config.get_connection_details(Engine.Aurora), + schema_name=None, + ) + cxn: Connection = OdbcConnection.connect_sync(cstr, autocommit=True, timeout_s=30) + cursor = cxn.cursor_sync() + cursor.execute_sync("SELECT 1") + print(cursor.fetchall_sync()) + + cxn.close_sync() + + +if __name__ == "__main__": + main()