Class: UringMachine::IO
- Inherits:
-
Object
- Object
- UringMachine::IO
- Defined in:
- ext/um/um_io_class.c
Defined Under Namespace
Classes: RESPError
Class Method Summary collapse
Instance Method Summary collapse
- #clear ⇒ Object
- #consumed ⇒ Object
- #eof? ⇒ Object
- #initialize(*args) ⇒ Object constructor
- #mode ⇒ Object
- #pending ⇒ Object
- #read(len) ⇒ Object
- #read_each ⇒ Object
- #read_int_be(len) ⇒ Object
- #read_line(limit) ⇒ Object
- #read_to_delim(delim, limit) ⇒ Object
- #read_uint_be(len) ⇒ Object
- #resp_read ⇒ Object
- #resp_write(obj) ⇒ Object
- #skip(len) ⇒ Object
- #write(*args) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'ext/um/um_io_class.c', line 134
VALUE IO_initialize(int argc, VALUE *argv, VALUE self) {
VALUE machine;
VALUE target;
VALUE mode;
rb_scan_args(argc, argv, "21", &machine, &target, &mode);
struct um_io *conn = um_get_io(self);
memset(conn, 0, sizeof(struct um_io));
RB_OBJ_WRITE(self, &conn->self, self);
conn->machine = um_get_machine(machine);
io_setup(conn, target, mode);
return self;
}
|
Class Method Details
.resp_encode(str, obj) ⇒ Object
343 344 345 346 347 348 349 350 |
# File 'ext/um/um_io_class.c', line 343
VALUE IO_resp_encode(VALUE self, VALUE str, VALUE obj) {
struct um_write_buffer buf;
write_buffer_init(&buf, str);
rb_str_modify(str);
resp_encode(&buf, obj);
write_buffer_update_len(&buf);
return str;
}
|
Instance Method Details
#clear ⇒ Object
395 396 397 398 399 |
# File 'ext/um/um_io_class.c', line 395 VALUE IO_clear(VALUE self) { struct um_io *conn = um_get_io(self); io_clear(conn); return self; } |
#consumed ⇒ Object
371 372 373 374 |
# File 'ext/um/um_io_class.c', line 371
VALUE IO_consumed(VALUE self) {
struct um_io *conn = um_get_io(self);
return LONG2NUM(conn->consumed_bytes);
}
|
#eof? ⇒ Object
359 360 361 362 |
# File 'ext/um/um_io_class.c', line 359
VALUE IO_eof_p(VALUE self) {
struct um_io *conn = um_get_io(self);
return conn->eof ? Qtrue : Qfalse;
}
|
#mode ⇒ Object
157 158 159 160 161 162 163 164 165 166 |
# File 'ext/um/um_io_class.c', line 157
VALUE IO_mode(VALUE self) {
struct um_io *conn = um_get_io(self);
switch (conn->mode) {
case IO_FD: return SYM_fd;
case IO_SOCKET: return SYM_socket;
case IO_SSL: return SYM_ssl;
default: return Qnil;
}
return Qnil;
}
|
#pending ⇒ Object
383 384 385 386 |
# File 'ext/um/um_io_class.c', line 383
VALUE IO_pending(VALUE self) {
struct um_io *conn = um_get_io(self);
return LONG2NUM(conn->pending_bytes);
}
|
#read(len) ⇒ Object
193 194 195 196 |
# File 'ext/um/um_io_class.c', line 193
VALUE IO_read(VALUE self, VALUE len) {
struct um_io *conn = um_get_io(self);
return io_read(conn, Qnil, NUM2LONG(len), 0, false);
}
|
#read_each ⇒ Object
239 240 241 242 243 |
# File 'ext/um/um_io_class.c', line 239 VALUE IO_read_each(VALUE self) { struct um_io *conn = um_get_io(self); io_read_each(conn); return self; } |
#read_int_be(len) ⇒ Object
257 258 259 260 261 262 |
# File 'ext/um/um_io_class.c', line 257
VALUE IO_read_int_be(VALUE self, VALUE len) {
struct um_io *conn = um_get_io(self);
size_t len_i = NUM2UINT(len);
if (unlikely(len_i > MAX_INT_SIZE)) rb_raise(eUMError, "Invalid length given");
return io_read_int_be(conn, len_i);
}
|
#read_line(limit) ⇒ Object
178 179 180 181 |
# File 'ext/um/um_io_class.c', line 178
VALUE IO_read_line(VALUE self, VALUE limit) {
struct um_io *conn = um_get_io(self);
return io_read_line(conn, Qnil, NUM2ULONG(limit));
}
|
#read_to_delim(delim, limit) ⇒ Object
213 214 215 216 |
# File 'ext/um/um_io_class.c', line 213
VALUE IO_read_to_delim(VALUE self, VALUE delim, VALUE limit) {
struct um_io *conn = um_get_io(self);
return io_read_to_delim(conn, Qnil, delim, NUM2LONG(limit));
}
|
#read_uint_be(len) ⇒ Object
274 275 276 277 278 279 |
# File 'ext/um/um_io_class.c', line 274
VALUE IO_read_uint_be(VALUE self, VALUE len) {
struct um_io *conn = um_get_io(self);
size_t len_i = NUM2UINT(len);
if (unlikely(len_i > MAX_INT_SIZE)) rb_raise(eUMError, "Invalid length given");
return io_read_uint_be(conn, len_i);
}
|
#resp_read ⇒ Object
302 303 304 305 306 307 308 |
# File 'ext/um/um_io_class.c', line 302 VALUE IO_resp_read(VALUE self) { struct um_io *conn = um_get_io(self); VALUE out_buffer = rb_utf8_str_new_literal(""); VALUE obj = resp_read(conn, out_buffer); RB_GC_GUARD(out_buffer); return obj; } |
#resp_write(obj) ⇒ Object
319 320 321 322 323 324 325 326 327 328 329 330 331 332 |
# File 'ext/um/um_io_class.c', line 319
VALUE IO_resp_write(VALUE self, VALUE obj) {
struct um_io *conn = um_get_io(self);
VALUE str = rb_str_new(NULL, 0);
struct um_write_buffer buf;
write_buffer_init(&buf, str);
rb_str_modify(str);
resp_encode(&buf, obj);
write_buffer_update_len(&buf);
size_t len = io_write_raw(conn, buf.ptr, buf.len);
RB_GC_GUARD(str);
return ULONG2NUM(len);
}
|
#skip(len) ⇒ Object
226 227 228 229 230 |
# File 'ext/um/um_io_class.c', line 226
VALUE IO_skip(VALUE self, VALUE len) {
struct um_io *conn = um_get_io(self);
io_skip(conn, NUM2LONG(len), true);
return len;
}
|
#write(*args) ⇒ Object
290 291 292 293 |
# File 'ext/um/um_io_class.c', line 290
VALUE IO_write(int argc, VALUE *argv, VALUE self) {
struct um_io *conn = um_get_io(self);
return io_writev(conn, argc, argv);
}
|