Skip to content
Snippets Groups Projects
Commit 9b5420ed authored by Roman Khlopkov's avatar Roman Khlopkov 🔜
Browse files

[*] Proc threads involved on CLI command execution

parent 5410384d
No related branches found
No related tags found
No related merge requests found
Pipeline #32955 passed with stage
in 17 minutes and 28 seconds
......@@ -23,46 +23,20 @@
along with any Cellframe SDK based project. If not, see <http://www.gnu.org/licenses/>.
*/
#include <sys/stat.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <assert.h>
//#include <glib.h>
#include <unistd.h>
#ifndef _WIN32
#include <poll.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <arpa/inet.h>
//#include <unistd.h> // for close
#include <fcntl.h>
//#include <sys/poll.h>
//#include <sys/select.h>
#include <netinet/in.h>
#include <sys/un.h>
#include <sys/stat.h>
//#define closesocket close
//typedef int SOCKET;
//#define SOCKET_ERROR -1 // for win32 = (-1)
//#define INVALID_SOCKET -1 // for win32 = (SOCKET)(~0)
// for Windows
#else
#include <winsock2.h>
#include <windows.h>
#include <mswsock.h>
#include <ws2tcpip.h>
#include <io.h>
#endif
#include <pthread.h>
#include "dap_common.h"
#include "dap_strfuncs.h"
#include "dap_file_utils.h"
#include "dap_list.h"
#include "dap_net.h"
#include "dap_cli_server.h"
#include "dap_proc_thread.h"
#define LOG_TAG "dap_cli_server"
......@@ -79,8 +53,6 @@ static bool s_debug_cli = false;
static dap_cli_cmd_t * s_commands = NULL;
static dap_cli_cmd_aliases_t * s_command_alias = NULL;
static void* s_thread_one_client_func(void *args);
static void* s_thread_main_func(void *args);
static inline void s_cmd_add_ex(const char * a_name, dap_cli_server_cmd_callback_ex_t a_func, void *a_arg_func, const char *a_doc, const char *a_doc_ex);
......@@ -726,9 +698,9 @@ char* s_get_next_str( SOCKET nSocket, int *dwLen, const char *stop_str, bool del
/**
* threading function for processing a request from a client
*/
static void* s_thread_one_client_func(void *args)
static bool s_thread_one_client_func(dap_proc_thread_t UNUSED_ARG *a_thread, void *arg)
{
SOCKET newsockfd = (SOCKET) (intptr_t) args;
SOCKET newsockfd = (SOCKET) (intptr_t) arg;
int str_len, marker = 0, timeout = 5000, argc = 0, is_data;
dap_list_t *cmd_param_list = NULL;
char *str_header;
......@@ -857,7 +829,7 @@ char *str_header;
if (s_debug_cli)
log_it(L_DEBUG, "close connection=%d sockfd=%"DAP_FORMAT_SOCKET, cs, newsockfd);
return NULL;
return false;
}
/**
......@@ -875,7 +847,6 @@ static void* s_thread_main_func(void *args)
// wait of clients
while(1)
{
pthread_t threadId;
struct sockaddr_in peer;
socklen_t size = sizeof(peer);
// received a new connection request
......@@ -883,10 +854,8 @@ static void* s_thread_main_func(void *args)
log_it(L_ERROR, "new connection break newsockfd=%"DAP_FORMAT_SOCKET, newsockfd);
break;
}
// create child thread for a client connection
pthread_create(&threadId, NULL, s_thread_one_client_func, (void*) (intptr_t) newsockfd);
// in order to thread not remain in state "dead" after completion
pthread_detach(threadId);
// Serve client connection on automatically chosen processing thread
dap_proc_thread_callback_add(NULL, s_thread_one_client_func, DAP_INT_TO_POINTER(newsockfd));
};
// close connection
int cs = closesocket(sockfd);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment