about summary refs log tree commit homepage
path: root/ext/raindrops/tcp_info.c
diff options
context:
space:
mode:
authorEric Wong <bofh@yhbt.net>2023-06-11 21:33:25 +0000
committerEric Wong <bofh@yhbt.net>2023-06-26 09:16:36 +0000
commita8dfec2568830241a27fce10014b6151a7a47813 (patch)
tree9c31af5dbeffb046a23eb1fb4fe85ec68a7f49fc /ext/raindrops/tcp_info.c
parentb3212417cc3e7cc44aa9e1ffe89b0d62ef3fdab5 (diff)
downloadraindrops-a8dfec2568830241a27fce10014b6151a7a47813.tar.gz
Calling `#to_io' is only necessary when we're handling an argument
from user code where the user could pass a non-IO object.
`#to_io' calls are a waste of time when we create the IO object
ourselves (in `Raindrops::InetDiagSock.new').

This allows us to define the `my_fileno' macro for Ruby 3.1+
users to call the new `rb_io_descriptor' function directly
without an extra C stack frame.  This also allows us to get
rid of nesting CPP directives inside C functions which (IMHO)
improves readability.

Furthermore, any necessary #to_io calls using `rb_convert_type'
can be replaced with `rb_io_get_io' to decrease code size.
`rb_io_get_io' has been in ruby/io.h since Ruby 1.9.2 and
there's no expectation that it'd be deprecated since it only
deals with opaque `VALUE' types.
Diffstat (limited to 'ext/raindrops/tcp_info.c')
-rw-r--r--ext/raindrops/tcp_info.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/ext/raindrops/tcp_info.c b/ext/raindrops/tcp_info.c
index b82f705..c0d34e0 100644
--- a/ext/raindrops/tcp_info.c
+++ b/ext/raindrops/tcp_info.c
@@ -76,7 +76,7 @@ static VALUE alloc(VALUE klass)
  */
 static VALUE init(VALUE self, VALUE io)
 {
-        int fd = my_fileno(io);
+        int fd = my_fileno(rb_io_get_io(io));
         struct tcp_info *info = DATA_PTR(self);
         socklen_t len = (socklen_t)sizeof(struct tcp_info);
         int rc = getsockopt(fd, IPPROTO_TCP, TCP_INFO, info, &len);