From 245bc9c437e8e66a012733eedf37101a47ee9ca7 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Wed, 31 Aug 2022 00:19:23 +0200 Subject: Try to connect to another backend app Signed-off-by: Alejandro Colomar --- src/nxt_unit_app_test.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 3 deletions(-) diff --git a/src/nxt_unit_app_test.c b/src/nxt_unit_app_test.c index 1aeca62..51df731 100644 --- a/src/nxt_unit_app_test.c +++ b/src/nxt_unit_app_test.c @@ -5,10 +5,15 @@ #include #include +#include //#include #include #include +#include #include +#include +#include +#include #define nxt_expect(c, x) __builtin_expect((long) (x), (c)) @@ -157,11 +162,57 @@ greeting_app_request_handler(nxt_unit_request_info_t *req) nxt_unit_field_t *f; nxt_unit_request_t *r; + int sfd; + ssize_t rd, wr; + struct sockaddr_un sun; + char buff[14]; + + rc = NXT_UNIT_ERROR; + + warnx("ALX: socket()"); + sfd = socket(AF_UNIX, SOCK_STREAM, 0); + if (nxt_slow_path(sfd == -1)) { + warn("ALX: fail"); + goto fail; + } + + sun.sun_family = AF_UNIX; + warnx("ALX: memset()"); + memcpy(sun.sun_path, "\0back", 6); + warnx("ALX: connect()"); + if (nxt_slow_path(connect(sfd, (struct sockaddr *)&sun, + offsetof(struct sockaddr_un, sun_path) + 5))) + { + warn("ALX: fail"); + goto fail; + } + char get[] = "GET / HTTP/1.0\n\n"; + fprintf(stderr, "ALX: write(): "); + wr = write(sfd, get, sizeof(get)); + fprintf(stderr, "%zd(%zu)\n", wr, sizeof(get)); + if (nxt_slow_path(wr != sizeof(get))) { + warn("ALX: fail"); + goto fail; + } + fprintf(stderr, "ALX: read(): "); + rd = read(sfd, buff, 12); + fprintf(stderr, "%zd\n", rd); + if (nxt_slow_path(rd < 12)) { + warn("ALX: fail"); + goto fail; + } + warnx("ALX: close()"); + if (nxt_slow_path(close(sfd) == -1)) { + warn("ALX: fail"); + goto fail; + } + warn("ALX:"); + rc = nxt_unit_response_init(req, 200 /* Status code. */, 1 /* Number of response headers. */, nxt_length(CONTENT_TYPE) + nxt_length(TEXT_PLAIN) - + nxt_length(HELLO_WORLD)); + + nxt_length(buff)); if (nxt_slow_path(rc != NXT_UNIT_OK)) { goto fail; } @@ -173,8 +224,8 @@ greeting_app_request_handler(nxt_unit_request_info_t *req) goto fail; } - rc = nxt_unit_response_add_content(req, HELLO_WORLD, - nxt_length(HELLO_WORLD)); + rc = nxt_unit_response_add_content(req, buff, + nxt_length(buff)); if (nxt_slow_path(rc != NXT_UNIT_OK)) { goto fail; } -- cgit v1.2.3