-
Notifications
You must be signed in to change notification settings - Fork 609
/
io.hpp
196 lines (148 loc) · 5.16 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#ifndef RBX_BUILTIN_IO_HPP
#define RBX_BUILTIN_IO_HPP
#include "builtin/object.hpp"
#include "type_info.hpp"
namespace rubinius {
class ByteArray;
class String;
class Encoding;
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
Encoding* external_; // slot
Encoding* internal_; // slot
Object* autoclose_; // 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);
attr_accessor(external, Encoding);
attr_accessor(internal, Encoding);
attr_accessor(autoclose, Object);
/* interface */
static void init(STATE);
static IO* create(STATE, int fd);
native_int to_fd();
void set_mode(STATE);
void force_read_only(STATE);
void force_write_only(STATE);
static void finalize(STATE, IO* io);
/* Class primitives */
// Rubinius.primitive :io_allocate
static IO* allocate(STATE, Object* self);
// Rubinius.primitive :io_connect_pipe
static Object* connect_pipe(STATE, IO* lhs, IO* rhs);
// Rubinius.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
*/
// Rubinius.primitive :io_select
static Object* select(STATE, Object* readables, Object* writables, Object* errorables, Object* timeout, CallFrame* calling_environment);
// Rubinius.primitive :io_fnmatch
static Object* fnmatch(STATE, String* pattern, String* path, Fixnum* flags);
/* Instance primitives */
// Rubinius.primitive :io_ensure_open
Object* ensure_open(STATE);
/**
* Directly read up to number of bytes from descriptor.
*
* Returns cNil at EOF.
*/
// Rubinius.primitive :io_sysread
Object* sysread(STATE, Fixnum* number_of_bytes, CallFrame* calling_environment);
// Rubinius.primitive :io_read_if_available
Object* read_if_available(STATE, Fixnum* number_of_bytes);
// Rubinius.primitive :io_socket_read
Object* socket_read(STATE, Fixnum* bytes, Fixnum* flags, Fixnum* type, CallFrame* calling_environment);
// Rubinius.primitive :io_seek
Integer* seek(STATE, Integer* amount, Fixnum* whence);
// Rubinius.primitive :io_write
Object* write(STATE, String* buf, CallFrame* calling_environment);
// Rubinius.primitive :io_reopen
Object* reopen(STATE, IO* other);
// Rubinius.primitive :io_reopen_path
Object* reopen_path(STATE, String* other, Fixnum * mode);
// Rubinius.primitive :io_close
Object* close(STATE);
// Rubinius.primitive :io_accept
Object* accept(STATE, CallFrame* calling_environment);
// Rubinius.primitive :io_send_io
Object* send_io(STATE, IO* io);
// Rubinius.primitive :io_recv_fd
Object* recv_fd(STATE, CallFrame* calling_environment);
/**
* 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.
*/
// Rubinius.primitive :io_shutdown
Object* shutdown(STATE, Fixnum* how);
// Rubinius.primitive :io_query
Object* query(STATE, Symbol* op);
// Rubinius.primitive :io_write_nonblock
Object* write_nonblock(STATE, String* buf);
// Rubinius.primitive :io_advise
Object* advise(STATE, Symbol* advice_name, Integer* offset, Integer* len);
void set_nonblock(STATE);
class Info : public TypeInfo {
public:
BASIC_TYPEINFO(TypeInfo)
};
};
#define IOBUFFER_SIZE 1024U
class IOBuffer : public Object {
public:
const static size_t fields = 7;
const static object_type type = IOBufferType;
private:
ByteArray* storage_; // 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(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);
// Rubinius.primitive :iobuffer_allocate
static IOBuffer* allocate(STATE);
// Rubinius.primitive :iobuffer_unshift
Object* unshift(STATE, String* str, Fixnum* start_pos);
// Rubinius.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