summaryrefslogtreecommitdiffhomepage
path: root/src/ruby
diff options
context:
space:
mode:
authorMax Romanov <max.romanov@nginx.com>2020-03-12 17:54:05 +0300
committerMax Romanov <max.romanov@nginx.com>2020-03-12 17:54:05 +0300
commit2454dfe876c7d761aa46f972addd3e7c97bb8d68 (patch)
tree119e3b55c7c1ed2b5d7346d2668e6caccb5c6998 /src/ruby
parent23636ce02cf8a9abc6759b88a117f84b8457a7cd (diff)
downloadunit-2454dfe876c7d761aa46f972addd3e7c97bb8d68.tar.gz
unit-2454dfe876c7d761aa46f972addd3e7c97bb8d68.tar.bz2
Introducing readline function in libunit.
Ruby and Java modules now use this function instead of own implementations.
Diffstat (limited to 'src/ruby')
-rw-r--r--src/ruby/nxt_ruby_stream_io.c28
1 files changed, 8 insertions, 20 deletions
diff --git a/src/ruby/nxt_ruby_stream_io.c b/src/ruby/nxt_ruby_stream_io.c
index 7e8b3ce1..cc110035 100644
--- a/src/ruby/nxt_ruby_stream_io.c
+++ b/src/ruby/nxt_ruby_stream_io.c
@@ -88,9 +88,7 @@ static VALUE
nxt_ruby_stream_io_gets(VALUE obj)
{
VALUE buf;
- char *p;
- size_t size, b_size;
- nxt_unit_buf_t *b;
+ ssize_t res;
nxt_ruby_run_ctx_t *run_ctx;
nxt_unit_request_info_t *req;
@@ -102,30 +100,20 @@ nxt_ruby_stream_io_gets(VALUE obj)
return Qnil;
}
- size = 0;
-
- for (b = req->content_buf; b; b = nxt_unit_buf_next(b)) {
- b_size = b->end - b->free;
- p = memchr(b->free, '\n', b_size);
-
- if (p != NULL) {
- p++;
- size += p - b->free;
- break;
- }
-
- size += b_size;
+ res = nxt_unit_request_readline_size(req, SSIZE_MAX);
+ if (nxt_slow_path(res < 0)) {
+ return Qnil;
}
- buf = rb_str_buf_new(size);
+ buf = rb_str_buf_new(res);
- if (buf == Qnil) {
+ if (nxt_slow_path(buf == Qnil)) {
return Qnil;
}
- size = nxt_unit_request_read(req, RSTRING_PTR(buf), size);
+ res = nxt_unit_request_read(req, RSTRING_PTR(buf), res);
- rb_str_set_len(buf, size);
+ rb_str_set_len(buf, res);
return buf;
}