network.h 682 B

12345678910111213141516171819202122232425262728293031323334
  1. /*
  2. * Copyright (C) 2019-2020 Alibaba Group Holding Limited
  3. */
  4. #ifndef __NETWORK_H__
  5. #define __NETWORK_H__
  6. #include <sys/socket.h>
  7. #include <arpa/inet.h>
  8. #ifndef __linux__
  9. #include <lwip/netdb.h>
  10. #else
  11. #include <netdb.h>
  12. #endif
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. typedef struct network {
  17. int fd;
  18. struct sockaddr_in address;
  19. int (*net_connect)(struct network *n, char *addr, int port, int net_type);
  20. int (*net_read)(struct network *, unsigned char *, int, int);
  21. int (*net_write)(struct network *, unsigned char *, int, int);
  22. void (*net_disconncet)(struct network *n);
  23. } network_t;
  24. void network_init(network_t *n);
  25. #ifdef __cplusplus
  26. }
  27. #endif
  28. #endif