chore: rename handles to be more descriptive

main
Sean McBride 5 years ago
parent d5366f11de
commit 46a2fcfbc4

@ -46,7 +46,7 @@ current_sandbox__get_arguments(void)
/** /**
* Initializes and returns an IO handle on the current sandbox ready for use * Initializes and returns an IO handle on the current sandbox ready for use
* @return index of handle we preopened or -1 if all handles are exhausted * @return index of handle we preopened or -1 if all io_handles are exhausted
**/ **/
static inline int static inline int
current_sandbox__initialize_io_handle(void) current_sandbox__initialize_io_handle(void)
@ -58,7 +58,7 @@ current_sandbox__initialize_io_handle(void)
/** /**
* Initializes and returns an IO handle on the current sandbox ready for use * Initializes and returns an IO handle on the current sandbox ready for use
* @param file_descriptor what we'll set on the IO handle after initialization * @param file_descriptor what we'll set on the IO handle after initialization
* @return index of handle we preopened or -1 if all handles are exhausted * @return index of handle we preopened or -1 if all io_handles are exhausted
**/ **/
static inline int static inline int
current_sandbox__initialize_io_handle_and_set_file_descriptor(int file_descriptor) current_sandbox__initialize_io_handle_and_set_file_descriptor(int file_descriptor)
@ -83,50 +83,50 @@ current_sandbox__parse_http_request(size_t length)
/** /**
* Sets the file descriptor of the sandbox's ith io_handle * Sets the file descriptor of the sandbox's ith io_handle
* Returns error condition if the file_descriptor to set does not contain sandbox preopen magin * Returns error condition if the file_descriptor to set does not contain sandbox preopen magin
* @param handle_index index of the sandbox handles we want to set * @param io_handle_index index of the sandbox io_handle we want to set
* @param file_descriptor the file descripter we want to set it to * @param file_descriptor the file descripter we want to set it to
* @returns the index that was set or -1 in case of error * @returns the index that was set or -1 in case of error
**/ **/
static inline int static inline int
current_sandbox__set_file_descriptor(int handle_index, int file_descriptor) current_sandbox__set_file_descriptor(int io_handle_index, int file_descriptor)
{ {
struct sandbox *sandbox = current_sandbox__get(); struct sandbox *sandbox = current_sandbox__get();
return sandbox__set_file_descriptor(sandbox, handle_index, file_descriptor); return sandbox__set_file_descriptor(sandbox, io_handle_index, file_descriptor);
} }
/** /**
* Get the file descriptor of the sandbox's ith io_handle * Get the file descriptor of the sandbox's ith io_handle
* @param handle_index index into the sandbox's handles table * @param io_handle_index index into the sandbox's io_handles table
* @returns file descriptor * @returns file descriptor
**/ **/
static inline int static inline int
current_sandbox__get_file_descriptor(int handle_index) current_sandbox__get_file_descriptor(int io_handle_index)
{ {
struct sandbox *sandbox = current_sandbox__get(); struct sandbox *sandbox = current_sandbox__get();
return sandbox__get_file_descriptor(sandbox, handle_index); return sandbox__get_file_descriptor(sandbox, io_handle_index);
} }
/** /**
* Close the sandbox's ith io_handle * Close the sandbox's ith io_handle
* @param handle_index index of the handle to close * @param io_handle_index index of the handle to close
**/ **/
static inline void static inline void
current_sandbox__close_file_descriptor(int handle_index) current_sandbox__close_file_descriptor(int io_handle_index)
{ {
struct sandbox *sandbox = current_sandbox__get(); struct sandbox *sandbox = current_sandbox__get();
sandbox__close_file_descriptor(sandbox, handle_index); sandbox__close_file_descriptor(sandbox, io_handle_index);
} }
/** /**
* Get the Libuv handle located at idx of the sandbox ith io_handle * Get the Libuv handle located at idx of the sandbox ith io_handle
* @param handle_index index of the handle containing libuv_handle??? * @param io_handle_index index of the handle containing libuv_handle???
* @returns any libuv handle * @returns any libuv handle
**/ **/
static inline union uv_any_handle * static inline union uv_any_handle *
current_sandbox__get_libuv_handle(int handle_index) current_sandbox__get_libuv_handle(int io_handle_index)
{ {
struct sandbox *sandbox = current_sandbox__get(); struct sandbox *sandbox = current_sandbox__get();
return sandbox__get_libuv_handle(sandbox, handle_index); return sandbox__get_libuv_handle(sandbox, io_handle_index);
} }
/** /**

@ -53,7 +53,7 @@ struct sandbox {
void *arguments; // arguments from request, must be of module->argument_count size. void *arguments; // arguments from request, must be of module->argument_count size.
i32 return_value; i32 return_value;
struct sandbox__io_handle handles[SBOX_MAX_OPEN]; struct sandbox__io_handle io_handles[SBOX_MAX_OPEN];
struct sockaddr client_address; // client requesting connection! struct sockaddr client_address; // client requesting connection!
int client_socket_descriptor; int client_socket_descriptor;
uv_tcp_t client_libuv_stream; uv_tcp_t client_libuv_stream;
@ -128,20 +128,20 @@ sandbox__get_arguments(struct sandbox *sandbox)
/** /**
* Initializes and returns an IO handle on the current sandbox ready for use * Initializes and returns an IO handle on the current sandbox ready for use
* @param sandbox * @param sandbox
* @return index of handle we preopened or -1 on error (sandbox is null or all handles are exhausted) * @return index of handle we preopened or -1 on error (sandbox is null or all io_handles are exhausted)
**/ **/
static inline int static inline int
sandbox__initialize_io_handle(struct sandbox *sandbox) sandbox__initialize_io_handle(struct sandbox *sandbox)
{ {
if (!sandbox) return -1; if (!sandbox) return -1;
int handle_index; int io_handle_index;
for (handle_index = 0; handle_index < SBOX_MAX_OPEN; handle_index++) { for (io_handle_index = 0; io_handle_index < SBOX_MAX_OPEN; io_handle_index++) {
if (sandbox->handles[handle_index].file_descriptor < 0) break; if (sandbox->io_handles[io_handle_index].file_descriptor < 0) break;
} }
if (handle_index == SBOX_MAX_OPEN) return -1; if (io_handle_index == SBOX_MAX_OPEN) return -1;
sandbox->handles[handle_index].file_descriptor = SBOX_PREOPEN_MAGIC; sandbox->io_handles[io_handle_index].file_descriptor = SBOX_PREOPEN_MAGIC;
memset(&sandbox->handles[handle_index].libuv_handle, 0, sizeof(union uv_any_handle)); memset(&sandbox->io_handles[io_handle_index].libuv_handle, 0, sizeof(union uv_any_handle));
return handle_index; return io_handle_index;
} }
@ -149,77 +149,78 @@ sandbox__initialize_io_handle(struct sandbox *sandbox)
* Initializes and returns an IO handle of a sandbox ready for use * Initializes and returns an IO handle of a sandbox ready for use
* @param sandbox * @param sandbox
* @param file_descriptor what we'll set on the IO handle after initialization * @param file_descriptor what we'll set on the IO handle after initialization
* @return index of handle we preopened or -1 if all handles are exhausted * @return index of handle we preopened or -1 if all io_handles are exhausted
**/ **/
static inline int static inline int
sandbox__initialize_io_handle_and_set_file_descriptor(struct sandbox *sandbox, int file_descriptor) sandbox__initialize_io_handle_and_set_file_descriptor(struct sandbox *sandbox, int file_descriptor)
{ {
if (!sandbox) return -1; if (!sandbox) return -1;
if (file_descriptor < 0) return file_descriptor; if (file_descriptor < 0) return file_descriptor;
int handle_index = sandbox__initialize_io_handle(sandbox); int io_handle_index = sandbox__initialize_io_handle(sandbox);
if (handle_index != -1) if (io_handle_index != -1)
sandbox->handles[handle_index].file_descriptor = sandbox->io_handles[io_handle_index].file_descriptor =
file_descriptor; // well, per sandbox.. so synchronization necessary! file_descriptor; // well, per sandbox.. so synchronization necessary!
return handle_index; return io_handle_index;
} }
/** /**
* Sets the file descriptor of the sandbox's ith io_handle * Sets the file descriptor of the sandbox's ith io_handle
* Returns error condition if the file_descriptor to set does not contain sandbox preopen magic * Returns error condition if the file_descriptor to set does not contain sandbox preopen magic
* @param sandbox * @param sandbox
* @param handle_index index of the sandbox handles we want to set * @param io_handle_index index of the sandbox io_handles we want to set
* @param file_descriptor the file descripter we want to set it to * @param file_descriptor the file descripter we want to set it to
* @returns the index that was set or -1 in case of error * @returns the index that was set or -1 in case of error
**/ **/
static inline int static inline int
sandbox__set_file_descriptor(struct sandbox *sandbox, int handle_index, int file_descriptor) sandbox__set_file_descriptor(struct sandbox *sandbox, int io_handle_index, int file_descriptor)
{ {
if (!sandbox) return -1; if (!sandbox) return -1;
if (handle_index >= SBOX_MAX_OPEN || handle_index < 0) return -1; if (io_handle_index >= SBOX_MAX_OPEN || io_handle_index < 0) return -1;
if (file_descriptor < 0 || sandbox->handles[handle_index].file_descriptor != SBOX_PREOPEN_MAGIC) return -1; if (file_descriptor < 0 || sandbox->io_handles[io_handle_index].file_descriptor != SBOX_PREOPEN_MAGIC)
sandbox->handles[handle_index].file_descriptor = file_descriptor; return -1;
return handle_index; sandbox->io_handles[io_handle_index].file_descriptor = file_descriptor;
return io_handle_index;
} }
/** /**
* Get the file descriptor of the sandbox's ith io_handle * Get the file descriptor of the sandbox's ith io_handle
* @param sandbox * @param sandbox
* @param handle_index index into the sandbox's handles table * @param io_handle_index index into the sandbox's io_handles table
* @returns file descriptor or -1 in case of error * @returns file descriptor or -1 in case of error
**/ **/
static inline int static inline int
sandbox__get_file_descriptor(struct sandbox *sandbox, int handle_index) sandbox__get_file_descriptor(struct sandbox *sandbox, int io_handle_index)
{ {
if (!sandbox) return -1; if (!sandbox) return -1;
if (handle_index >= SBOX_MAX_OPEN || handle_index < 0) return -1; if (io_handle_index >= SBOX_MAX_OPEN || io_handle_index < 0) return -1;
return sandbox->handles[handle_index].file_descriptor; return sandbox->io_handles[io_handle_index].file_descriptor;
} }
/** /**
* Close the sandbox's ith io_handle * Close the sandbox's ith io_handle
* @param sandbox * @param sandbox
* @param handle_index index of the handle to close * @param io_handle_index index of the handle to close
**/ **/
static inline void static inline void
sandbox__close_file_descriptor(struct sandbox *sandbox, int handle_index) sandbox__close_file_descriptor(struct sandbox *sandbox, int io_handle_index)
{ {
if (handle_index >= SBOX_MAX_OPEN || handle_index < 0) return; if (io_handle_index >= SBOX_MAX_OPEN || io_handle_index < 0) return;
// TODO: Do we actually need to call some sort of close function here? // TODO: Do we actually need to call some sort of close function here?
sandbox->handles[handle_index].file_descriptor = -1; sandbox->io_handles[io_handle_index].file_descriptor = -1;
} }
/** /**
* Get the Libuv handle located at idx of the sandbox ith io_handle * Get the Libuv handle located at idx of the sandbox ith io_handle
* @param sandbox * @param sandbox
* @param handle_index index of the handle containing libuv_handle??? * @param io_handle_index index of the handle containing libuv_handle???
* @returns any libuv handle or a NULL pointer in case of error * @returns any libuv handle or a NULL pointer in case of error
**/ **/
static inline union uv_any_handle * static inline union uv_any_handle *
sandbox__get_libuv_handle(struct sandbox *sandbox, int handle_index) sandbox__get_libuv_handle(struct sandbox *sandbox, int io_handle_index)
{ {
if (!sandbox) return NULL; if (!sandbox) return NULL;
if (handle_index >= SBOX_MAX_OPEN || handle_index < 0) return NULL; if (io_handle_index >= SBOX_MAX_OPEN || io_handle_index < 0) return NULL;
return &sandbox->handles[handle_index].libuv_handle; return &sandbox->io_handles[io_handle_index].libuv_handle;
} }
#endif /* SFRT_SANDBOX_H */ #endif /* SFRT_SANDBOX_H */

@ -56,8 +56,8 @@ runtime__initialize(void)
********************************/ ********************************/
/** /**
* @brief Execution Loop of the listener core, handles HTTP requests, allocates sandbox request objects, and pushes the * @brief Execution Loop of the listener core, io_handles HTTP requests, allocates sandbox request objects, and pushes
* sandbox object to the global dequeue * the sandbox object to the global dequeue
* @param dummy data pointer provided by pthreads API. Unused in this function * @param dummy data pointer provided by pthreads API. Unused in this function
* @return NULL * @return NULL
* *

@ -318,7 +318,7 @@ sandbox__allocate(struct module *module, char *arguments, int socket_descriptor,
} }
sandbox->client_socket_descriptor = socket_descriptor; sandbox->client_socket_descriptor = socket_descriptor;
if (socket_address) memcpy(&sandbox->client_address, socket_address, sizeof(struct sockaddr)); if (socket_address) memcpy(&sandbox->client_address, socket_address, sizeof(struct sockaddr));
for (int i = 0; i < SBOX_MAX_OPEN; i++) sandbox->handles[i].file_descriptor = -1; for (int i = 0; i < SBOX_MAX_OPEN; i++) sandbox->io_handles[i].file_descriptor = -1;
ps_list_init_d(sandbox); ps_list_init_d(sandbox);
// Setup the sandbox's context, stack, and instruction pointer // Setup the sandbox's context, stack, and instruction pointer

Loading…
Cancel
Save