socket_comm.h 665 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #ifndef SOCKET_COMM_H
  2. #define SOCKET_COMM_H
  3. #include "buffer.h"
  4. #include <sys/types.h>
  5. #include <sys/socket.h>
  6. #include <arpa/inet.h>
  7. #include <netdb.h>
  8. #include <netinet/tcp.h>
  9. #include <unistd.h>
  10. #include <fcntl.h>
  11. #include <errno.h>
  12. #define SOCKET_CONNECTED 1
  13. #define SOCKET_CONNECTING 2
  14. struct client_info
  15. {
  16. int id;
  17. int fd;
  18. int to_id;
  19. int connect_type;
  20. struct ring_buffer* buffer;
  21. char client_ip[128];
  22. };
  23. union sockaddr_all {
  24. struct sockaddr s; /*normal storage*/
  25. struct sockaddr_in v4; /*ipv4 storage*/
  26. struct sockaddr_in6 v6; /*ipv6 storage*/
  27. };
  28. void sp_nonblocking(int fd);
  29. void set_keep_alive(int fd);
  30. #endif