Another copy of my dotfiles. Because I don't completely trust GitHub.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.2 KiB

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