1
2/*
3 * Copyright (C) Alexander Borisov
4 * Copyright (C) NGINX, Inc.
5 */
6
7#include <ruby/nxt_ruby.h>
8#include <nxt_unit.h>
9
10
11static VALUE nxt_ruby_stream_io_new(VALUE class, VALUE wrap);
12static VALUE nxt_ruby_stream_io_initialize(int argc, VALUE *argv, VALUE self);
13static VALUE nxt_ruby_stream_io_gets(VALUE obj, VALUE args);
14static VALUE nxt_ruby_stream_io_each(VALUE obj, VALUE args);
13static VALUE nxt_ruby_stream_io_gets(VALUE obj);
14static VALUE nxt_ruby_stream_io_each(VALUE obj);
15static VALUE nxt_ruby_stream_io_read(VALUE obj, VALUE args);
16static VALUE nxt_ruby_stream_io_rewind(VALUE obj, VALUE args);
16static VALUE nxt_ruby_stream_io_rewind(VALUE obj);
17static VALUE nxt_ruby_stream_io_puts(VALUE obj, VALUE args);
18static VALUE nxt_ruby_stream_io_write(VALUE obj, VALUE args);
19nxt_inline long nxt_ruby_stream_io_s_write(nxt_ruby_run_ctx_t *run_ctx,
20 VALUE val);
21static VALUE nxt_ruby_stream_io_flush(VALUE obj, VALUE args);
21static VALUE nxt_ruby_stream_io_flush(VALUE obj);
22
23
24VALUE
25nxt_ruby_stream_io_input_init(void)
26{
27 VALUE stream_io;
28
29 stream_io = rb_define_class("NGINX_Unit_Stream_IO_Read", rb_cData);

--- 50 unchanged lines hidden (view full) ---

80static VALUE
81nxt_ruby_stream_io_initialize(int argc, VALUE *argv, VALUE self)
82{
83 return self;
84}
85
86
87static VALUE
88nxt_ruby_stream_io_gets(VALUE obj, VALUE args)
88nxt_ruby_stream_io_gets(VALUE obj)
89{
90 VALUE buf;
91 char *p;
92 size_t size, b_size;
93 nxt_unit_buf_t *b;
94 nxt_ruby_run_ctx_t *run_ctx;
95 nxt_unit_request_info_t *req;
96

--- 30 unchanged lines hidden (view full) ---

127
128 rb_str_set_len(buf, size);
129
130 return buf;
131}
132
133
134static VALUE
135nxt_ruby_stream_io_each(VALUE obj, VALUE args)
135nxt_ruby_stream_io_each(VALUE obj)
136{
137 VALUE chunk;
138
139 if (rb_block_given_p() == 0) {
140 rb_raise(rb_eArgError, "Expected block on rack.input 'each' method");
141 }
142
143 for ( ;; ) {
144 chunk = nxt_ruby_stream_io_gets(obj, Qnil);
144 chunk = nxt_ruby_stream_io_gets(obj);
145
146 if (chunk == Qnil) {
147 return Qnil;
148 }
149
150 rb_yield(chunk);
151 }
152

--- 45 unchanged lines hidden (view full) ---

198
199 rb_str_set_len(buf, copy_size);
200
201 return buf;
202}
203
204
205static VALUE
206nxt_ruby_stream_io_rewind(VALUE obj, VALUE args)
206nxt_ruby_stream_io_rewind(VALUE obj)
207{
208 return Qnil;
209}
210
211
212static VALUE
213nxt_ruby_stream_io_puts(VALUE obj, VALUE args)
214{

--- 46 unchanged lines hidden (view full) ---

261
262 nxt_unit_req_error(run_ctx->req, "Ruby: %s", RSTRING_PTR(val));
263
264 return RSTRING_LEN(val);
265}
266
267
268static VALUE
269nxt_ruby_stream_io_flush(VALUE obj, VALUE args)
269nxt_ruby_stream_io_flush(VALUE obj)
270{
271 return Qnil;
272}