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.

44 lines
1.3KB

  1. #include <sys/types.h>
  2. #include <sys/socket.h>
  3. #include <sys/time.h>
  4. #include <netinet/in.h>
  5. #include <arpa/inet.h>
  6. #include <fcntl.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <unistd.h>
  10. #include <string.h>
  11. #include <inttypes.h>
  12. struct message_t {
  13. uint32_t addr;
  14. size_t length;
  15. void *data_p;
  16. };
  17. struct subscription_t {
  18. uint32_t addr;
  19. int fd_listen, fd_client;
  20. };
  21. struct list_subscription_cell_t {
  22. struct subscription_t subscription;
  23. struct list_subscription_cell_t *prev_p, *next_p;
  24. };
  25. struct list_subscription_t {
  26. struct list_subscription_cell_t *list_p, *read_p;
  27. int fd_command_listen, fd_command_client;
  28. };
  29. int char_hexa_to_uint32(const char *const argv, uint32_t *nombre);
  30. /* initialise la liste en mettant le port port_listen en écoute pour recevoir les commandes «subscribe» et «unsubscribe» */
  31. int list_subscription_init(struct list_subscription_t *list_p, int port_listen);
  32. /* détruit la liste */
  33. void list_subscription_destroy(struct list_subscription_t *list_p);
  34. /* envoyer le message (retourne 0 si l'adresse de destination du message n'est pas incrite) */
  35. int send_message(struct list_subscription_t *list_p, struct message_t *message_p);
  36. /* fonction qui fait un malloc de message_p->data */
  37. int read_message(struct list_subscription_t *list_p, struct message_t *message_p);