dwm

Kris's build of dwm
git clone git clone https://git.krisyotam.com/krisyotam/dwm.git
Log | Files | Refs | README | LICENSE

IPCClient.c (1227B)


      1 #include "IPCClient.h"
      2 
      3 #include <string.h>
      4 #include <sys/epoll.h>
      5 
      6 #include "util.h"
      7 
      8 IPCClient *
      9 ipc_client_new(int fd)
     10 {
     11   IPCClient *c = (IPCClient *)malloc(sizeof(IPCClient));
     12 
     13   if (c == NULL) return NULL;
     14 
     15   // Initialize struct
     16   memset(&c->event, 0, sizeof(struct epoll_event));
     17 
     18   c->buffer_size = 0;
     19   c->buffer = NULL;
     20   c->fd = fd;
     21   c->event.data.fd = fd;
     22   c->next = NULL;
     23   c->prev = NULL;
     24   c->subscriptions = 0;
     25 
     26   return c;
     27 }
     28 
     29 void
     30 ipc_list_add_client(IPCClientList *list, IPCClient *nc)
     31 {
     32   DEBUG("Adding client with fd %d to list\n", nc->fd);
     33 
     34   if (*list == NULL) {
     35     // List is empty, point list at first client
     36     *list = nc;
     37   } else {
     38     IPCClient *c;
     39     // Go to last client in list
     40     for (c = *list; c && c->next; c = c->next)
     41       ;
     42     c->next = nc;
     43     nc->prev = c;
     44   }
     45 }
     46 
     47 void
     48 ipc_list_remove_client(IPCClientList *list, IPCClient *c)
     49 {
     50   IPCClient *cprev = c->prev;
     51   IPCClient *cnext = c->next;
     52 
     53   if (cprev != NULL) cprev->next = c->next;
     54   if (cnext != NULL) cnext->prev = c->prev;
     55   if (c == *list) *list = c->next;
     56 }
     57 
     58 IPCClient *
     59 ipc_list_get_client(IPCClientList list, int fd)
     60 {
     61   for (IPCClient *c = list; c; c = c->next) {
     62     if (c->fd == fd) return c;
     63   }
     64 
     65   return NULL;
     66 }
     67