@@ -504,26 +504,34 @@ static int opt_connect_attr_add_i(VALUE key, VALUE value, VALUE arg)
504504}
505505#endif
506506
507- static VALUE rb_mysql_connect (VALUE self , VALUE user , VALUE pass , VALUE host , VALUE port , VALUE database , VALUE socket , VALUE flags , VALUE conn_attrs ) {
507+ static VALUE rb_mysql_connect (VALUE self , VALUE user , VALUE pass , VALUE host , VALUE port , VALUE database , VALUE socket , VALUE flags , VALUE conn_attrs , VALUE tls_sni_name ) {
508508 struct nogvl_connect_args args ;
509509 time_t start_time , end_time , elapsed_time , connect_timeout ;
510+ const char * sni_hostname ;
510511 VALUE rv ;
511512 GET_CLIENT (self );
512513
513- args .host = NIL_P (host ) ? NULL : StringValueCStr (host );
514- args .unix_socket = NIL_P (socket ) ? NULL : StringValueCStr (socket );
515- args .port = NIL_P (port ) ? 0 : NUM2INT (port );
516- args .user = NIL_P (user ) ? NULL : StringValueCStr (user );
517- args .passwd = NIL_P (pass ) ? NULL : StringValueCStr (pass );
518- args .db = NIL_P (database ) ? NULL : StringValueCStr (database );
519- args .mysql = wrapper -> client ;
520- args .client_flag = NUM2ULONG (flags );
514+ args .host = NIL_P (host ) ? NULL : StringValueCStr (host );
515+ args .unix_socket = NIL_P (socket ) ? NULL : StringValueCStr (socket );
516+ args .port = NIL_P (port ) ? 0 : NUM2INT (port );
517+ args .user = NIL_P (user ) ? NULL : StringValueCStr (user );
518+ args .passwd = NIL_P (pass ) ? NULL : StringValueCStr (pass );
519+ args .db = NIL_P (database ) ? NULL : StringValueCStr (database );
520+ args .mysql = wrapper -> client ;
521+ args .client_flag = NUM2ULONG (flags );
522+
523+ sni_hostname = NIL_P (tls_sni_name ) ? NULL : StringValueCStr (tls_sni_name );
521524
522525#ifdef CLIENT_CONNECT_ATTRS
523526 mysql_options (wrapper -> client , MYSQL_OPT_CONNECT_ATTR_RESET , 0 );
524527 rb_hash_foreach (conn_attrs , opt_connect_attr_add_i , (VALUE )wrapper );
525528#endif
526529
530+ if (sni_hostname != NULL ) {
531+ /* Set the TLS SNI name if provided */
532+ mysql_options (wrapper -> client , MYSQL_OPT_TLS_SNI_SERVERNAME , sni_hostname );
533+ }
534+
527535 if (wrapper -> connect_timeout )
528536 time (& start_time );
529537 rv = (VALUE ) rb_thread_call_without_gvl (nogvl_connect , & args , RUBY_UBF_IO , 0 );
@@ -1619,7 +1627,7 @@ void init_mysql2_client() {
16191627 rb_define_private_method (cMysql2Client , "ssl_mode=" , rb_set_ssl_mode_option , 1 );
16201628 rb_define_private_method (cMysql2Client , "enable_cleartext_plugin=" , set_enable_cleartext_plugin , 1 );
16211629 rb_define_private_method (cMysql2Client , "initialize_ext" , initialize_ext , 0 );
1622- rb_define_private_method (cMysql2Client , "connect" , rb_mysql_connect , 8 );
1630+ rb_define_private_method (cMysql2Client , "connect" , rb_mysql_connect , 9 );
16231631 rb_define_private_method (cMysql2Client , "_query" , rb_mysql_query , 2 );
16241632
16251633 sym_id = ID2SYM (rb_intern ("id" ));
0 commit comments