@@ -656,7 +656,22 @@ void phongo_stream_destroy(mongoc_stream_t *stream_wrap) /* {{{ */
656
656
{
657
657
php_phongo_stream_socket * base_stream = (php_phongo_stream_socket * )stream_wrap ;
658
658
659
+ mongoc_log (MONGOC_LOG_LEVEL_DEBUG , MONGOC_LOG_DOMAIN , "Not destroying RSRC#%d" , base_stream -> stream -> rsrc_id );
660
+ /*
661
+ * DON'T DO ANYTHING TO THE INTERNAL base_stream->stream
662
+ * The stream should not be closed during normal dtor -- as we want it to
663
+ * survive until next request.
664
+ * We only clean it up on failure and (implicitly) MSHUTDOWN
665
+ */
666
+
667
+ efree (base_stream );
668
+ } /* }}} */
669
+ void phongo_stream_failed (mongoc_stream_t * stream_wrap ) /* {{{ */
670
+ {
671
+ php_phongo_stream_socket * base_stream = (php_phongo_stream_socket * )stream_wrap ;
672
+
659
673
if (base_stream -> stream ) {
674
+ mongoc_log (MONGOC_LOG_LEVEL_DEBUG , MONGOC_LOG_DOMAIN , "Destroying RSRC#%d" , base_stream -> stream -> rsrc_id );
660
675
TSRMLS_FETCH_FROM_CTX (base_stream -> tsrm_ls );
661
676
662
677
php_stream_free (base_stream -> stream , PHP_STREAM_FREE_CLOSE_PERSISTENT | PHP_STREAM_FREE_RSRC_DTOR );
@@ -666,8 +681,12 @@ void phongo_stream_destroy(mongoc_stream_t *stream_wrap) /* {{{ */
666
681
efree (base_stream );
667
682
} /* }}} */
668
683
669
- int phongo_stream_close (mongoc_stream_t * stream ) /* {{{ */
684
+ int phongo_stream_close (mongoc_stream_t * stream_wrap ) /* {{{ */
670
685
{
686
+ php_phongo_stream_socket * base_stream = (php_phongo_stream_socket * )stream_wrap ;
687
+
688
+ mongoc_log (MONGOC_LOG_LEVEL_DEBUG , MONGOC_LOG_DOMAIN , "Closing RSRC#%d" , base_stream -> stream -> rsrc_id );
689
+ phongo_stream_destroy (stream_wrap );
671
690
return 0 ;
672
691
} /* }}} */
673
692
@@ -938,28 +957,30 @@ mongoc_stream_t* phongo_stream_initiator(const mongoc_uri_t *uri, const mongoc_h
938
957
}
939
958
940
959
spprintf (& uniqid , 0 , "mongodb://%s:%s@%s:%d/%s?ssl=%d&authMechanism=%s&authSource=%s" ,
941
- mongoc_uri_get_username (uri ),
942
- mongoc_uri_get_password (uri ),
960
+ mongoc_uri_get_username (uri ) ?: "" ,
961
+ mongoc_uri_get_password (uri ) ?: "" ,
943
962
host -> host ,
944
963
host -> port ,
945
- mongoc_uri_get_database (uri ),
964
+ mongoc_uri_get_database (uri ) ?: "" ,
946
965
mongoc_uri_get_ssl (uri ) ? 1 : 0 ,
947
- mongoc_uri_get_auth_mechanism (uri ),
948
- mongoc_uri_get_auth_source (uri )
966
+ mongoc_uri_get_auth_mechanism (uri ) ?: "" ,
967
+ mongoc_uri_get_auth_source (uri ) ?: ""
949
968
);
950
969
951
970
mongoc_log (MONGOC_LOG_LEVEL_DEBUG , MONGOC_LOG_DOMAIN , "Connecting to '%s'" , uniqid );
952
971
stream = php_stream_xport_create (dsn , dsn_len , 0 , STREAM_XPORT_CLIENT | STREAM_XPORT_CONNECT | STREAM_XPORT_CONNECT_ASYNC , uniqid , timeoutp , (php_stream_context * )user_data , & errmsg , & errcode );
953
972
954
- efree (uniqid );
955
973
if (!stream ) {
956
974
bson_set_error (error , MONGOC_ERROR_STREAM , MONGOC_ERROR_STREAM_CONNECT , "Failed connecting to '%s:%d': %s" , host -> host , host -> port , errmsg );
957
975
efree (dsn );
976
+ efree (uniqid );
958
977
if (errmsg ) {
959
978
efree (errmsg );
960
979
}
961
980
RETURN (NULL );
962
981
}
982
+ mongoc_log (MONGOC_LOG_LEVEL_DEBUG , MONGOC_LOG_DOMAIN , "Created: RSRC#%d as '%s'" , stream -> rsrc_id , uniqid );
983
+ efree (uniqid );
963
984
964
985
/* Avoid invalid leak warning in debug mode when freeing the stream */
965
986
#if ZEND_DEBUG
@@ -1021,6 +1042,7 @@ mongoc_stream_t* phongo_stream_initiator(const mongoc_uri_t *uri, const mongoc_h
1021
1042
/* flush missing, doesn't seem to be used */
1022
1043
base_stream -> vtable .type = 100 ;
1023
1044
base_stream -> vtable .destroy = phongo_stream_destroy ;
1045
+ base_stream -> vtable .failed = phongo_stream_failed ;
1024
1046
base_stream -> vtable .close = phongo_stream_close ;
1025
1047
base_stream -> vtable .writev = phongo_stream_writev ;
1026
1048
base_stream -> vtable .readv = phongo_stream_readv ;
0 commit comments