qxwz_sdk_socket.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #ifndef QXWZ_SD_SOCKET_H__
  2. #define QXWZ_SD_SOCKET_H__
  3. #include "gnss_config.h"
  4. /* #include <sys/socket.h> */
  5. typedef enum {
  6. QX_SOCK_MONITOR_READ,
  7. QX_SOCK_MONITOR_WRITE,
  8. QX_SOCK_MONITOR_EXCEPTION,
  9. QX_SOCK_MONITOR_ALL,
  10. QX_SOCK_MONITOR_UNKNOW
  11. } QX_SOCKET_MONITOR;
  12. typedef enum{
  13. QX_SOCKET_AF_INET,
  14. QX_SOCKET_AF_INET6
  15. }QX_SOCKET_PROTOCOL_FAMILY;
  16. typedef enum{
  17. QX_SOCKET_STREAM,
  18. QX_SOCKET_DGRAM
  19. }QX_SOCKET_STREAM_TYPE;
  20. /*some special platform will need some special config, we can specify here and set*/
  21. typedef struct{
  22. int netid;
  23. }qx_socket_t;
  24. void qx_socket_config_setting(int id);
  25. /**
  26. * get host ip by host name.
  27. * params:
  28. host: host name
  29. * returns:
  30. NULL if failed, host ip pointer if success
  31. */
  32. int qx_socket_gethostbyname(char *host, char *strip, int *af);
  33. #define QX_SOCKET_BLOCK 0
  34. #define QX_SOCKET_UBLOCK 1
  35. /**
  36. * create socket
  37. * params:
  38. domain: protocol family, such as AF_INET or AF_INET6
  39. type: communication type, such as SOCK_STREAM, SOCK_DGRAM, SOCK_RAW
  40. protocol: potocol type, specify as 0
  41. nonblock: QX_SOCKET_BLOCK, QX_SOCKET_UBLOCK
  42. * returns:
  43. -1 failed, other non-zero for socket file description
  44. */
  45. int qx_socket(int domain, int type, int protocol, int nonblock);
  46. /**
  47. * start socket connect.
  48. * params:
  49. sockfd: socket file description
  50. host : host ip, which has converted from host name
  51. port : host port number
  52. * returns:
  53. -1 if failed, 0 if success
  54. */
  55. int qx_socket_connect(int sockfd, void *host, int port, int af);
  56. /**
  57. * send data.
  58. * params:
  59. sockfd: socket file description
  60. buf : data buf will be sent
  61. len : data length will be sent
  62. flags : extra flags, usually 0
  63. * returns:
  64. On success, these calls return the number of bytes sent. On error, -1 is returned
  65. */
  66. int qx_socket_send(int sockfd, const void *buf, int len, int flags);
  67. /**
  68. * receive data.
  69. * params:
  70. sockfd: socket file description
  71. buf : data buf will be sent
  72. len : data length will be sent
  73. flags : extra flags, usually 0
  74. * returns:
  75. On success, return the number of bytes receive. On error, -1 is returned
  76. */
  77. int qx_socket_recv(int sockfd, void *buf, int len, int flags);
  78. /**
  79. * monitor socket ready or not.
  80. * params:
  81. sockfd : socket file description
  82. timeout: time to monitor
  83. rw : socket monitor type
  84. * returns:
  85. On success, return 0. On error, return -1
  86. */
  87. int qx_socket_select(int sockfd, long timeout, QX_SOCKET_MONITOR rw);
  88. /**
  89. * close socket
  90. * params:
  91. sockfd : socket file description
  92. * returns:
  93. On success, return 0. On error, return -1
  94. */
  95. int qx_socket_close(int sockfd);
  96. #endif