PengZheng commented on code in PR #851:
URL: https://github.com/apache/celix/pull/851#discussion_r4119039993


##########
bundles/shell/remote_shell/src/remote_shell.c:
##########
@@ -175,24 +175,32 @@ void *remoteShell_connection_run(void *data) {
                        char buff[COMMAND_BUFF_SIZE];
 
                        len = recv(fd, buff, COMMAND_BUFF_SIZE - 1, 0);
-                       if (len < COMMAND_BUFF_SIZE) {
-                               celix_status_t commandStatus = CELIX_SUCCESS;
-                               buff[len] = '\0';
-
-                               commandStatus = 
remoteShell_connection_execute(connection, buff);
-
-                               if (commandStatus == CELIX_SUCCESS) {
-                                       
remoteShell_connection_print(connection, RS_PROMPT);
-                               } else if (commandStatus == 
CELIX_FILE_IO_EXCEPTION) {
-                                       //exit command
-                                       break;
-                               } else { //error
-                                       
remoteShell_connection_print(connection, RS_ERROR);
-                                       
remoteShell_connection_print(connection, RS_PROMPT);
+                       if (len > 0) {
+                               if (len < COMMAND_BUFF_SIZE) {

Review Comment:
   Strictly speaking, we cannot assume a single TCP read returns the whole 
request body. This remark also applies to 
https://github.com/apache/celix/blob/0789aaa184b7b829e156ff5e2918abd48170623f/bundles/remote_services/remote_service_admin_dfi/src/remote_service_admin_dfi.c#L529-L532
   
   The correct way is illustrated by the following [official 
example](https://github.com/civetweb/civetweb/blob/master/docs/api/mg_read.md)
   
   ```C++
   #define RECV_BUF_SIZE 1 << 20
   
   size_t read_data(struct mg_connection* conn,
                           uint8_t* buff,
                           size_t buff_len) {
     size_t read_len = 0;
     while (read_len < buff_len) {
       size_t sz_to_read = std::min<size_t>(RECV_BUF_SIZE, buff_len - read_len);
       int this_read = mg_read(conn, buff + read_len, sz_to_read);
       if (this_read < 0) {
         std::cerr << "[error] Failed to read data" << std::endl;
         break;
       } else {
         read_len += size_t(this_read);
         if (this_read > 0) {
           std::cout << "[debug] Received " << this_read << " more bytes" << 
std::endl;
         }
       }
     }
   
     return read_len;
   }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to