Re: [PATCH v6 04/12] test-http-server: add stub HTTP server test helper
- From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
- Date
- Jan 18, 2023, 11:04 UTC
- Message-ID
- <230118.86k01kxfr7.gmgdl@evledraar.gmail.com>
- In-Reply-To
- <d6e5e8825e8454242820738f0dfb03a9f1c01ced.1674012618.git.gitgitgadget@gmail.com>
On Wed, Jan 18 2023, Matthew John Cheetham via GitGitGadget wrote:
Show 31 quoted lines
> From: Matthew John Cheetham <mjcheetham@outlook.com>
> [...]
> +enum worker_result {
> + /*
> + * Operation successful.
> + * Caller *might* keep the socket open and allow keep-alive.
> + */
> + WR_OK = 0,
> [...]
> + enum worker_result wr = WR_OK;
> +
> + if (client_addr)
> + loginfo("Connection from %s:%s", client_addr, client_port);
> +
> + set_keep_alive(0, logerror);
> +
> + while (1) {
> + if (write_in_full(STDOUT_FILENO, response, strlen(response)) < 0) {
> + logerror("unable to write response");
> + wr = WR_IO_ERROR;
> + }
> +
> + if (wr != WR_OK)
> + break;
> + }
> +
> + close(STDIN_FILENO);
> + close(STDOUT_FILENO);
> +
> + return !!(wr & WR_IO_ERROR);
> +}We have cases where we assign "0" to a bitfield-looking structure like this, but only in cases where we're planning to use it as a boolean too.
Or, in other cases where we want some to be explicitly <-1.
Here though we're adding a mixed "OK" and error use, which seems a bit odd. Shouldn't we pick one or the other?
So far (maybe in later commits?) nothing uses WR_HANGUP, and oddly we also use the bitfield-looking thing as a return value from main()....