@@ -560,7 +560,7 @@ _mongoc_get_rr_search (const char *service,
560
560
*
561
561
* Fetch an SRV or TXT resource record and update put results in
562
562
* @rr_data.
563
- *
563
+ *
564
564
* See RFCs 1464 and 2782, MongoDB's "Initial DNS Seedlist Discovery"
565
565
* spec, and MongoDB's "Polling SRV Records for Mongos Discovery"
566
566
* spec.
@@ -644,10 +644,12 @@ mongoc_client_connect_tcp (int32_t connecttimeoutms,
644
644
hints .ai_flags = 0 ;
645
645
hints .ai_protocol = 0 ;
646
646
647
+ TRACE ("DNS lookup for %s" , host -> host );
647
648
s = getaddrinfo (host -> host , portstr , & hints , & result );
648
649
649
650
if (s != 0 ) {
650
651
mongoc_counter_dns_failure_inc ();
652
+ TRACE ("Failed to resolve %s" , host -> host );
651
653
bson_set_error (error ,
652
654
MONGOC_ERROR_STREAM ,
653
655
MONGOC_ERROR_STREAM_NAME_RESOLUTION ,
@@ -764,49 +766,26 @@ mongoc_client_connect_unix (const mongoc_host_list_t *host, bson_error_t *error)
764
766
#endif
765
767
}
766
768
767
-
768
- /*
769
- *--------------------------------------------------------------------------
770
- *
771
- * mongoc_client_default_stream_initiator --
772
- *
773
- * A mongoc_stream_initiator_t that will handle the various type
774
- * of supported sockets by MongoDB including TCP and UNIX.
775
- *
776
- * Language binding authors may want to implement an alternate
777
- * version of this method to use their native stream format.
778
- *
779
- * Returns:
780
- * A mongoc_stream_t if successful; otherwise NULL and @error is set.
781
- *
782
- * Side effects:
783
- * @error is set if return value is NULL.
784
- *
785
- *--------------------------------------------------------------------------
786
- */
787
-
788
769
mongoc_stream_t *
789
- mongoc_client_default_stream_initiator (const mongoc_uri_t * uri ,
790
- const mongoc_host_list_t * host ,
791
- void * user_data ,
792
- bson_error_t * error )
770
+ mongoc_client_connect (bool buffered ,
771
+ bool use_ssl ,
772
+ void * ssl_opts_void ,
773
+ const mongoc_uri_t * uri ,
774
+ const mongoc_host_list_t * host ,
775
+ bson_error_t * error )
793
776
{
794
777
mongoc_stream_t * base_stream = NULL ;
795
778
int32_t connecttimeoutms ;
796
- #ifdef MONGOC_ENABLE_SSL
797
- mongoc_client_t * client = (mongoc_client_t * ) user_data ;
798
- const char * mechanism ;
799
- #endif
800
779
801
780
BSON_ASSERT (uri );
802
781
BSON_ASSERT (host );
803
782
804
783
#ifndef MONGOC_ENABLE_SSL
805
- if (mongoc_uri_get_tls (uri )) {
784
+ if (ssl_opts_void || mongoc_uri_get_tls (uri )) {
806
785
bson_set_error (error ,
807
786
MONGOC_ERROR_CLIENT ,
808
787
MONGOC_ERROR_CLIENT_NO_ACCEPTABLE_PEER ,
809
- "SSL is not enabled in this build of mongo-c-driver." );
788
+ "TLS is not enabled in this build of mongo-c-driver." );
810
789
return NULL ;
811
790
}
812
791
#endif
@@ -836,14 +815,17 @@ mongoc_client_default_stream_initiator (const mongoc_uri_t *uri,
836
815
837
816
#ifdef MONGOC_ENABLE_SSL
838
817
if (base_stream ) {
818
+ mongoc_ssl_opt_t * ssl_opts ;
819
+ const char * mechanism ;
820
+
821
+ ssl_opts = (mongoc_ssl_opt_t * ) ssl_opts_void ;
839
822
mechanism = mongoc_uri_get_auth_mechanism (uri );
840
823
841
- if (client -> use_ssl ||
842
- (mechanism && (0 == strcmp (mechanism , "MONGODB-X509" )))) {
824
+ if (use_ssl || (mechanism && (0 == strcmp (mechanism , "MONGODB-X509" )))) {
843
825
mongoc_stream_t * original = base_stream ;
844
826
845
827
base_stream = mongoc_stream_tls_new_with_hostname (
846
- base_stream , host -> host , & client -> ssl_opts , true);
828
+ base_stream , host -> host , ssl_opts , true);
847
829
848
830
if (!base_stream ) {
849
831
mongoc_stream_destroy (original );
@@ -863,9 +845,54 @@ mongoc_client_default_stream_initiator (const mongoc_uri_t *uri,
863
845
}
864
846
#endif
865
847
866
- return base_stream ? mongoc_stream_buffered_new (base_stream , 1024 ) : NULL ;
848
+ if (!base_stream ) {
849
+ return NULL ;
850
+ }
851
+ if (buffered ) {
852
+ return mongoc_stream_buffered_new (base_stream , 1024 );
853
+ }
854
+ return base_stream ;
867
855
}
868
856
857
+ /*
858
+ *--------------------------------------------------------------------------
859
+ *
860
+ * mongoc_client_default_stream_initiator --
861
+ *
862
+ * A mongoc_stream_initiator_t that will handle the various type
863
+ * of supported sockets by MongoDB including TCP and UNIX.
864
+ *
865
+ * Language binding authors may want to implement an alternate
866
+ * version of this method to use their native stream format.
867
+ *
868
+ * Returns:
869
+ * A mongoc_stream_t if successful; otherwise NULL and @error is set.
870
+ *
871
+ * Side effects:
872
+ * @error is set if return value is NULL.
873
+ *
874
+ *--------------------------------------------------------------------------
875
+ */
876
+
877
+ mongoc_stream_t *
878
+ mongoc_client_default_stream_initiator (const mongoc_uri_t * uri ,
879
+ const mongoc_host_list_t * host ,
880
+ void * user_data ,
881
+ bson_error_t * error )
882
+ {
883
+ void * ssl_opts_void = NULL ;
884
+ bool use_ssl = false;
885
+ #ifdef MONGOC_ENABLE_SSL
886
+ mongoc_client_t * client = (mongoc_client_t * ) user_data ;
887
+
888
+ use_ssl = client -> use_ssl ;
889
+ ssl_opts_void = (void * ) & client -> ssl_opts ;
890
+
891
+ #endif
892
+
893
+ return mongoc_client_connect (
894
+ true, use_ssl , ssl_opts_void , uri , host , error );
895
+ }
869
896
870
897
/*
871
898
*--------------------------------------------------------------------------
0 commit comments