]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-program-client: test-program-client-net: Match client input handling code with...
authorStephan Bosch <stephan.bosch@dovecot.fi>
Sun, 25 Feb 2018 17:15:59 +0000 (18:15 +0100)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Tue, 25 Jun 2019 09:22:30 +0000 (12:22 +0300)
src/lib-program-client/test-program-client-net.c

index f6cc468897c1bbaa8826d4b42a44003795f318cc..265f6beabb1650552dd2e603897367c211521c2e 100644 (file)
@@ -134,7 +134,11 @@ test_program_input_handle(struct test_client *client, const char *line)
 
                switch(o_stream_send_istream(client->os_body, client->in)) {
                case OSTREAM_SEND_ISTREAM_RESULT_ERROR_OUTPUT:
+                       i_panic("Cannot write to ostream-temp: %s",
+                               o_stream_get_error(client->os_body));
                case OSTREAM_SEND_ISTREAM_RESULT_ERROR_INPUT:
+                       i_warning("Client stream error: %s",
+                               i_stream_get_error(client->in));
                        return -1;
                case OSTREAM_SEND_ISTREAM_RESULT_WAIT_INPUT:
                        break;
@@ -190,34 +194,36 @@ static void test_program_input(struct test_client *client)
        const char *line = "";
        int ret = 0;
 
-       if (client->state == CLIENT_STATE_BODY) {
-               if (test_program_input_handle(client, NULL)==0 &&
-                   !client->in->eof)
-                       return;
-       } else {
-               while((line = i_stream_read_next_line(client->in)) != NULL) {
-                       ret = test_program_input_handle(client, line);
-                       if (client->state == CLIENT_STATE_BODY)
-                               ret = test_program_input_handle(client, NULL);
-                       if (ret != 0) break;
+       while (ret >= 0) {
+               if (client->state == CLIENT_STATE_BODY) {
+                       ret = test_program_input_handle(client, NULL);
+                       break;
+               }
+               while (client->state != CLIENT_STATE_BODY) {
+                       line = i_stream_read_next_line(client->in);
+                       if (line == NULL) {
+                               ret = 0;
+                               break;
+                       }
+                       if ((ret=test_program_input_handle(client, line)) < 0) {
+                               i_warning("Client sent invalid line: %s", line);
+                               break;
+                       }
                }
-
-               if ((line == NULL && !client->in->eof) ||
-                   (line != NULL && ret == 0))
-                       return;
        }
 
-       /* incur short delay to make sure the client did not disconnect
-          prematurely */
+       if (ret < 0 || client->in->stream_errno != 0)
+               return;
+       if (!client->in->eof)
+               return;
+
+       if (client->state != CLIENT_STATE_BODY)
+               i_warning("Client prematurely disconnected");
+
        io_remove(&client->io);
+       /* incur slight delay to check if the connection gets
+          prematurely closed */
        test_globals.to = timeout_add_short(100, test_program_run, client);
-
-       if (client->state != CLIENT_STATE_BODY) {
-               if (client->in->eof)
-                       i_warning("Client prematurely disconnected");
-               else
-                       i_warning("Client sent invalid line: %s", line);
-       }
 }
 
 static void test_program_connected(struct test_server *server)