src/monitor/monitor-thread.c
src/monitor/monitor-command.c
src/monitor/request-server.c
+ src/monitor/request-handler-thread.c
)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
--- /dev/null
+/*
+ * PASS (Power Aware System Service)
+ *
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __REQUEST_HANDLER_H__
+#define __REQUEST_HANDLER_H__
+
+static const char *request_type_str[] = {
+ "REQUEST_INIT",
+ "REQUEST_EXIT",
+ "REQUEST_SET_ATTRS",
+ "REQUEST_GET_AVAILABLE_ATTRS",
+ "REQUEST_START",
+ "REQUEST_STOP",
+ "REQUEST_UPDATE",
+ "REQUEST_GET_VALUE_INT",
+ "REQUEST_GET_RESOURCE_NUM",
+ "REQUEST_TYPE",
+};
+
+/*
+ * states of client
+ */
+enum {
+ CLIENT_DISCONNECTED,
+ CLIENT_CONNECTED,
+ CLIENT_RUNNING,
+ CLIENT_STOPPED,
+ CLIENT_FINALIZED,
+};
+
+struct request_resource {
+ int resource_type;
+ u_int64_t attr_mask;
+};
+
+#define RESOURCE_MAX 10 /* temperary value */
+
+struct request_client {
+ int id; // unique identifier
+ int state; // one of three states (DISCONNECTED, CONNECTED, RUNNING)
+ int socket_fd; // socket
+ int period; // period in millisecond (0 means one-shot)
+ int nr_resources;
+ struct thread *worker;
+ int worker_running;
+ GList *g_request_resource_head;
+ struct resource *res[RESOURCE_MAX];
+};
+
+#define REQUEST_BUFFER_MAX 1000
+#define REQUEST_TOKEN_MAX 10
+
+static inline int buffer_tokenize(char *buffer, char *tokens[])
+{
+ int i = 0;
+ char *tok;
+
+ tok = strtok(buffer, ":");
+ while (tok) {
+ tokens[i++] = tok;
+ tok = strtok(NULL, ":");
+ if (i > REQUEST_TOKEN_MAX)
+ return -1;
+ }
+ return i;
+}
+
+void request_handler_setup(struct request_client *client);
+
+#endif /* __REQUEST_HANDLER_H__ */
--- /dev/null
+/*
+ * PASS (Power Aware System Service)
+ *
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file request-handler-thread.c
+ * @brief TBD
+ * @ingroup TBD
+ */
+
+#include <glib.h>
+
+#include <util/common.h>
+#include <util/log.h>
+#include <util/resource.h>
+#include <util/thread.h>
+#include <util/device-notifier.h>
+#include <util/devices.h>
+#include <util/request.h>
+#include <util/request-handler.h>
+
+#include <string.h>
+#include <arpa/inet.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <sys/time.h>
+#include <assert.h>
+
+static void remove_resource_from_list(struct request_resource *resource, GList **list)
+{
+ if (!resource || !list)
+ return;
+
+ *list = g_list_remove(*list, (gpointer)resource);
+}
+
+static void release_resource_list(GList **resource_head)
+{
+ struct request_resource *resource;
+ GList *node;
+ GList *next;
+
+ node = *resource_head;
+ while (node != NULL) {
+ next = node->next;
+ resource = node->data;
+ remove_resource_from_list(resource, resource_head);
+ free(resource);
+ node = next;
+ }
+}
+
+static void handle_request_in_stopped(struct request_client *client, char *buffer)
+{
+ char response[10];
+ int response_len;
+ int nr_tokens;
+ char *tokens[REQUEST_TOKEN_MAX];
+ int request_type;
+ int i;
+ int id;
+
+ nr_tokens = buffer_tokenize(buffer, tokens);
+ if (nr_tokens < 0) {
+ _E("error occurred while tokenizing");
+ return;
+ }
+
+ request_type = atoi(tokens[0]);
+ id = atoi(tokens[1]);
+
+ /* expect start, set_attrs, exit calls */
+ if (request_type != REQUEST_START && request_type != REQUEST_SET_ATTRS
+ && request_type != REQUEST_EXIT) {
+ _E("client-%d: state: %d Invalid request type: %s client-%d",
+ client->id, client->state,
+ request_type_str[request_type], client->id);
+ return;
+ }
+
+ if (client->id != id) {
+ _E("client-%d: state: %d invalid client id incoming id: %d",
+ client->id, client->state, id);
+ return;
+ }
+
+ _I("client-%d state: %d request_type: %s",
+ client->id, client->state, request_type_str[request_type]);
+
+ switch (request_type) {
+ case REQUEST_EXIT:
+ /**
+ * Format of REQUEST_EXIT:
+ * - <REQUEST_TYPE:ID>
+ */
+ if (client->g_request_resource_head) {
+ _I("client-%d: before release resource list", client->id);
+ release_resource_list(&client->g_request_resource_head);
+ _I("client-%d: release resource list", client->id);
+ }
+
+ for (i = 0; i < client->nr_resources; i++)
+ free(client->res[i]);
+
+ client->state = CLIENT_FINALIZED;
+ break;
+ }
+
+ /**
+ * Format of response
+ * - <REQUEST_TYPE:ID>
+ */
+ response_len = sprintf(response, "%d:%d", request_type, client->id);
+ if (send(client->socket_fd, response, response_len, 0) < 0) {
+ _E("failed to send respones, error: %s", strerror(errno));
+ return;
+ }
+
+ _I("send response \"%s\" to client-%d", response, client->id);
+
+}
+
+static struct resource *find_resource_by_type(struct request_client *client, int resource_type)
+{
+ int i;
+ struct resource *res;
+
+ if (!client)
+ return NULL;
+
+ for (i = 0; i < client->nr_resources; i++) {
+ res = client->res[i];
+ if (res->type == resource_type)
+ return res;
+ }
+ return NULL;
+}
+
+static void handle_request_update(struct request_client *client, int resource_type)
+{
+ char response[10];
+ int response_len;
+ struct resource *resource;
+
+ if (!client)
+ return;
+
+ resource = find_resource_by_type(client, resource_type);
+ if (!resource) {
+ _E("there is no resource for type (%d)", resource_type);
+ return;
+ }
+
+ update_resource_attrs(resource);
+
+ /**
+ * Format of response
+ * - <REQUEST_TYPE:ID>
+ */
+ response_len = sprintf(response, "%d:%d", REQUEST_UPDATE, client->id);
+ if (send(client->socket_fd, response, response_len, 0) < 0) {
+ _E("failed to send respones, error: %s", strerror(errno));
+ return;
+ }
+
+ _I("send response \"%s\" to client-%d", response, client->id);
+}
+
+static void handle_request_get_value_int(struct request_client *client,
+ int resource_type, u_int64_t attr)
+{
+ char response[100];
+ int response_len;
+ struct resource *resource;
+ int val;
+
+ resource = find_resource_by_type(client, resource_type);
+ if (!resource) {
+ _E("there is no resource for type (%d)", resource_type);
+ return;
+ }
+
+ get_resource_attr_integer(resource, attr, &val);
+ /**
+ * Format of response
+ * - <REQUEST_TYPE:ID>
+ */
+ response_len = sprintf(response, "%d:%d:%d", REQUEST_GET_VALUE_INT, client->id, val);
+ if (send(client->socket_fd, response, response_len, 0) < 0) {
+ _E("failed to send respones, error: %s", strerror(errno));
+ return;
+ }
+
+ _I("send response \"%s\" to client-%d", response, client->id);
+
+}
+
+static void handle_request_stop(struct request_client *client)
+{
+ int i;
+ char response[10];
+ int response_len;
+
+ client->state = CLIENT_STOPPED;
+ /**
+ * Format of response
+ * - <REQUEST_TYPE:ID>
+ */
+ response_len = sprintf(response, "%d:%d", REQUEST_STOP, client->id);
+ if (send(client->socket_fd, response, response_len, 0) < 0) {
+ _E("failed to send respones, error: %s", strerror(errno));
+ return;
+ }
+
+ _I("send response \"%s\" to client-%d", response, client->id);
+}
+
+static void handle_request_in_running(struct request_client *client, char *buffer)
+{
+ int nr_tokens;
+ char *tokens[REQUEST_TOKEN_MAX];
+ int request_type;
+ int id;
+ int resource_type;
+ u_int64_t attr;
+
+ nr_tokens = buffer_tokenize(buffer, tokens);
+ if (nr_tokens < 0) {
+ _E("error occurred while tokenizing");
+ return;
+ }
+
+ request_type = atoi(tokens[0]);
+ id = atoi(tokens[1]);
+
+ /* expect stop, update, get_value calls */
+ if (request_type != REQUEST_STOP && request_type != REQUEST_UPDATE &&
+ request_type != REQUEST_GET_VALUE_INT) {
+ _E("state: %d Invalid request type: %s client-%d", client->state,
+ request_type_str[request_type], client->id);
+ return;
+ }
+
+ if (client->id != id) {
+ _E("client-%d: state: %d invalid client id incoming id: %d",
+ client->id, client->state, id);
+ return;
+ }
+
+ _I("client-%d state: %d request_type: %s",
+ client->id, client->state, request_type_str[request_type]);
+
+ switch (request_type) {
+ case REQUEST_UPDATE:
+ /**
+ * Format of REQUEST_UPDATE:
+ * - <REQUEST_TYPE:ID:RESOURCE_TYPE>
+ */
+ resource_type = atoi(tokens[2]);
+ handle_request_update(client, resource_type);
+ break;
+ case REQUEST_GET_VALUE_INT:
+ /**
+ * Format of REQUEST_GET_VALUE_INT:
+ * - <REQUEST_TYPE:ID:RESOURCE_TYPE:ATTRS>
+ */
+ resource_type = atoi(tokens[2]);
+ attr = strtoul(tokens[3], NULL, 16);
+ handle_request_get_value_int(client, resource_type, attr);
+ break;
+ case REQUEST_STOP:
+ /**
+ * Format of REQUEST_STOP:
+ * - <REQUEST_TYPE:ID>
+ */
+ handle_request_stop(client);
+ break;
+ }
+}
+
+static void handle_request_in_thread(struct request_client *client, char *buffer)
+{
+ switch (client->state) {
+ case CLIENT_RUNNING:
+ handle_request_in_running(client, buffer);
+ break;
+ case CLIENT_STOPPED:
+ handle_request_in_stopped(client, buffer);
+ break;
+ }
+}
+
+static int request_handler_func(void *data, void **result)
+{
+ int recv_len;
+ fd_set read_fds;
+ fd_set active_fds;
+ char buffer[REQUEST_BUFFER_MAX];
+ struct timeval wait;
+ struct request_client *client = (struct request_client *)data;
+
+ FD_ZERO(&active_fds);
+ FD_SET(client->socket_fd, &active_fds);
+
+ _I("start worker thread for client-%d", client->id);
+
+ while (client->worker_running) {
+ read_fds = active_fds;
+ wait.tv_sec = 1;
+ wait.tv_usec = 0;
+
+ if (select(FD_SETSIZE, &read_fds, NULL, NULL, &wait) < 0) {
+ _E("select failed");
+ goto error_out;
+ }
+
+ if (FD_ISSET(client->socket_fd, &read_fds)) {
+ /* client submits request */
+ recv_len = recv(client->socket_fd, buffer, REQUEST_BUFFER_MAX, 0);
+ if (recv_len == 0) {
+ /* finalize client connection */
+ _I("client-%d state(%d) disconnected",
+ client->id, client->state);
+ close(client->socket_fd);
+ client->state = CLIENT_FINALIZED;
+ break;
+ } else {
+ buffer[recv_len] = '\0';
+ _I("incoming buffer: %s", buffer);
+ handle_request_in_thread(client, buffer);
+ }
+ }
+ }
+
+ return THREAD_RETURN_DONE;
+
+error_out:
+ client->state = CLIENT_FINALIZED;
+ return THREAD_RETURN_ERROR;
+}
+
+void request_handler_setup(struct request_client *client)
+{
+ int i;
+ GList *node;
+ struct request_resource *resource;
+
+ /* */
+ for (i = 0; i < RESOURCE_MAX; i++)
+ client->res[i] = NULL;
+
+ i = 0;
+ node = client->g_request_resource_head;
+ while (node != NULL) {
+ resource = node->data;
+ client->res[i] = create_resource(resource->resource_type, 0, NULL);
+ set_resource_attr_interest(client->res[i], resource->attr_mask);
+ node = node->next;
+ }
+ _I("fork worker thread for client-%d", client->id);
+
+ create_worker_thread(&client->worker, request_handler_func, client);
+ client->worker_running = 1;
+ resume_thread(client->worker);
+}
+
#include <util/device-notifier.h>
#include <util/devices.h>
#include <util/request.h>
+#include <util/request-handler.h>
#include <string.h>
#include <arpa/inet.h>
#include <assert.h>
#define PENDING_MAX 3
-#define REQUEST_MAX 1000
-
#define REQUEST_SERVER_PORT 10001
-#define REQUEST_TOKEN_MAX 10
-#define RESOURCE_MAX 10 /* temperary value */
-
-
static bool request_server_run;
-const char *request_type_str[] = {
- "REQUEST_INIT",
- "REQUEST_EXIT",
- "REQUEST_SET_ATTRS",
- "REQUEST_GET_AVAILABLE_ATTRS",
- "REQUEST_START",
- "REQUEST_STOP",
- "REQUEST_UPDATE",
- "REQUEST_GET_VALUE_INT",
- "REQUEST_GET_RESOURCE_NUM",
- "REQUEST_TYPE",
-};
-
-/*
- * states of client
- */
-enum {
- CLIENT_DISCONNECTED,
- CLIENT_CONNECTED,
- CLIENT_RUNNING,
- CLIENT_STOPPED,
- CLIENT_FINALIZED,
-};
-
-struct request_resource {
- int resource_type;
- u_int64_t attr_mask;
-};
-
-struct request_client {
- int id; // unique identifier
- int state; // one of three states (DISCONNECTED, CONNECTED, RUNNING)
- int socket_fd; // socket
- int period; // period in millisecond (0 means one-shot)
- int nr_resources;
- struct thread *worker;
- int worker_running;
- GList *g_request_resource_head;
- struct resource *res[RESOURCE_MAX];
-};
-
static GList *g_request_client_head;
static unsigned int client_id;
-static int buffer_tokenize(char *buffer, char *tokens[])
-{
- int i = 0;
- char *tok;
-
- tok = strtok(buffer, ":");
- while (tok) {
- tokens[i++] = tok;
- tok = strtok(NULL, ":");
- if (i > REQUEST_TOKEN_MAX)
- return -1;
- }
- return i;
-}
-
static void add_resource_to_list(struct request_resource *resource, GList **list)
{
if (!resource || !list)
*list = g_list_append(*list, (gpointer)resource);
}
-static void remove_resource_from_list(struct request_resource *resource, GList **list)
-{
- if (!resource || !list)
- return;
-
- *list = g_list_remove(*list, (gpointer)resource);
-}
-
static void add_resource_to_client(struct request_client *client, int resource_type, u_int64_t attr_mask)
{
struct request_resource *resource;
client->nr_resources++;
}
-static void release_resource_list(GList **resource_head)
-{
- struct request_resource *resource;
- GList *node;
- GList *next;
-
- node = *resource_head;
- while (node != NULL) {
- next = node->next;
- resource = node->data;
- remove_resource_from_list(resource, resource_head);
- free(resource);
- node = next;
- }
-}
-
-static void handle_request_in_stopped(struct request_client *client, char *buffer)
-{
- char response[10];
- int response_len;
- int nr_tokens;
- char *tokens[REQUEST_TOKEN_MAX];
- int request_type;
- int id;
- int resource_type;
-
- nr_tokens = buffer_tokenize(buffer, tokens);
- if (nr_tokens < 0) {
- _E("error occurred while tokenizing");
- return;
- }
-
- request_type = atoi(tokens[0]);
- id = atoi(tokens[1]);
-
- /* expect start, set_attrs, exit calls */
- if (request_type != REQUEST_START && request_type != REQUEST_SET_ATTRS
- && request_type != REQUEST_EXIT) {
- _E("client-%d: state: %d Invalid request type: %s client-%d",
- client->id, client->state,
- request_type_str[request_type], client->id);
- return;
- }
-
- if (client->id != id) {
- _E("client-%d: state: %d invalid client id incoming id: %d",
- client->id, client->state, id);
- return;
- }
-
- _I("client-%d state: %d request_type: %s",
- client->id, client->state, request_type_str[request_type]);
-
- switch (request_type) {
- case REQUEST_EXIT:
- /**
- * Format of REQUEST_EXIT:
- * - <REQUEST_TYPE:ID>
- */
- if (client->g_request_resource_head) {
- _I("client-%d: before release resource list", client->id);
- release_resource_list(&client->g_request_resource_head);
- _I("client-%d: release resource list", client->id);
- }
- /* TODO release client->res[] */
-
- client->state = CLIENT_FINALIZED;
- break;
- }
-
- /**
- * Format of response
- * - <REQUEST_TYPE:ID>
- */
- response_len = sprintf(response, "%d:%d", request_type, client->id);
- if (send(client->socket_fd, response, response_len, 0) < 0) {
- _E("failed to send respones, error: %s", strerror(errno));
- return;
- }
-
- _I("send response \"%s\" to client-%d", response, client->id);
-
-}
-
-static struct resource *find_resource_by_type(struct request_client *client, int resource_type)
-{
- int i;
- struct resource *res;
-
- if (!client)
- return NULL;
-
- for (i = 0; i < client->nr_resources; i++) {
- res = client->res[i];
- if (res->type == resource_type)
- return res;
- }
- return NULL;
-}
-
-static void handle_request_update(struct request_client *client, int resource_type)
-{
- char response[10];
- int response_len;
- struct resource *resource;
-
- if (!client)
- return;
-
- resource = find_resource_by_type(client, resource_type);
- if (!resource) {
- _E("there is no resource for type (%d)", resource_type);
- return;
- }
-
- update_resource_attrs(resource);
-
- /**
- * Format of response
- * - <REQUEST_TYPE:ID>
- */
- response_len = sprintf(response, "%d:%d", REQUEST_UPDATE, client->id);
- if (send(client->socket_fd, response, response_len, 0) < 0) {
- _E("failed to send respones, error: %s", strerror(errno));
- return;
- }
-
- _I("send response \"%s\" to client-%d", response, client->id);
-}
-
-static void handle_request_get_value_int(struct request_client *client,
- int resource_type, u_int64_t attr)
-{
- char response[100];
- int response_len;
- struct resource *resource;
- int val;
-
- resource = find_resource_by_type(client, resource_type);
- if (!resource) {
- _E("there is no resource for type (%d)", resource_type);
- return;
- }
-
- get_resource_attr_integer(resource, attr, &val);
- /**
- * Format of response
- * - <REQUEST_TYPE:ID>
- */
- response_len = sprintf(response, "%d:%d:%d", REQUEST_GET_VALUE_INT, client->id, val);
- if (send(client->socket_fd, response, response_len, 0) < 0) {
- _E("failed to send respones, error: %s", strerror(errno));
- return;
- }
-
- _I("send response \"%s\" to client-%d", response, client->id);
-
-}
-
-static void handle_request_stop(struct request_client *client)
-{
- int i;
- char response[10];
- int response_len;
-
- /**
- * Format of REQUEST_EXIT:
- * - <REQUEST_TYPE:ID>
- */
- if (client->g_request_resource_head) {
- _I("client-%d: before release resource list", client->id);
- release_resource_list(&client->g_request_resource_head);
- _I("client-%d: release resource list", client->id);
- }
-
- /*
- * client->res should be freed in this step?
- */
- for (i = 0; i < client->nr_resources; i++)
- free(client->res[i]);
-
- client->state = CLIENT_STOPPED;
- /**
- * Format of response
- * - <REQUEST_TYPE:ID>
- */
- response_len = sprintf(response, "%d:%d", REQUEST_STOP, client->id);
- if (send(client->socket_fd, response, response_len, 0) < 0) {
- _E("failed to send respones, error: %s", strerror(errno));
- return;
- }
-
- _I("send response \"%s\" to client-%d", response, client->id);
-}
-
-static void handle_request_in_running(struct request_client *client, char *buffer)
-{
- int nr_tokens;
- char *tokens[REQUEST_TOKEN_MAX];
- int request_type;
- int id;
- int resource_type;
- u_int64_t attr;
-
- nr_tokens = buffer_tokenize(buffer, tokens);
- if (nr_tokens < 0) {
- _E("error occurred while tokenizing");
- return;
- }
-
- request_type = atoi(tokens[0]);
- id = atoi(tokens[1]);
-
- /* expect stop, update, get_value calls */
- if (request_type != REQUEST_STOP && request_type != REQUEST_UPDATE &&
- request_type != REQUEST_GET_VALUE_INT) {
- _E("state: %d Invalid request type: %s client-%d", client->state,
- request_type_str[request_type], client->id);
- return;
- }
-
- if (client->id != id) {
- _E("client-%d: state: %d invalid client id incoming id: %d",
- client->id, client->state, id);
- return;
- }
-
- _I("client-%d state: %d request_type: %s",
- client->id, client->state, request_type_str[request_type]);
-
- switch (request_type) {
- case REQUEST_UPDATE:
- resource_type = atoi(tokens[2]);
- handle_request_update(client, resource_type);
- break;
- case REQUEST_GET_VALUE_INT:
- resource_type = atoi(tokens[2]);
- attr = strtoul(tokens[3], NULL, 16);
- handle_request_get_value_int(client, resource_type, attr);
- break;
- case REQUEST_STOP:
- handle_request_stop(client);
- break;
- }
-}
-
-static void handle_request_in_thread(struct request_client *client, char *buffer)
-{
- switch (client->state) {
- case CLIENT_RUNNING:
- handle_request_in_running(client, buffer);
- break;
- case CLIENT_STOPPED:
- handle_request_in_stopped(client, buffer);
- break;
- }
-}
-
-static int request_handler_func(void *data, void **result)
-{
- int recv_len;
- fd_set read_fds;
- fd_set active_fds;
- char buffer[REQUEST_MAX];
- struct timeval wait;
- struct request_client *client = (struct request_client *)data;
-
- FD_ZERO(&active_fds);
- FD_SET(client->socket_fd, &active_fds);
-
- _I("start worker thread for client-%d", client->id);
-
- while (client->worker_running) {
- read_fds = active_fds;
- wait.tv_sec = 1;
- wait.tv_usec = 0;
-
- if (select(FD_SETSIZE, &read_fds, NULL, NULL, &wait) < 0) {
- _E("select failed");
- goto error_out;
- }
-
- if (FD_ISSET(client->socket_fd, &read_fds)) {
- /* client submits request */
- recv_len = recv(client->socket_fd, buffer, REQUEST_MAX, 0);
- if (recv_len == 0) {
- /* finalize client connection */
- _I("client-%d state(%d) disconnected",
- client->id, client->state);
- close(client->socket_fd);
- client->state = CLIENT_FINALIZED;
- break;
- } else {
- buffer[recv_len] = '\0';
- _I("incoming buffer: %s", buffer);
- handle_request_in_thread(client, buffer);
- }
- }
- }
-
- return THREAD_RETURN_DONE;
-
-error_out:
- client->state = CLIENT_FINALIZED;
- return THREAD_RETURN_ERROR;
-}
-
-static void request_handler_setup(struct request_client *client)
-{
- int i;
- GList *node;
- struct request_resource *resource;
-
- /* */
- for (i = 0; i < RESOURCE_MAX; i++)
- client->res[i] = NULL;
-
- i = 0;
- node = client->g_request_resource_head;
- while (node != NULL) {
- resource = node->data;
- client->res[i] = create_resource(resource->resource_type, 0, NULL);
- set_resource_attr_interest(client->res[i], resource->attr_mask);
- node = node->next;
- }
- _I("fork worker thread for client-%d", client->id);
-
- create_worker_thread(&client->worker, request_handler_func, client);
- client->worker_running = 1;
- resume_thread(client->worker);
-}
-
static void handle_request_in_connected(struct request_client *client, char *buffer, fd_set *fds)
{
char response[10];
static int request_server_func(void *ctx, void **result)
{
- char buffer[REQUEST_MAX];
+ char buffer[REQUEST_BUFFER_MAX];
int opt = true;
int server_socket;
int addrlen;
client = node->data;
int sd = client->socket_fd;
if (FD_ISSET(sd, &read_fds)) {
- read_len = read(sd, buffer, REQUEST_MAX);
+ read_len = read(sd, buffer, REQUEST_BUFFER_MAX);
if (read_len == 0) {
/* finalize client connection */
getpeername(sd, (struct sockaddr *)&address,