Ruby: rb_io Struct Reference

Ruby 3.4.7p58 (2025-10-08 revision 7a5688e2a27668e48f8d6ff4af5b2208b98a2f5e)

Data Fields
rb_io Struct Reference

Ruby's IO, metadata and buffers. More...

`#include <io.h>`

## Data Fields
VALUE | self
| The IO's Ruby level counterpart.
FILE * | stdio_file
| stdio ptr for read/write, if available.
int | fd
| file descriptor.
int | mode
| mode flags: FMODE_XXXs
rb_pid_t | pid
| child's pid (for pipes)
int | lineno
| number of lines read
VALUE | pathv
| pathname for file
void(* | finalize )(struct rb_io *, int)
| finalize proc
rb_io_buffer_t | wbuf
| Write buffer.
rb_io_buffer_t | rbuf
| (Byte) read buffer.
VALUE | tied_io_for_writing
| Duplex IO object, if set.
struct rb_io_encoding | encs
| Decomposed encoding flags.
rb_econv_t * | readconv
| Encoding converter used when reading from this IO.
rb_io_buffer_t | cbuf
| rb_io_ungetc() destination.
rb_econv_t * | writeconv
| Encoding converter used when writing to this IO.
VALUE | writeconv_asciicompat
| This is, when set, an instance of rb_cString which holds the "common" encoding.
int | writeconv_initialized
| Whether rb_io_t::writeconv is already set up.
int | writeconv_pre_ecflags
| Value of ::rb_io_t::rb_io_enc_t::ecflags stored right before initialising rb_io_t::writeconv.
VALUE | writeconv_pre_ecopts
| Value of ::rb_io_t::rb_io_enc_t::ecopts stored right before initialising rb_io_t::writeconv.
VALUE | write_lock
| This is a Ruby level mutex.
VALUE | timeout
| The timeout associated with this IO when performing blocking operations.

## Detailed Description

Ruby's IO, metadata and buffers.

Definition at line 143 of file io.h.

## Field Documentation

## ◆ cbuf

rb_io_buffer_t rb_io::cbuf

rb_io_ungetc() destination.

This buffer is read before checking rb_io_t::rbuf

Definition at line 207 of file io.h.

Referenced by rb_io_ungetc().

## ◆ encs

struct rb_io_encoding rb_io::encs

Decomposed encoding flags.

Definition at line 196 of file io.h.

Referenced by rb_io_open_descriptor().

## ◆ fd

int rb_io::fd

file descriptor.

Definition at line 154 of file io.h.

Referenced by rb_file_size(), rb_io_binmode(), rb_io_check_closed(), rb_io_closed_p(), rb_io_descriptor(), rb_io_eof(), rb_io_getbyte(), rb_io_open_descriptor(), rb_io_set_nonblock(), rb_io_stdio_file(), and rb_io_wait().

## ◆ finalize

void(* rb_io::finalize)(struct rb_io *, int)

finalize proc

Definition at line 174 of file io.h.

## ◆ lineno

int rb_io::lineno

number of lines read

Definition at line 166 of file io.h.

## ◆ mode

int rb_io::mode

mode flags: FMODE_XXXs

Definition at line 158 of file io.h.

Referenced by rb_file_size(), rb_io_binmode(), rb_io_check_char_readable(), rb_io_check_writable(), rb_io_getbyte(), rb_io_mode(), rb_io_open_descriptor(), rb_io_stdio_file(), and rb_io_synchronized().

## ◆ pathv

VALUE rb_io::pathv

pathname for file

Definition at line 170 of file io.h.

Referenced by rb_file_size(), rb_io_open_descriptor(), rb_io_path(), and rb_io_set_nonblock().

## ◆ pid

rb_pid_t rb_io::pid

child's pid (for pipes)

Definition at line 162 of file io.h.

## ◆ rbuf

rb_io_buffer_t rb_io::rbuf

(Byte) read buffer.

Note also that there is a field called rb_io_t::cbuf, which also concerns read IO.

Definition at line 185 of file io.h.

Referenced by rb_io_check_writable(), and rb_io_getbyte().

## ◆ readconv

rb_econv_t * rb_io::readconv

Encoding converter used when reading from this IO.

Definition at line 200 of file io.h.

Referenced by rb_io_binmode().

## ◆ self

VALUE rb_io::self

The IO's Ruby level counterpart.

Definition at line 146 of file io.h.

Referenced by rb_io_open_descriptor(), and rb_io_read_check().

## ◆ stdio_file

FILE * rb_io::stdio_file

stdio ptr for read/write, if available.

Definition at line 150 of file io.h.

Referenced by rb_io_stdio_file().

## ◆ tied_io_for_writing

VALUE rb_io::tied_io_for_writing

Duplex IO object, if set.

See also
  rb_io_set_write_io()

Definition at line 193 of file io.h.

Referenced by rb_io_check_char_readable(), and rb_io_set_write_io().

## ◆ timeout

VALUE rb_io::timeout

The timeout associated with this IO when performing blocking operations.

Definition at line 254 of file io.h.

Referenced by rb_io_open_descriptor(), rb_io_set_timeout(), rb_io_timeout(), and rb_io_wait().

## ◆ wbuf

rb_io_buffer_t rb_io::wbuf

Write buffer.

Definition at line 178 of file io.h.

Referenced by rb_io_check_char_readable().

## ◆ write_lock

VALUE rb_io::write_lock

This is a Ruby level mutex.

It avoids multiple threads to write to an IO at once; helps for instance rb_io_puts() to ensure newlines right next to its arguments.

This of course doesn't help inter-process IO interleaves, though.

Definition at line 248 of file io.h.

## ◆ writeconv

rb_econv_t * rb_io::writeconv

Encoding converter used when writing to this IO.

Definition at line 211 of file io.h.

Referenced by rb_io_binmode().

## ◆ writeconv_asciicompat

VALUE rb_io::writeconv_asciicompat

This is, when set, an instance of rb_cString which holds the "common" encoding.

Write conversion can convert strings twice... In case conversion from encoding X to encoding Y does not exist, Ruby finds an encoding Z that bridges the two, so that X to Z to Y conversion happens.

Definition at line 220 of file io.h.

## ◆ writeconv_initialized

int rb_io::writeconv_initialized

Whether rb_io_t::writeconv is already set up.

Definition at line 224 of file io.h.

## ◆ writeconv_pre_ecflags

int rb_io::writeconv_pre_ecflags

Value of ::rb_io_t::rb_io_enc_t::ecflags stored right before initialising rb_io_t::writeconv.

Definition at line 231 of file io.h.

Referenced by rb_io_binmode().

## ◆ writeconv_pre_ecopts

VALUE rb_io::writeconv_pre_ecopts

Value of ::rb_io_t::rb_io_enc_t::ecopts stored right before initialising rb_io_t::writeconv.

Definition at line 238 of file io.h.

The documentation for this struct was generated from the following files:

- include/ruby/io.h
- internal/io.h