Project

General

Profile

Actions

Feature #17187

closed

Add connect_timeout to TCPSocket

Added by Glass_saga (Masaki Matsushita) about 1 year ago. Updated 11 months ago.

Status:
Closed
Priority:
Normal
Target version:
-
[ruby-core:100139]

Description

Add connect_timeout to TCPSocket.new in the same way as Socket.tcp.

TCPSocket.new("192.0.2.1", 1234, connect_timeout: 1) #=> raise Errno::ETIMEDOUT

Files

connect_timeout.patch (8.93 KB) connect_timeout.patch Glass_saga (Masaki Matsushita), 09/25/2020 11:16 AM
ruby3-socksocket-fix.patch (361 Bytes) ruby3-socksocket-fix.patch A quick patch to fix the compilation of official Ruby 3.0.0 PhobosK (Phobos Kappa), 12/28/2020 02:48 PM

Related issues

Related to Ruby master - Feature #16381: Accept resolv_timeout in Net::HTTPOpenActions
Related to Ruby master - Feature #17134: Add resolv_timeout to TCPSocketOpenActions
Actions #2

Updated by Glass_saga (Masaki Matsushita) about 1 year ago

Actions #3

Updated by Glass_saga (Masaki Matsushita) about 1 year ago

Updated by matz (Yukihiro Matsumoto) about 1 year ago

Accepted.

Matz.

Updated by Glass_saga (Masaki Matsushita) about 1 year ago

  • Assignee set to Glass_saga (Masaki Matsushita)
  • Status changed from Open to Assigned
Actions #7

Updated by naruse (Yui NARUSE) 12 months ago

  • Target version deleted (3.0)
Actions #8

Updated by Glass_saga (Masaki Matsushita) 12 months ago

  • Status changed from Assigned to Closed

Applied in changeset git|78f188524f551c97b1a7a44ae13514729f1a21c7.


Add connect_timeout to TCPSocket

Add connect_timeout to TCPSocket.new in the same way as Socket.tcp.

Closes [Feature #17187]

Updated by PhobosK (Phobos Kappa) 11 months ago

You forgot to add the new parameter connect_timeout to the return statement of the function socks_init in sockssocket.c.
Thus the now available official sources of Ruby 3.0.0 cannot compile when sockets are enabled giving the error:

x86_64-pc-linux-gnu-gcc -I. -I../../.ext/include/x86_64-linux -I../.././include -I../.././ext/socket -I../.. -I../../. -DRUBY_EXTCONF_H=\"extconf.h\"    -fPIC -march=native -O2 -pipe -fno-strict-aliasing -fPIC  -o sockssocket.o -c sockssocket.c
sockssocket.c: In function ‘socks_init’:
sockssocket.c:37:12: error: too few arguments to function ‘rsock_init_inetsock’
   37 |     return rsock_init_inetsock(sock, host, port, Qnil, Qnil, INET_SOCKS, Qnil);
      |            ^~~~~~~~~~~~~~~~~~~
In file included from sockssocket.c:11:
rubysocket.h:349:7: note: declared here
  349 | VALUE rsock_init_inetsock(VALUE sock, VALUE remote_host, VALUE remote_serv, VALUE local_host, VALUE local_serv, int type, VALUE resolv_timeout, VALUE connect_timeout);
      |       ^~~~~~~~~~~~~~~~~~~
make[2]: *** [Makefile:262: sockssocket.o] Error 1
make[2]: Leaving directory '/dev/shm/portage/dev-lang/ruby-3.0.0/work/ruby-3.0.0/ext/socket'
make[1]: *** [exts.mk:285: ext/socket/all] Error 2
make[1]: Leaving directory '/dev/shm/portage/dev-lang/ruby-3.0.0/work/ruby-3.0.0'
make: *** [uncommon.mk:300: build-ext] Error 2

I dunno if something else is missing also, but adding the Qnil as last parameter in line 37 of ext/socket/sockssocket.c

return rsock_init_inetsock(sock, host, port, Qnil, Qnil, INET_SOCKS, Qnil, Qnil);

fixes at least the compilation....

Thanks.

Great work BTW :)

Updated by Glass_saga (Masaki Matsushita) 11 months ago

PhobosK (Phobos Kappa)

Many thanks for reporting the issue!
I merged your patch.

Actions

Also available in: Atom PDF