cpp-driver icon indicating copy to clipboard operation
cpp-driver copied to clipboard

Fix building ExportedConnection on Windows

Open SeverinLeonhardt opened this issue 2 years ago • 1 comments
trafficstars

The <unistd.h> header isn't available on Windows. The dup function is deprecated^1 and apparently also not the correct function here.

On Windows uv_fileno currently returns a SOCKET^2 cast into uv_os_fd_t^3. Contrary to many other handles this handle type can't be duplicated using DuplicateHandle^4. WSADuplicateSocket has to be used instead. As documented an actual SOCKET has to be constructed from WSAPROTOCOL_INFOW. The parameters are taken from the struct, except for g and dwFlags which were taken from libuv's implementation^5.

Error handling was omitted like with uv_fileno and dup already.

Also changed the type of fd to what uv_tcp_open expects which is SOCKET instead of int on Windows.

SeverinLeonhardt avatar Jun 14 '23 15:06 SeverinLeonhardt

To test whether these changes work I've applied the following patch:

diff --git a/src/connection_pool.cpp b/src/connection_pool.cpp
index 21464b18..891226ec 100644
--- a/src/connection_pool.cpp
+++ b/src/connection_pool.cpp
@@ -95,11 +95,7 @@ ConnectionPool::ConnectionPool(const Connection::Vec& connections, ConnectionPoo
        ++it) {
     const Connection::Ptr& connection(*it);
     if (!connection->is_closing()) {
-      if (connections_by_shard_[connection->shard_id()].size() < num_connections_per_shard_) {
-        add_connection(PooledConnection::Ptr(new PooledConnection(this, connection)));
-      } else {
         host_->add_unpooled_connection(std::move(connection));
-      }
     }
   }

This lead to ExportConnection's constructor and import_connection method being called. The test application then successfully ran various CQL queries against a single-node Scylla cluster.

SeverinLeonhardt avatar Jun 14 '23 15:06 SeverinLeonhardt