summaryrefslogtreecommitdiffhomepage
path: root/src/java/nxt_jni_InputStream.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/java/nxt_jni_InputStream.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 '')
-rw-r--r--src/java/nxt_jni_InputStream.c28
1 files changed, 4 insertions, 24 deletions
diff --git a/src/java/nxt_jni_InputStream.c b/src/java/nxt_jni_InputStream.c
index b96ff742..3b74b0c1 100644
--- a/src/java/nxt_jni_InputStream.c
+++ b/src/java/nxt_jni_InputStream.c
@@ -90,40 +90,20 @@ static jint JNICALL
nxt_java_InputStream_readLine(JNIEnv *env, jclass cls,
jlong req_info_ptr, jarray out, jint off, jint len)
{
- char *p;
- jint size, b_size;
uint8_t *data;
ssize_t res;
- nxt_unit_buf_t *b;
nxt_unit_request_info_t *req;
req = nxt_jlong2ptr(req_info_ptr);
- 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;
- }
+ data = (*env)->GetPrimitiveArrayCritical(env, out, NULL);
- size += b_size;
+ res = nxt_unit_request_readline_size(req, len);
- if (size >= len) {
- break;
- }
+ if (res > 0) {
+ res = nxt_unit_request_read(req, data + off, res);
}
- len = len < size ? len : size;
-
- data = (*env)->GetPrimitiveArrayCritical(env, out, NULL);
-
- res = nxt_unit_request_read(req, data + off, len);
-
nxt_unit_req_debug(req, "readLine '%.*s'", res, (char *) data + off);
(*env)->ReleasePrimitiveArrayCritical(env, out, data, 0);