Skip to content

Commit

Permalink
Fix baseline implementation, add simple experiment script
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffxy committed Jun 23, 2024
1 parent 369759b commit 6208a58
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
7 changes: 4 additions & 3 deletions cpp/experimental/proxy_socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
Expand Down Expand Up @@ -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<struct sockaddr *>(&address), &addrlen);
if (new_fd < 0) {
perror("Accept failed");
Expand Down Expand Up @@ -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;
Expand Down
33 changes: 33 additions & 0 deletions experiments/18-proxy/odbc_noop.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 6208a58

Please sign in to comment.