summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_unit.c
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/nxt_unit.c
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/nxt_unit.c')
-rw-r--r--src/nxt_unit.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/nxt_unit.c b/src/nxt_unit.c
index 7c3d945c..07717545 100644
--- a/src/nxt_unit.c
+++ b/src/nxt_unit.c
@@ -2428,6 +2428,44 @@ nxt_unit_request_read(nxt_unit_request_info_t *req, void *dst, size_t size)
}
+ssize_t
+nxt_unit_request_readline_size(nxt_unit_request_info_t *req, size_t max_size)
+{
+ char *p;
+ size_t l_size, b_size;
+ nxt_unit_buf_t *b;
+
+ if (req->content_length == 0) {
+ return 0;
+ }
+
+ l_size = 0;
+
+ b = req->content_buf;
+
+ while (b != NULL) {
+ b_size = b->end - b->free;
+ p = memchr(b->free, '\n', b_size);
+
+ if (p != NULL) {
+ p++;
+ l_size += p - b->free;
+ break;
+ }
+
+ l_size += b_size;
+
+ if (max_size <= l_size) {
+ break;
+ }
+
+ b = nxt_unit_buf_next(b);
+ }
+
+ return nxt_min(max_size, l_size);
+}
+
+
static ssize_t
nxt_unit_buf_read(nxt_unit_buf_t **b, uint64_t *len, void *dst, size_t size)
{