summaryrefslogtreecommitdiff
path: root/patch/ipc/IPCClient.c
diff options
context:
space:
mode:
authorBear <bear@bengtsson.win>2021-12-27 09:29:58 +0000
committerBear <bear@bengtsson.win>2021-12-27 09:29:58 +0000
commit69262b01ced79c2d776fab9b889926d1816a1e7a (patch)
treef304cd6fa8734e83a7772d07dc9b484781565155 /patch/ipc/IPCClient.c
Added DWM
Diffstat (limited to 'patch/ipc/IPCClient.c')
-rw-r--r--patch/ipc/IPCClient.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/patch/ipc/IPCClient.c b/patch/ipc/IPCClient.c
new file mode 100644
index 0000000..a157513
--- /dev/null
+++ b/patch/ipc/IPCClient.c
@@ -0,0 +1,67 @@
+#include "IPCClient.h"
+
+#include <string.h>
+#include <sys/epoll.h>
+
+#include "util.h"
+
+IPCClient *
+ipc_client_new(int fd)
+{
+ IPCClient *c = (IPCClient *)malloc(sizeof(IPCClient));
+
+ if (c == NULL) return NULL;
+
+ // Initialize struct
+ memset(&c->event, 0, sizeof(struct epoll_event));
+
+ c->buffer_size = 0;
+ c->buffer = NULL;
+ c->fd = fd;
+ c->event.data.fd = fd;
+ c->next = NULL;
+ c->prev = NULL;
+ c->subscriptions = 0;
+
+ return c;
+}
+
+void
+ipc_list_add_client(IPCClientList *list, IPCClient *nc)
+{
+ DEBUG("Adding client with fd %d to list\n", nc->fd);
+
+ if (*list == NULL) {
+ // List is empty, point list at first client
+ *list = nc;
+ } else {
+ IPCClient *c;
+ // Go to last client in list
+ for (c = *list; c && c->next; c = c->next)
+ ;
+ c->next = nc;
+ nc->prev = c;
+ }
+}
+
+void
+ipc_list_remove_client(IPCClientList *list, IPCClient *c)
+{
+ IPCClient *cprev = c->prev;
+ IPCClient *cnext = c->next;
+
+ if (cprev != NULL) cprev->next = c->next;
+ if (cnext != NULL) cnext->prev = c->prev;
+ if (c == *list) *list = c->next;
+}
+
+IPCClient *
+ipc_list_get_client(IPCClientList list, int fd)
+{
+ for (IPCClient *c = list; c; c = c->next) {
+ if (c->fd == fd) return c;
+ }
+
+ return NULL;
+}
+