-
Notifications
You must be signed in to change notification settings - Fork 609
/
io.hpp
170 lines (128 loc) · 4.06 KB
/
io.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#ifndef RBX_BUILTIN_IO_HPP
#define RBX_BUILTIN_IO_HPP
#include "builtin/object.hpp"
#include "type_info.hpp"
namespace rubinius {
class ByteArray;
class Channel;
class String;
class ByteArray;
class IO : public Object {
public:
const static object_type type = IOType;
private:
Fixnum* descriptor_; // slot
Object* ibuffer_; // slot
Fixnum* mode_; // slot
Object* eof_; // slot
Integer* lineno_; // slot
Object* sync_; // slot
public:
/* accessors */
attr_accessor(descriptor, Fixnum);
attr_accessor(ibuffer, Object);
attr_accessor(mode, Fixnum);
attr_accessor(eof, Object);
attr_accessor(lineno, Integer);
attr_accessor(sync, Object);
/* interface */
static void init(STATE);
static IO* create(STATE, int fd);
native_int to_fd();
void set_mode(STATE);
void unsafe_set_descriptor(native_int fd);
void force_read_only(STATE);
void force_write_only(STATE);
/* Class primitives */
// Ruby.primitive :io_allocate
static IO* allocate(STATE, Object* self);
// Ruby.primitive :io_connect_pipe
static Object* connect_pipe(STATE, IO* lhs, IO* rhs);
// Ruby.primitive :io_open
static Fixnum* open(STATE, String* path, Fixnum* mode, Fixnum* perm);
/**
* Perform select() on descriptors.
*
* @todo Replace with an evented version when redoing events. --rue
*/
// Ruby.primitive :io_select
static Object* select(STATE, Object* readables, Object* writables, Object* errorables, Object* timeout, CallFrame* calling_environment);
/* Instance primitives */
// Ruby.primitive :io_ensure_open
Object* ensure_open(STATE);
/**
* Directly read up to number of bytes from descriptor.
*
* Returns Qnil at EOF.
*/
// Ruby.primitive :io_sysread
Object* sysread(STATE, Fixnum* number_of_bytes, CallFrame* calling_environment);
// Ruby.primitive :io_seek
Integer* seek(STATE, Integer* amount, Fixnum* whence);
// Ruby.primitive :io_write
Object* write(STATE, String* buf);
// Ruby.primitive :io_reopen
Object* reopen(STATE, IO* other);
// Ruby.primitive :io_close
Object* close(STATE);
/**
* Shutdown a full-duplex descriptor's read and/or write stream.
*
* Careful with this, it applies to full-duplex only.
* It also shuts the stream *in all processes*, not
* just the current one.
*/
// Ruby.primitive :io_shutdown
Object* shutdown(STATE, Fixnum* how);
// Ruby.primitive :io_blocking_read
Object* blocking_read(STATE, Fixnum* count);
// Ruby.primitive :io_query
Object* query(STATE, Symbol* op);
class Info : public TypeInfo {
public:
BASIC_TYPEINFO(TypeInfo)
};
};
#define IOBUFFER_SIZE 32384U
class IOBuffer : public Object {
public:
const static size_t fields = 7;
const static object_type type = IOBufferType;
private:
ByteArray* storage_; // slot
Channel* channel_; // slot
Integer* total_; // slot
Integer* used_; // slot
Integer* start_; // slot
Object* eof_; // slot
Object* write_synced_;// slot
public:
/* accessors */
attr_accessor(storage, ByteArray);
attr_accessor(channel, Channel);
attr_accessor(total, Integer);
attr_accessor(used, Integer);
attr_accessor(start, Integer);
attr_accessor(eof, Object);
attr_accessor(write_synced, Object);
/* interface */
static IOBuffer* create(STATE, size_t bytes = IOBUFFER_SIZE);
// Ruby.primitive :iobuffer_allocate
static IOBuffer* allocate(STATE);
// Ruby.primitive :iobuffer_unshift
Object* unshift(STATE, String* str, Fixnum* start_pos);
// Ruby.primitive :iobuffer_fill
Object* fill(STATE, IO* io, CallFrame* calling_environment);
void reset(STATE);
String* drain(STATE);
char* byte_address();
size_t left();
char* at_unused();
void read_bytes(STATE, size_t bytes);
class Info : public TypeInfo {
public:
BASIC_TYPEINFO(TypeInfo)
};
};
}
#endif