]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-program-client: test-program-client-net: Read the client input stream to EOF...
authorStephan Bosch <stephan.bosch@dovecot.fi>
Sun, 25 Feb 2018 16:31:51 +0000 (17:31 +0100)
committerAki Tuomi <aki.tuomi@dovecot.fi>
Sun, 18 Mar 2018 10:53:18 +0000 (12:53 +0200)
The low-level file stream is not necessarily read to EOF when the body dot
stream sees EOF.

src/lib-program-client/test-program-client-net.c

index c7a6abcdf3ada80ad58f806ded1c8f74d926a970..cdc36789022bdb92959486e28238074c4e2d7664 100644 (file)
@@ -57,7 +57,8 @@ struct test_client {
                CLIENT_STATE_INIT,
                CLIENT_STATE_VERSION,
                CLIENT_STATE_ARGS,
-               CLIENT_STATE_BODY
+               CLIENT_STATE_BODY,
+               CLIENT_STATE_FINISH
        } state;
 };
 
@@ -147,11 +148,16 @@ test_program_input_handle(struct test_client *client, const char *line)
                        client->body =
                                iostream_temp_finish(&client->os_body, -1);
                        i_stream_unref(&client->is_body);
-                       return 1;
+                       client->state = CLIENT_STATE_FINISH;
+                       return 0;
                case OSTREAM_SEND_ISTREAM_RESULT_WAIT_OUTPUT:
                        i_panic("Cannot write to ostream-temp");
                }
                break;
+       case CLIENT_STATE_FINISH:
+               if (i_stream_read_eof(client->in))
+                       return 1;
+               break;
        }
        return 0;
 }
@@ -197,11 +203,11 @@ static void test_program_input(struct test_client *client)
        int ret = 0;
 
        while (ret >= 0) {
-               if (client->state == CLIENT_STATE_BODY) {
+               if (client->state >= CLIENT_STATE_BODY) {
                        ret = test_program_input_handle(client, NULL);
                        break;
                }
-               while (client->state != CLIENT_STATE_BODY) {
+               while (client->state < CLIENT_STATE_BODY) {
                        line = i_stream_read_next_line(client->in);
                        if (line == NULL) {
                                ret = 0;
@@ -221,7 +227,7 @@ static void test_program_input(struct test_client *client)
        if (!client->in->eof)
                return;
 
-       if (client->state != CLIENT_STATE_BODY)
+       if (client->state < CLIENT_STATE_FINISH)
                i_warning("Client prematurely disconnected");
 
        io_remove(&client->io);