]> rtime.felk.cvut.cz Git - pes-rpp/rpp-test-sw.git/commitdiff
Fix echoserver's foreground mode
authorMartin Vajnar <martin.vajnar@gmail.com>
Thu, 30 Jul 2015 11:54:58 +0000 (13:54 +0200)
committerMartin Vajnar <martin.vajnar@gmail.com>
Thu, 30 Jul 2015 11:54:58 +0000 (13:54 +0200)
es_logic() requires pointer to valid thread_context, but the pointer was
only assigned properly when running echoserver as a background thread.

Now the pointer is assigned in both cases, that is for running in
background and foreground.

rpp-test-sw/commands/cmd_echoserver.c

index 635249c9004aca72290987e730a948d89b40180c..054f12130695cb3ff31e1e0ed9657376a8ee7e76 100644 (file)
@@ -210,7 +210,7 @@ int cmd_do_init_es(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
        err_t err = ERR_OK;
        uint8_t pindex;
        int thread_nr;
-       int command = 0;
+       int command = ES_COMMAND_RUN_FOREGROUND;
        unsigned int port_no = 0;
        int i;
 
@@ -222,19 +222,19 @@ int cmd_do_init_es(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
        /* Parse the "command line" arguments */
        for (pindex = 1; param[pindex] != 0; pindex++) {
                if (strncmp(param[pindex], "-c", 3) == 0) {
-                       if (command) {
+                       if (command != ES_COMMAND_RUN_FOREGROUND) {
                                rpp_sci_printf("More than single command are used\n");
                                return FAILURE;
                        }
                        command = ES_COMMAND_KILL_ALL_THREADS;
                } else if (strncmp(param[pindex], "-l", 3) == 0) {
-                       if (command) {
+                       if (command != ES_COMMAND_RUN_FOREGROUND) {
                                rpp_sci_printf("More than single command are used\n");
                                return FAILURE;
                        }
                        command = ES_COMMAND_LIST_THREADS;
                } else if (strncmp(param[pindex], "-t", 3) == 0) {
-                       if (command) {
+                       if (command != ES_COMMAND_RUN_FOREGROUND) {
                                rpp_sci_printf("More than single command are used\n");
                                return FAILURE;
                        }
@@ -249,14 +249,14 @@ int cmd_do_init_es(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
        }
 
        /* Port number is mandatory for interactive or background-thread mode */
-       if ((!command || command == ES_COMMAND_NEW_THREAD) && !port_no)
+       if (command == ES_COMMAND_RUN_FOREGROUND || command == ES_COMMAND_NEW_THREAD)
        {
-               rpp_sci_printf("Port number not set\n");
-               return FAILURE;
-       }
+               if (!port_no)
+               {
+                       rpp_sci_printf("Port number not set\n");
+                       return FAILURE;
+               }
 
-       /* Execute the particular command */
-       if (command == ES_COMMAND_NEW_THREAD) {
                /* Is there any free preallocated thread handle? */
                thread_nr = es_thread_handle_find_first_free();
                if (thread_nr < 0) {
@@ -266,7 +266,10 @@ int cmd_do_init_es(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
                }
                thread_context = &es_threads[thread_nr];
                thread_context->port_no = port_no;
+       }
 
+       /* Execute the particular command */
+       if (command == ES_COMMAND_NEW_THREAD) {
                unsigned int thread_nr_tmp;
                thread_nr_tmp = (thread_nr % 100);
                thread_name[2] = (thread_nr_tmp/10) + '0';