End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
class method
BasicSocket.for_fd
BasicSocket.for_fd(fd) => basicsocket
ext/socket/basicsocket.c
View on GitHub ↗
static VALUE
bsock_s_for_fd(VALUE klass, VALUE fd)
{
rb_io_t *fptr;
VALUE sock = rsock_init_sock(rb_obj_alloc(klass), NUM2INT(fd));
GetOpenFile(sock, fptr);
return sock;
}
Returns a socket object which contains the file descriptor, fd.
Example
# If invoked by inetd, STDIN/STDOUT/STDERR is a socket. STDIN_SOCK = Socket.for_fd(STDIN.fileno) p STDIN_SOCK.remote_address
See also
.do_not_reverse_lookup=
#close_read
.do_not_reverse_lookup
#close_write
also in
4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1