@@ -27,9 +27,19 @@ struct inetsock_arg
2727};
2828
2929void
30- rsock_raise_user_specified_timeout (void )
30+ rsock_raise_user_specified_timeout (struct addrinfo * ai , VALUE host , VALUE port )
3131{
32- rb_raise (rb_eIOTimeoutError , "user specified timeout" );
32+ VALUE message ;
33+
34+ if (ai && ai -> ai_addr ) {
35+ VALUE rai = rsock_addrinfo_new ((struct sockaddr * )ai -> ai_addr , (socklen_t )ai -> ai_addrlen , PF_UNSPEC , 0 , 0 , Qnil , Qnil );
36+ VALUE addr_str = rsock_addrinfo_inspect_sockaddr (rai );
37+ message = rb_sprintf ("user specified timeout for %" PRIsVALUE , addr_str );
38+ } else {
39+ message = rb_sprintf ("user specified timeout for %" PRIsVALUE " port %" PRIsVALUE , host , port );
40+ }
41+
42+ rb_raise (rb_eIOTimeoutError , "%" PRIsVALUE , message );
3343}
3444
3545static VALUE
@@ -149,7 +159,9 @@ init_inetsock_internal(VALUE v)
149159 } else {
150160 VALUE elapsed = rb_funcall (current_clocktime (), '-' , 1 , starts_at );
151161 timeout = rb_funcall (open_timeout , '-' , 1 , elapsed );
152- if (rb_funcall (timeout , '<' , 1 , INT2FIX (0 )) == Qtrue ) rsock_raise_user_specified_timeout ();
162+ if (rb_funcall (timeout , '<' , 1 , INT2FIX (0 )) == Qtrue ) {
163+ rsock_raise_user_specified_timeout (res , arg -> remote .host , arg -> remote .serv );
164+ }
153165 }
154166
155167 if (status >= 0 ) {
@@ -844,6 +856,10 @@ init_fast_fallback_inetsock_internal(VALUE v)
844856 if (!NIL_P (open_timeout )) {
845857 VALUE elapsed = rb_funcall (current_clocktime (), '-' , 1 , starts_at );
846858 timeout = rb_funcall (open_timeout , '-' , 1 , elapsed );
859+
860+ if (rb_funcall (timeout , '<' , 1 , INT2FIX (0 )) == Qtrue ) {
861+ rsock_raise_user_specified_timeout (NULL , arg -> remote .host , arg -> remote .serv );
862+ }
847863 }
848864 if (NIL_P (timeout )) {
849865 if (!NIL_P (connect_timeout )) {
@@ -1180,7 +1196,9 @@ init_fast_fallback_inetsock_internal(VALUE v)
11801196 }
11811197 }
11821198
1183- if (is_timeout_tv (user_specified_open_timeout_at , now )) rsock_raise_user_specified_timeout ();
1199+ if (is_timeout_tv (user_specified_open_timeout_at , now )) {
1200+ rsock_raise_user_specified_timeout (NULL , arg -> remote .host , arg -> remote .serv );
1201+ }
11841202
11851203 if (!any_addrinfos (& resolution_store )) {
11861204 if (!in_progress_fds (arg -> connection_attempt_fds_size ) &&
@@ -1203,7 +1221,7 @@ init_fast_fallback_inetsock_internal(VALUE v)
12031221 resolution_store .is_all_finished ) &&
12041222 (is_timeout_tv (user_specified_connect_timeout_at , now ) ||
12051223 !in_progress_fds (arg -> connection_attempt_fds_size ))) {
1206- rsock_raise_user_specified_timeout ();
1224+ rsock_raise_user_specified_timeout (NULL , arg -> remote . host , arg -> remote . serv );
12071225 }
12081226 }
12091227 }
0 commit comments