summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlejandro Colomar <alx@kernel.org>2023-05-20 17:43:46 +0200
committerAlejandro Colomar <alx@kernel.org>2023-05-20 17:43:56 +0200
commitc3b6231eca2f7ff9ddf2758922953ef2e97947e1 (patch)
tree3bf9df5be0540e8b8aa37269380992f974aa26b4
parent409cf6a6dccf188c4867cce72b81b4778f660302 (diff)
nxt_unit_app_test.c: Test having several buffers, and sending them in reverse creation order
Suggested-by: Andrei Vasiliu <whyte.vuhuni@gmail.com> Link: <https://github.com/nginx/unit/issues/738> Signed-off-by: Alejandro Colomar <alx@kernel.org>
-rw-r--r--src/nxt_unit_app_test.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/src/nxt_unit_app_test.c b/src/nxt_unit_app_test.c
index c1bbef4..f595419 100644
--- a/src/nxt_unit_app_test.c
+++ b/src/nxt_unit_app_test.c
@@ -3,6 +3,7 @@
* Copyright (C) NGINX, Inc.
*/
+#define _GNU_SOURCE
#include <nxt_unit.h>
#include <nxt_unit_request.h>
//#include <nxt_clang.h>
@@ -153,7 +154,7 @@ greeting_app_request_handler(nxt_unit_request_info_t *req)
char *p;
ssize_t res;
uint32_t i;
- nxt_unit_buf_t *buf;
+ nxt_unit_buf_t *buf, *buf2;
nxt_unit_field_t *f;
nxt_unit_request_t *r;
@@ -271,6 +272,35 @@ greeting_app_request_handler(nxt_unit_request_info_t *req)
buf->free = p;
rc = nxt_unit_buf_send(buf);
+ if (nxt_slow_path(rc != NXT_UNIT_OK)) {
+ goto fail;
+ }
+
+ buf = nxt_unit_response_buf_alloc(req, strlen("foo"));
+ if (nxt_slow_path(buf == NULL)) {
+ rc = NXT_UNIT_ERROR;
+ goto fail;
+ }
+
+ buf->free = mempcpy(buf->free, "foo", strlen("foo"));
+
+ buf2 = nxt_unit_response_buf_alloc(req, strlen("barbaz"));
+ if (nxt_slow_path(buf2 == NULL)) {
+ rc = NXT_UNIT_ERROR;
+ goto fail;
+ }
+
+ buf2->free = mempcpy(buf2->free, "barbaz", strlen("barbaz"));
+
+ rc = nxt_unit_buf_send(buf2);
+ if (nxt_slow_path(rc != NXT_UNIT_OK)) {
+ goto fail;
+ }
+
+ rc = nxt_unit_buf_send(buf);
+ if (nxt_slow_path(rc != NXT_UNIT_OK)) {
+ goto fail;
+ }
fail: