From 275227400fc84a1070c8f642c2752e2858dea271 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Sun, 20 Feb 2022 12:35:10 +0100 Subject: [PATCH] Wait for chunked stream WIP [CI SKIP] --- src/build.v | 1 + src/docker/docker.v | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/build.v b/src/build.v index 304aaf2..f3834fd 100644 --- a/src/build.v +++ b/src/build.v @@ -4,4 +4,5 @@ import docker fn build() { println(docker.pull('archlinux', 'latest') or { panic('yeetus') }) + // println(docker.containers() or { panic('heet') }) } diff --git a/src/docker/docker.v b/src/docker/docker.v index 7f5c854..0fcb058 100644 --- a/src/docker/docker.v +++ b/src/docker/docker.v @@ -23,23 +23,27 @@ fn send(req &string) ?http.Response { // Write the request to the socket s.write_string(req) ? - // Wait for the server to respond - s.wait_for_write() ? - mut buf := []byte{len: docker.buf_len} mut res := []byte{} mut c := 0 - for { - c = s.read(mut buf) or { return error('Failed to read data from socket.') } - res << buf[..c] + for res.len < 5 && res#[-4..] != [0, '\r', `\n`, `\r`, `\n`] { + // Wait for the server to respond + s.wait_for_write() ? - if c < docker.buf_len { - break + for { + c = s.read(mut buf) or { return error('Failed to read data from socket.') } + res << buf[..c] + + if c < docker.buf_len { + break + } } } + println(res) + // Decode chunked response return http.parse_response(res.bytestr())