Ruby 3.5.0dev (2025-06-26 revision 242343ff801e35d19d81ec9d4ff3c32a36c00f06)
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
33struct rb_io {
34
36 VALUE self;
37
40
42 int fd;
43
45 enum rb_io_mode mode;
46
48 rb_pid_t pid;
49
51 int lineno;
52
55
57 void (*finalize)(struct rb_io*,int);
58
61
67
74
75 struct rb_io_encoding encs;
79
85
88
96
99
105
111
120
125
131 struct ccan_list_head blocking_operations;
132 struct rb_execution_context_struct *closing_ec;
133 VALUE wakeup_mutex;
134
135 // The fork generation of the the blocking operations list.
136 rb_serial_t fork_generation;
137};
138
139/* io.c */
140void ruby_set_inplace_mode(const char *);
141void rb_stdio_set_default_encoding(void);
142VALUE rb_io_flush_raw(VALUE, int);
143size_t rb_io_memsize(const rb_io_t *);
144int rb_stderr_tty_p(void);
145VALUE rb_io_popen(VALUE pname, VALUE pmode, VALUE env, VALUE opt);
146
147VALUE rb_io_prep_stdin(void);
148VALUE rb_io_prep_stdout(void);
149VALUE rb_io_prep_stderr(void);
150
151int rb_io_notify_close(struct rb_io *fptr);
152
153RUBY_SYMBOL_EXPORT_BEGIN
154/* io.c (export) */
155void rb_maygvl_fd_fix_cloexec(int fd);
156int rb_gc_for_fd(int err);
157void rb_write_error_str(VALUE mesg);
158
159VALUE rb_io_blocking_region_wait(struct rb_io *io, rb_blocking_function_t *function, void *argument, enum rb_io_event events);
160VALUE rb_io_blocking_region(struct rb_io *io, rb_blocking_function_t *function, void *argument);
161RUBY_SYMBOL_EXPORT_END
162
163#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:131
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