summaryrefslogtreecommitdiffhomepage
path: root/patch/ipc/IPCClient.c
diff options
context:
space:
mode:
authorbakkeby <[email protected]>2020-09-08 13:34:58 +0200
committerbakkeby <[email protected]>2020-09-08 13:34:58 +0200
commit95611ca0bd691416c23ea6c0ed00cfe454f601b5 (patch)
treeb493e6d3f8251160b0695d229de8d9a8259653e8 /patch/ipc/IPCClient.c
parent4379517c25b136f4628c436254a54852542ebadf (diff)
downloaddwm-flexipatch-95611ca0bd691416c23ea6c0ed00cfe454f601b5.tar.gz
dwm-flexipatch-95611ca0bd691416c23ea6c0ed00cfe454f601b5.zip
Adding IPC v1.5.5 patch
Diffstat (limited to 'patch/ipc/IPCClient.c')
-rw-r--r--patch/ipc/IPCClient.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/patch/ipc/IPCClient.c b/patch/ipc/IPCClient.c
new file mode 100644
index 0000000..0d3eefb
--- /dev/null
+++ b/patch/ipc/IPCClient.c
@@ -0,0 +1,66 @@
+#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;
+}