joylink_adapter_net.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. /*Copyright (c) 2015-2050, JD Smart All rights reserved.
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License. */
  11. #ifndef JOYLINK_ADAPTER_NET_TCP_H
  12. #define JOYLINK_ADAPTER_NET_TCP_H
  13. #include <stdint.h>
  14. #define ANET_OK 0
  15. #define ANET_ERR -1
  16. #define ANET_ERR_LEN 256
  17. /* Flags used with certain functions. */
  18. #define ANET_NONE 0
  19. #define ANET_IP_ONLY (1<<0)
  20. #if defined(__sun)
  21. #define AF_LOCAL AF_UNIX
  22. #endif
  23. #include "joylink_ret_code.h"
  24. /**
  25. * brief:
  26. *
  27. * @Param: err
  28. * @Param: addr
  29. * @Param: port
  30. *
  31. * @Returns:
  32. */
  33. int32_t
  34. joylink_adapter_net_tcp_connect(char *err, const char *addr, int32_t port);
  35. /**
  36. * brief:
  37. *
  38. * @Param: err
  39. * @Param: addr
  40. * @Param: port
  41. *
  42. * @Returns:
  43. */
  44. int32_t
  45. joylink_adapter_net_tcp_non_block_connect(char *err, char *addr, int32_t port);
  46. /**
  47. * brief:
  48. *
  49. * @Param: err
  50. * @Param: port
  51. * @Param: bindaddr
  52. * @Param: backlog
  53. *
  54. * @Returns:
  55. */
  56. int32_t
  57. joylink_adapter_net_tcp_server(char *err, int32_t port, char *bindaddr, int32_t backlog);
  58. /**
  59. * brief:
  60. *
  61. * @Param: err
  62. * @Param: port
  63. * @Param: bindaddr
  64. * @Param: backlog
  65. *
  66. * @Returns:
  67. */
  68. int32_t
  69. joylink_adapter_net_tcp6_server(char *err, int32_t port, char *bindaddr, int32_t backlog);
  70. /**
  71. * brief:
  72. *
  73. * @Param: err
  74. * @Param: serversock
  75. * @Param: ip
  76. * @Param: ip_len
  77. * @Param: port
  78. *
  79. * @Returns:
  80. */
  81. int32_t
  82. joylink_net_tcp_accept(char *err, int32_t serversock, char *ip, int32_t ip_len, int32_t *port);
  83. /**
  84. * brief:
  85. *
  86. * @Param: err
  87. * @Param: fd
  88. *
  89. * @Returns:
  90. */
  91. int32_t
  92. joylink_adapter_net_tcp_keep_alive(char *err, int32_t fd);
  93. /**
  94. * brief:
  95. *
  96. * @Param: err
  97. * @Param: serversock
  98. *
  99. * @Returns:
  100. */
  101. int32_t
  102. joylink_net_unix_accept(char *err, int32_t serversock);
  103. /**
  104. * brief:
  105. *
  106. * @Param: err
  107. * @Param: fd
  108. *
  109. * @Returns:
  110. */
  111. int32_t
  112. joylink_adapter_net_non_block(char *err, int32_t fd);
  113. /**
  114. * brief:
  115. *
  116. * @Param: err
  117. * @Param: fd
  118. *
  119. * @Returns:
  120. */
  121. int32_t
  122. joylink_adapter_net_enable_tcp_no_delay(char *err, int32_t fd);
  123. /**
  124. * brief:
  125. *
  126. * @Param: err
  127. * @Param: fd
  128. *
  129. * @Returns:
  130. */
  131. int32_t
  132. joylink_adapter_net_disable_tcp_no_delay(char *err, int32_t fd);
  133. /**
  134. * brief:
  135. *
  136. * @Param: fd
  137. * @Param: ip
  138. * @Param: ip_len
  139. * @Param: port
  140. *
  141. * @Returns:
  142. */
  143. int32_t
  144. joylink_net_peer_to_string(int32_t fd, char *ip, int32_t ip_len, int32_t *port);
  145. /**
  146. * brief:
  147. *
  148. * @Param: err
  149. * @Param: fd
  150. * @Param: int32_terval
  151. *
  152. * @Returns:
  153. */
  154. int32_t
  155. joylink_adapter_net_keep_alive(char *err, int32_t fd, int32_t int32_terval);
  156. /**
  157. * brief:
  158. *
  159. * @Param: fd
  160. * @Param: ip
  161. * @Param: ip_len
  162. * @Param: port
  163. *
  164. * @Returns:
  165. */
  166. int32_t
  167. joylink_net_sock_name(int32_t fd, char *ip, int32_t ip_len, int32_t *port);
  168. /**
  169. * brief:
  170. *
  171. * @Param: err
  172. * @Param: host
  173. * @Param: ipbuf
  174. * @Param: ipbuf_len
  175. *
  176. * @Returns:
  177. */
  178. int32_t
  179. joylink_adapter_net_resolve(char *err, char *host, char *ipbuf, int32_t ipbuf_len);
  180. /**
  181. * brief:
  182. *
  183. * @Param: err
  184. * @Param: host
  185. * @Param: ipbuf
  186. * @Param: ipbuf_len
  187. *
  188. * @Returns:
  189. */
  190. int32_t
  191. joylink_adapter_net_resolve_ip(char *err, char *host, char *ipbuf, int32_t ipbuf_len);
  192. /**
  193. * brief:
  194. *
  195. * @Param: fd
  196. * @Param: buf
  197. * @Param: size
  198. *
  199. * @Returns:
  200. */
  201. int32_t
  202. joylink_adapter_net_send(int32_t fd, char *buf, int32_t size);
  203. /**
  204. * brief:
  205. *
  206. * @Param: fd
  207. * @Param: buf
  208. * @Param: size
  209. *
  210. * @Returns:
  211. */
  212. int32_t
  213. joylink_adapter_net_recv(int32_t fd, char *buf, int32_t size);
  214. /**
  215. * brief:
  216. *
  217. * @Param: fd
  218. * @Param: buf
  219. * @Param: count
  220. *
  221. * @Returns:
  222. */
  223. int32_t
  224. joylink_adapter_net_read(int32_t fd, char *buf, int32_t count);
  225. /**
  226. * brief:
  227. *
  228. * @Param: fd
  229. * @Param: buf
  230. * @Param: count
  231. *
  232. * @Returns:
  233. */
  234. int32_t
  235. joylink_adapter_net_write(int32_t fd, char *buf, int32_t count);
  236. /**
  237. * brief:
  238. *
  239. * @Param: fd
  240. * @Param: buf
  241. * @Param: size
  242. * @Param: usec
  243. * @Param: sec
  244. *
  245. * @Returns:
  246. */
  247. int32_t
  248. joylink_adapter_net_recv_with_time(int32_t fd, char *buf, int32_t size, int32_t usec, int32_t sec);
  249. /**
  250. * brief:
  251. *
  252. * @Param: err
  253. * @Param: fd
  254. * @Param: buffsize
  255. *
  256. * @Returns:
  257. */
  258. int32_t
  259. joylink_adapter_net_set_send_buf(char *err, int32_t fd, int32_t buffsize);
  260. /**
  261. * brief:
  262. *
  263. * @Param: fd
  264. *
  265. * @Returns:
  266. */
  267. int32_t
  268. joylink_adapter_net_close(int32_t fd);
  269. /**
  270. * brief:
  271. *
  272. * @Param: nfds
  273. * @Param: readfds
  274. * @Param: writefds
  275. * @Param: exceptfds
  276. * @Param: timeout
  277. *
  278. * @Returns:
  279. */
  280. int32_t
  281. joylink_adapter_select(int nfds, fd_set *readfds, fd_set *writefds,
  282. fd_set *exceptfds, struct timeval *timeout);
  283. /**
  284. * brief:
  285. *
  286. * @Returns:
  287. */
  288. int32_t
  289. joylink_adapter_udp_socket();
  290. #endif