Ruby 4.1.0dev (2026-09-22 revision d41370aec5370c96a7a1a62b1be84d21347901fc)
io.h
1#ifndef INTERNAL_IO_H /*-*-C-*-vi:se ft=c:*/
2#define INTERNAL_IO_H
11#include "ruby/ruby.h" /* for VALUE */
12
13#define HAVE_RB_IO_T
14struct rb_io;
15
16#include "ruby/io.h" /* for rb_io_t */
17#include "ccan/list/list.h"
18#include "serial.h"
19
20#define IO_WITHOUT_GVL(func, arg) rb_nogvl(func, arg, RUBY_UBF_IO, 0, RB_NOGVL_OFFLOAD_SAFE)
21#define IO_WITHOUT_GVL_INT(func, arg) (int)(VALUE)IO_WITHOUT_GVL(func, arg)
22
23// Represents an in-flight blocking operation:
25 // The linked list data structure.
26 struct ccan_list_node list;
27
28 // The execution context of the blocking operation.
30
31 // An operation-scoped target passed to the Fiber scheduler if interrupted.
32 VALUE scheduler_interrupt_target;
33};
34
36struct rb_io {
37
39 VALUE self;
40
43
45 int fd;
46
48 enum rb_io_mode mode;
49
51 rb_pid_t pid;
52
54 int lineno;
55
58
60 void (*finalize)(struct rb_io*,int);
61
64
70
77
78 struct rb_io_encoding encs;
82
88
91
99
102
108
114
123
128
134 struct ccan_list_head blocking_operations;
135 struct rb_execution_context_struct *closing_ec;
136 VALUE wakeup_mutex;
137
138 // The fork generation of the blocking operations list.
139 rb_serial_t fork_generation;
140};
141
142/* io.c */
143void ruby_set_inplace_mode(const char *);
144void rb_stdio_set_default_encoding(void);
145VALUE rb_io_flush_raw(VALUE, int);
146size_t rb_io_memsize(const rb_io_t *);
147int rb_stderr_tty_p(void);
148VALUE rb_io_popen(VALUE pname, VALUE pmode, VALUE env, VALUE opt);
149
150VALUE rb_io_prep_stdin(void);
151VALUE rb_io_prep_stdout(void);
152VALUE rb_io_prep_stderr(void);
153
154int rb_io_notify_close(struct rb_io *fptr);
155bool rb_io_fptr_finalize_closed(struct rb_io *fptr);
156
157RUBY_SYMBOL_EXPORT_BEGIN
158/* io.c (export) */
159void rb_maygvl_fd_fix_cloexec(int fd);
160int rb_gc_for_fd(int err);
161void rb_write_error_str(VALUE mesg);
162
163VALUE rb_io_blocking_region_wait(struct rb_io *io, rb_blocking_function_t *function, void *argument, enum rb_io_event events);
164VALUE rb_io_blocking_region(struct rb_io *io, rb_blocking_function_t *function, void *argument);
165RUBY_SYMBOL_EXPORT_END
166
167#endif /* INTERNAL_IO_H */
rb_io_event
Type of events that an IO can wait.
Definition io.h:96
Decomposed encoding flags (e.g.
Definition io.h:134
IO buffers.
Definition io.h:109
Ruby's IO, metadata and buffers.
Definition io.h:295
rb_io_buffer_t wbuf
Write buffer.
Definition io.h:330
enum rb_io_mode mode
mode flags: FMODE_XXXs
Definition io.h:310
void(* finalize)(struct rb_io *, int)
finalize proc
Definition io.h:326
rb_econv_t * readconv
Encoding converter used when reading from this IO.
Definition io.h:352
rb_econv_t * writeconv
Encoding converter used when writing to this IO.
Definition io.h:363
struct rb_io_encoding encs
Decomposed encoding flags.
Definition io.h:348
VALUE self
The IO's Ruby level counterpart.
Definition io.h:298
VALUE write_lock
This is a Ruby level mutex.
Definition io.h:400
VALUE timeout
The timeout associated with this IO when performing blocking operations.
Definition io.h:406
FILE * stdio_file
stdio ptr for read/write, if available.
Definition io.h:302
VALUE writeconv_pre_ecopts
Value of ::rb_io_t::rb_io_enc_t::ecopts stored right before initialising rb_io_t::writeconv.
Definition io.h:390
VALUE tied_io_for_writing
Duplex IO object, if set.
Definition io.h:345
int writeconv_initialized
Whether rb_io_t::writeconv is already set up.
Definition io.h:376
int fd
file descriptor.
Definition io.h:306
rb_io_buffer_t rbuf
(Byte) read buffer.
Definition io.h:337
int lineno
number of lines read
Definition io.h:318
struct ccan_list_head blocking_operations
Threads that are performing a blocking operation without the GVL using this IO.
Definition io.h:134
VALUE writeconv_asciicompat
This is, when set, an instance of rb_cString which holds the "common" encoding.
Definition io.h:372
rb_io_buffer_t cbuf
rb_io_ungetc() destination.
Definition io.h:359
rb_pid_t pid
child's pid (for pipes)
Definition io.h:314
int writeconv_pre_ecflags
Value of ::rb_io_t::rb_io_enc_t::ecflags stored right before initialising rb_io_t::writeconv.
Definition io.h:383
VALUE pathv
pathname for file
Definition io.h:322
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40