Commit 29df9adc authored by Vincent Wei's avatar Vincent Wei
Browse files

launch UnixSocket client

parent 94e3c223
......@@ -11,7 +11,7 @@ but the MiniGUI app is running in your IoT device actually.
1. A webpage connects to the Server via a URI like this:
ws://<domain.nam>:7777/<display-client-name>?width=<horizontal-resolution-in-pixel>&height=<vertical-resolution-in-pixel>
ws://<domain.nam>:7788/<display-client-name>
2. A local display client specified by the URI will be forked and executed
by the Server.
......
......@@ -144,7 +144,7 @@ static struct _demo_info {
{"cbplusui", "/usr/local/bin/cbplusui", "240x240-16bpp"},
};
pid_t us_launch_client (const char* demo_name, const char* video_mode)
pid_t us_launch_client (const char* demo_name)
{
int i, found = -1;
pid_t pid = 0;
......@@ -161,14 +161,12 @@ pid_t us_launch_client (const char* demo_name, const char* video_mode)
}
if ((pid = vfork ()) > 0) {
ACCESS_LOG (("fork child for %s of %s\n", demo_name, video_mode));
ACCESS_LOG (("fork child for %s\n", demo_name));
}
else if (pid == 0) {
char env_mode [32];
if (video_mode == NULL)
video_mode = _demo_list[found].def_mode;
strcpy (env_mode, "MG_DEFAULTMODE=");
strcat (env_mode, video_mode);
strcat (env_mode, _demo_list[found].def_mode);
char *const argv[] = {_demo_list[found].demo_name, NULL};
char *const envp[] = {"MG_GAL_ENGINE=commlcd", "MG_IAL_ENGINE=common", env_mode, NULL};
......
/**
* _______ _______ __ __
* / ____/ | / / ___/____ _____/ /_____ / /_
* / / __ | | /| / /\__ \/ __ \/ ___/ //_/ _ \/ __/
* / /_/ / | |/ |/ /___/ / /_/ / /__/ ,< / __/ /_
* \____/ |__/|__//____/\____/\___/_/|_|\___/\__/
*
* unixsocket.h: Utilities for UnixSocket server.
*
* Copyright (c) 2018 FMSoft
* Author: Vincent Wei (https://github.com/VincentWei)
......@@ -58,7 +53,7 @@ typedef struct USClient_
int us_listen (const char* name);
int us_accept (int listenfd, pid_t *pidptr, uid_t *uidptr);
pid_t us_launch_client (const char* demo_name, const char* video_mode);
pid_t us_launch_client (const char* demo_name);
int us_on_connected (USClient* us_client, const char* video_mode);
int us_ping_client (const USClient* us_client);
int us_on_client_data (USClient* us_client);
......
......@@ -73,7 +73,7 @@ static struct option long_opts[] = {
static void
cmd_help (void)
{
printf ("\nWDServer - %s\n\n", GW_VERSION);
printf ("\nWDServer - %s\n\n", WD_VERSION);
printf (
"Usage: "
......@@ -151,6 +151,11 @@ setup_signals (void)
static int
onopen (WSClient * client)
{
pid_t pid_usc;
pid_usc = us_launch_client (client->headers->path + 1);
printf ("INFO: Got a request from client (%d) %s and fork a child %d\n", client->listener, client->headers->path, pid_usc);
return 0;
}
......@@ -164,6 +169,9 @@ static int
onmessage (WSClient * client)
{
WSMessage **msg = &client->message;
printf ("INFO: got a message from client (%d): %s\n", client->listener, (*msg)->payload);
uint32_t hsize = sizeof (uint32_t) * 3;
char *hdr = NULL, *ptr = NULL;
......@@ -288,7 +296,7 @@ read_option_args (int argc, char **argv)
cmd_help ();
return 1;
case 'V':
fprintf (stdout, "GWSocket %s\n", GW_VERSION);
fprintf (stdout, "WDSocket %s\n", WD_VERSION);
return 1;
case 0:
parse_long_opt (long_opts[idx].name, optarg);
......@@ -323,7 +331,7 @@ set_self_pipe (void)
int
main (int argc, char **argv)
{
if ((server = ws_init ("0.0.0.0", "7890")) == NULL) {
if ((server = ws_init ("0.0.0.0", "7788")) == NULL) {
perror ("Error during ws_init.\n");
exit (EXIT_FAILURE);
}
......
......@@ -28,7 +28,7 @@
#ifndef WD_SERVER_H_INCLUDED
#define WD_SERVER_H_INCLUDED
#define GW_VERSION "0.8"
#define WD_VERSION "0.8"
/* The pixel format */
#define COMMLCD_TRUE_RGB565 3
......
......@@ -2814,7 +2814,7 @@ set_rfds_wfds (int ws_listener, int us_listener, WSServer * server)
/* WebSocket server socket, ready for accept() */
FD_SET (ws_listener, &fdstate.rfds);
/* UNIX server socket, ready for accept() */
/* UnixSocket server socket, ready for accept() */
FD_SET (us_listener, &fdstate.rfds);
while (client_node) {
......@@ -2962,7 +2962,7 @@ check_rfds_wfds (int ws_listener, int us_listener, WSServer * server)
/* handle new WebSocket connections */
if (FD_ISSET (ws_listener, &fdstate.rfds))
handle_accept (ws_listener, server);
/* handle new UNIX socket connections */
/* handle new UnixSocket connections */
else if (FD_ISSET (us_listener, &fdstate.rfds))
handle_us_accept (us_listener, server);
......@@ -2972,20 +2972,20 @@ check_rfds_wfds (int ws_listener, int us_listener, WSServer * server)
client = (WSClient*)(client_node->data);
ws_fd = client->listener;
/* handle reading data from a client */
/* handle reading data from a WebSocket client */
if (FD_ISSET (ws_fd, &fdstate.rfds))
handle_reads (ws_fd, server);
/* handle sending data to a client */
/* handle sending data to a WebSocket client */
else if (FD_ISSET (ws_fd, &fdstate.wfds))
handle_writes (ws_fd, server);
if (client->us_buddy) {
us_fd = client->us_buddy->fd;
/* handle reading data from a UNIX client */
/* handle reading data from a UnixSocket client */
if (FD_ISSET (us_fd, &fdstate.rfds))
handle_us_reads (us_fd, server);
/* handle sending data to a UNIX client */
/* handle sending data to a UnixSocket client */
else if (FD_ISSET (us_fd, &fdstate.wfds))
handle_us_writes (us_fd, server);
}
......@@ -3035,6 +3035,7 @@ ws_start (WSServer * server)
}
}
check_rfds_wfds (ws_listener, us_listener, server);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment