From 51bbf779ba2c9d5954e2c9470a8eae7c1ddd38a5 Mon Sep 17 00:00:00 2001 From: Phil Jones Date: Tue, 7 Jun 2022 13:47:35 +0100 Subject: Switch from using (E)GL to wl_shm. eglInitialize() is slow (~50-100ms), and uses a fair amount of memory (~100 MB). For such a small, simple program that just wants to launch as quickly as possible, wl_shm performs better. --- src/ipc.c | 121 -------------------------------------------------------------- 1 file changed, 121 deletions(-) delete mode 100644 src/ipc.c (limited to 'src/ipc.c') diff --git a/src/ipc.c b/src/ipc.c deleted file mode 100644 index 2af5dbf..0000000 --- a/src/ipc.c +++ /dev/null @@ -1,121 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "ipc.h" -#include "log.h" -#include "xmalloc.h" - -static int ipc_open(void); -static int ipc_send(int socket, struct json_object *request); -static struct json_object *ipc_receive(int socket); - -struct json_object *ipc_submit(struct json_object *request) -{ - int sock = ipc_open(); - if (sock == -1) { - return NULL; - } - - if (ipc_send(sock, request) == -1) { - close(sock); - return NULL; - } - - struct json_object *resp = ipc_receive(sock); - close(sock); - return resp; -} - -/* - * Open a connection to the UNIX socket specified by - * the environment variable GREETD_SOCK. - * - * Returns the socket file descriptor on success, or -1 on failure. - */ -int ipc_open(void) -{ - char *greetd_sock = getenv("GREETD_SOCK"); - - if (greetd_sock == NULL) { - log_error("GREETD_SOCK not set.\n"); - return -1; - } - - int sock = socket(AF_UNIX, SOCK_STREAM, 0); - if (sock == -1) { - log_error("Unable to create socket: %s\n", strerror(errno)); - return -1; - } - - struct sockaddr_un remote = { .sun_family = AF_UNIX }; - strncpy(remote.sun_path, greetd_sock, sizeof(remote.sun_path)); - - if (connect(sock, (struct sockaddr *)&remote, sizeof(remote)) == -1) { - log_error("Unable to connect to greetd: %s\n", strerror(errno)); - close(sock); - return -1; - } - return sock; -} - -/* - * Send an IPC request to the specified socket. - * - * Returns 0 on success, or -1 on failure. - */ -int ipc_send(int sock, struct json_object *request) -{ - const char *str = json_object_to_json_string(request); - uint32_t len = strlen(str); - - if (send(sock, &len, sizeof(len), 0) == -1) { - log_error("Error sending request size: %s\n", strerror(errno)); - return -1; - } - - if (send(sock, str, len, 0) == -1) { - log_error("Error sending request: %s\n", strerror(errno)); - return -1; - } - return 0; -} - -/* - * Receive an IPC response on the specified socket. - * - * Returns the response on success, or NULL on failure. - */ -struct json_object *ipc_receive(int sock) -{ - uint32_t len = 0; - - if (recv(sock, &len, sizeof(len), 0) != sizeof(len)) { - log_error("Error receiving response size: %s\n", strerror(errno)); - return NULL; - } - - char *buf = xmalloc(len + 1); - if (recv(sock, buf, len, 0) != len) { - log_error("Error receiving response: %s\n", strerror(errno)); - free(buf); - return NULL; - } - - buf[len] = '\0'; - - enum json_tokener_error error; - struct json_object *resp = json_tokener_parse_verbose(buf, &error); - free(buf); - - if (resp == NULL) { - log_error("Error parsing response: %s\n", json_tokener_error_desc(error)); - } - return resp; - -} -- cgit v1.2.3