|
Thank you for providing the pseudocode, as that is helpful in understanding the desired behavior. This seems like a reasonable request if there is a need to bind to a non-primary network interface, and no way to do this without driver changes.
I'd like to explore other approaches to solving this. I do not think we'd want to add a new URI option. In general, URIs should be portable between applications of different drivers, and URI options are standardized in our URI Options Specification. Here are my current thoughts:
Option 1: Extend custom initiators
It is technically possible to implement this behavior for a single-threaded mongoc_client_t just using the public API. The C driver exposes a custom initiator: mongoc_client_set_stream_initiator which allows overriding the default behavior of creating a stream to a server. But mongoc_client_set_stream_initiator only works for single threaded clients currently. We could add support for a mongoc_client_pool_t. This would be a more general solution, and more consistent with existing precedent in other drivers. However, this might be less convenient.
Option 2: Add a setter on mongoc_client
Add a setter for a bind address mongoc_client_t like so:
bool ret;
|
bson_error_t err;
|
|
ret = mongoc_client_set_bind_address (client, "1.2.3.4", &err);
|
I think Option 2 is more convenient for this use case, but I think there is more precedent for Option 1. I am discussing with the drivers team to get more perspective.
|