From 857c11d1402c8abc6e87e100ad11c6b8530cf8ab Mon Sep 17 00:00:00 2001 From: xiaosuGW Date: Thu, 8 Jul 2021 12:02:13 -0500 Subject: [PATCH] do not monitor client fd with epoll if the sandbox is not the last one in the chain --- runtime/include/sandbox_functions.h | 14 ++++++++------ runtime/include/sandbox_receive_request.h | 2 +- runtime/include/worker_thread_execute_epoll_loop.h | 1 - runtime/src/current_sandbox.c | 6 +----- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/runtime/include/sandbox_functions.h b/runtime/include/sandbox_functions.h index 2cd35cb..95ceafd 100644 --- a/runtime/include/sandbox_functions.h +++ b/runtime/include/sandbox_functions.h @@ -145,13 +145,15 @@ sandbox_open_http(struct sandbox *sandbox) /* Set the sandbox as the data the http-parser has access to */ sandbox->http_parser.data = sandbox; //assign data to sandbox in case to operator it when a callback happended - /* Freshly allocated sandbox going runnable for first time, so register client socket with epoll */ - struct epoll_event accept_evt; - accept_evt.data.ptr = (void *)sandbox; - accept_evt.events = EPOLLIN | EPOLLOUT | EPOLLET; - int rc = epoll_ctl(worker_thread_epoll_file_descriptor, EPOLL_CTL_ADD, sandbox->client_socket_descriptor, + if (sandbox->module->next_module == NULL) { + /* Freshly allocated sandbox going runnable for first time, so register client socket with epoll */ + struct epoll_event accept_evt; + accept_evt.data.ptr = (void *)sandbox; + accept_evt.events = EPOLLIN | EPOLLOUT | EPOLLET; + int rc = epoll_ctl(worker_thread_epoll_file_descriptor, EPOLL_CTL_ADD, sandbox->client_socket_descriptor, &accept_evt); - if (unlikely(rc < 0)) panic_err(); + if (unlikely(rc < 0)) panic_err(); + } } /** diff --git a/runtime/include/sandbox_receive_request.h b/runtime/include/sandbox_receive_request.h index 60c444e..a47b8d5 100644 --- a/runtime/include/sandbox_receive_request.h +++ b/runtime/include/sandbox_receive_request.h @@ -88,7 +88,7 @@ sandbox_receive_request(struct sandbox *sandbox) sandbox->request_response_data_length += nparsed; } - + http_request_print(&sandbox->http_request); sandbox->request_length = sandbox->request_response_data_length; rc = 0; diff --git a/runtime/include/worker_thread_execute_epoll_loop.h b/runtime/include/worker_thread_execute_epoll_loop.h index 96b922f..942db72 100644 --- a/runtime/include/worker_thread_execute_epoll_loop.h +++ b/runtime/include/worker_thread_execute_epoll_loop.h @@ -24,7 +24,6 @@ worker_thread_execute_epoll_loop(void) struct epoll_event epoll_events[RUNTIME_MAX_EPOLL_EVENTS]; int descriptor_count = epoll_wait(worker_thread_epoll_file_descriptor, epoll_events, RUNTIME_MAX_EPOLL_EVENTS, 0); - if (descriptor_count < 0) { if (errno == EINTR) continue; diff --git a/runtime/src/current_sandbox.c b/runtime/src/current_sandbox.c index 9edd8e5..d2a2a43 100644 --- a/runtime/src/current_sandbox.c +++ b/runtime/src/current_sandbox.c @@ -85,7 +85,7 @@ current_sandbox_start(void) assert(sandbox->previous_function_output != NULL); memcpy(sandbox->request_response_data, sandbox->previous_function_output, sandbox->output_length); sandbox->http_request.body = sandbox->request_response_data; - sandbox->http_request.body_length = sandbox->output_length; + sandbox->http_request.body_length = sandbox->output_length; sandbox->request_length = sandbox->pre_request_length; sandbox->request_response_data_length = sandbox->request_length; } @@ -116,11 +116,7 @@ current_sandbox_start(void) sandbox->request_arrival_timestamp, true, pre_func_output, output_length); /* Add to the Global Sandbox Request Scheduler */ global_request_scheduler_add(sandbox_request); - sandbox_remove_from_epoll(sandbox); sandbox_set_as_returned(sandbox, SANDBOX_RUNNING); - scheduler_yield(); - assert(0); - return; } else { /* Retrieve the result, construct the HTTP response, and send to client */ if (sandbox_send_response(sandbox) < 0) { // if send blocked, remove the sandbox from the local runqueue