@@ -293,7 +293,7 @@ rb_freeaddrinfo(struct rb_addrinfo *ai)
293293 xfree (ai );
294294}
295295
296- unsigned int
296+ static int
297297rsock_value_timeout_to_msec (VALUE timeout )
298298{
299299 double seconds = NUM2DBL (timeout );
@@ -308,7 +308,7 @@ rsock_value_timeout_to_msec(VALUE timeout)
308308#if GETADDRINFO_IMPL == 0
309309
310310static int
311- rb_getaddrinfo (const char * hostp , const char * portp , const struct addrinfo * hints , struct addrinfo * * ai , unsigned int _timeout )
311+ rb_getaddrinfo (const char * hostp , const char * portp , const struct addrinfo * hints , struct addrinfo * * ai , int _timeout )
312312{
313313 return getaddrinfo (hostp , portp , hints , ai );
314314}
@@ -346,7 +346,7 @@ fork_safe_getaddrinfo(void *arg)
346346}
347347
348348static int
349- rb_getaddrinfo (const char * hostp , const char * portp , const struct addrinfo * hints , struct addrinfo * * ai , unsigned int _timeout )
349+ rb_getaddrinfo (const char * hostp , const char * portp , const struct addrinfo * hints , struct addrinfo * * ai , int _timeout )
350350{
351351 struct getaddrinfo_arg arg ;
352352 MEMZERO (& arg , struct getaddrinfo_arg , 1 );
@@ -367,11 +367,11 @@ struct getaddrinfo_arg
367367 int err , gai_errno , refcount , done , cancelled , timedout ;
368368 rb_nativethread_lock_t lock ;
369369 rb_nativethread_cond_t cond ;
370- unsigned int timeout ;
370+ int timeout ;
371371};
372372
373373static struct getaddrinfo_arg *
374- allocate_getaddrinfo_arg (const char * hostp , const char * portp , const struct addrinfo * hints , unsigned int timeout )
374+ allocate_getaddrinfo_arg (const char * hostp , const char * portp , const struct addrinfo * hints , int timeout )
375375{
376376 size_t hostp_offset = sizeof (struct getaddrinfo_arg );
377377 size_t portp_offset = hostp_offset + (hostp ? strlen (hostp ) + 1 : 0 );
@@ -465,8 +465,11 @@ wait_getaddrinfo(void *ptr)
465465 struct getaddrinfo_arg * arg = (struct getaddrinfo_arg * )ptr ;
466466 rb_nativethread_lock_lock (& arg -> lock );
467467 while (!arg -> done && !arg -> cancelled ) {
468- unsigned long msec = arg -> timeout ;
469- if (msec > 0 ) {
468+ long msec = arg -> timeout ;
469+ if (msec == 0 ) {
470+ arg -> cancelled = 1 ;
471+ arg -> timedout = 1 ;
472+ } else if (msec > 0 ) {
470473 rb_native_cond_timedwait (& arg -> cond , & arg -> lock , msec );
471474 if (!arg -> done ) {
472475 arg -> cancelled = 1 ;
@@ -549,7 +552,7 @@ fork_safe_do_getaddrinfo(void *ptr)
549552}
550553
551554static int
552- rb_getaddrinfo (const char * hostp , const char * portp , const struct addrinfo * hints , struct addrinfo * * ai , unsigned int timeout )
555+ rb_getaddrinfo (const char * hostp , const char * portp , const struct addrinfo * hints , struct addrinfo * * ai , int timeout )
553556{
554557 int retry ;
555558 struct getaddrinfo_arg * arg ;
@@ -1021,7 +1024,7 @@ rb_scheduler_getaddrinfo(VALUE scheduler, VALUE host, const char *service,
10211024}
10221025
10231026struct rb_addrinfo *
1024- rsock_getaddrinfo (VALUE host , VALUE port , struct addrinfo * hints , int socktype_hack , unsigned int timeout )
1027+ rsock_getaddrinfo (VALUE host , VALUE port , struct addrinfo * hints , int socktype_hack , VALUE timeout )
10251028{
10261029 struct rb_addrinfo * res = NULL ;
10271030 struct addrinfo * ai ;
@@ -1056,7 +1059,8 @@ rsock_getaddrinfo(VALUE host, VALUE port, struct addrinfo *hints, int socktype_h
10561059 }
10571060
10581061 if (!resolved ) {
1059- error = rb_getaddrinfo (hostp , portp , hints , & ai , timeout );
1062+ int t = NIL_P (timeout ) ? -1 : rsock_value_timeout_to_msec (timeout );
1063+ error = rb_getaddrinfo (hostp , portp , hints , & ai , t );
10601064 if (error == 0 ) {
10611065 res = (struct rb_addrinfo * )xmalloc (sizeof (struct rb_addrinfo ));
10621066 res -> allocated_by_malloc = 0 ;
@@ -1089,7 +1093,7 @@ rsock_fd_family(int fd)
10891093}
10901094
10911095struct rb_addrinfo *
1092- rsock_addrinfo (VALUE host , VALUE port , int family , int socktype , int flags , unsigned int timeout )
1096+ rsock_addrinfo (VALUE host , VALUE port , int family , int socktype , int flags , VALUE timeout )
10931097{
10941098 struct addrinfo hints ;
10951099
@@ -1380,8 +1384,7 @@ call_getaddrinfo(VALUE node, VALUE service,
13801384 hints .ai_flags = NUM2INT (flags );
13811385 }
13821386
1383- unsigned int t = NIL_P (timeout ) ? 0 : rsock_value_timeout_to_msec (timeout );
1384- res = rsock_getaddrinfo (node , service , & hints , socktype_hack , t );
1387+ res = rsock_getaddrinfo (node , service , & hints , socktype_hack , timeout );
13851388
13861389 if (res == NULL )
13871390 rb_raise (rb_eSocket , "host not found" );
0 commit comments