pando_net_tcp.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*******************************************************
  2. * File name: pando_net_tcp.h
  3. * Author:Chongguang Li
  4. * Versions:0.0.1
  5. * Description: the tcp api
  6. * History:
  7. * 1.Date:
  8. * Author:
  9. * Modification:
  10. *********************************************************/
  11. #ifndef _PANDO_NET_TCP_H_
  12. #define _PANDO_NET_TCP_H_
  13. #include "pando_types.h"
  14. struct data_buf
  15. {
  16. uint16_t length;
  17. char *data;
  18. };
  19. typedef void (* net_tcp_connected_callback)(void *tcp_conn, int8_t errno);
  20. typedef void (* net_tcp_sent_callback)(void *tcp_conn, int8_t errno);
  21. typedef void (* net_tcp_recv_callback)(void *tcp_conn, struct data_buf *buffer);
  22. typedef void (* net_tcp_disconnected_callback)(void *tcp_conn, int8_t errno);
  23. struct pando_tcp_conn {
  24. uint8_t secure;
  25. uint32_t remote_ip;
  26. uint16_t remote_port;
  27. uint32_t local_ip;
  28. uint16_t local_port;
  29. uint16_t fd;
  30. net_tcp_connected_callback connected_callback;
  31. net_tcp_recv_callback recv_callback;
  32. net_tcp_sent_callback sent_callback;
  33. net_tcp_disconnected_callback disconnected_callback;
  34. void *reverse;
  35. };
  36. /******************************************************************************
  37. * FunctionName : net_tcp_connect
  38. * Description : The function given as the connect
  39. * Parameters : addr: the address used to listen the connection
  40. * timeout: the connect timeout set value.
  41. * Returns : none
  42. *******************************************************************************/
  43. void net_tcp_connect(struct pando_tcp_conn *conn, uint16_t timeout);
  44. /******************************************************************************
  45. * FunctionName : net_tcp_register_connect_callback
  46. * Description : it is used to specify the function that should be called when connected.
  47. * Parameters : connected_cb: the specify function.
  48. * Returns : none
  49. *******************************************************************************/
  50. void net_tcp_register_connected_callback(struct pando_tcp_conn *conn , net_tcp_connected_callback connected_cb);
  51. /******************************************************************************
  52. * FunctionName : net_tcp_send
  53. * Description : The tcp send function.
  54. * Parameters : buf: the data buffer to send.
  55. * timeout: the sent timeout set value.
  56. * Returns : none
  57. *******************************************************************************/
  58. void net_tcp_send(struct pando_tcp_conn *conn, struct data_buf buffer, uint16_t timeout);
  59. /******************************************************************************
  60. * FunctionName : net_tcp_register_sent_callback
  61. * Description : it is used to specify the function that should be called when sent.
  62. * Parameters : connected_cb: the specify function.
  63. * Returns : none
  64. *******************************************************************************/
  65. void net_tcp_register_sent_callback(struct pando_tcp_conn *conn, net_tcp_sent_callback sent_cb);
  66. /******************************************************************************
  67. * FunctionName : net_tcp_register_recv_callback
  68. * Description : it is used to specify the function that should be called when received.
  69. * Parameters : recv_cb: the specify function.
  70. * Returns : none
  71. *******************************************************************************/
  72. void net_tcp_register_recv_callback(struct pando_tcp_conn *conn, net_tcp_recv_callback recv_cb);
  73. /******************************************************************************
  74. * FunctionName : net_tcp_disconnect
  75. * Description : it is used to disconnect the connect.
  76. * Parameters : none.
  77. * Returns : none
  78. *******************************************************************************/
  79. void net_tcp_disconnect(struct pando_tcp_conn *conn);
  80. /******************************************************************************
  81. * FunctionName : net_tcp_register_disconnected_callback
  82. * Description : it is used to specify the function that should be called when disconnected.
  83. * Parameters : connected_cb: the specify function.
  84. * Returns : none
  85. *******************************************************************************/
  86. void net_tcp_register_disconnected_callback(struct pando_tcp_conn *conn, net_tcp_disconnected_callback disconnected_cb);
  87. /******************************************************************************
  88. * FunctionName : net_tcp_seriver_listen
  89. * Description : it is used to specify the function that should be called when disconnected.
  90. * Parameters : addr: the listen addr.
  91. * Returns : the listen result.
  92. *******************************************************************************/
  93. int8_t net_tcp_server_listen(struct pando_tcp_conn *conn);
  94. /******************************************************************************
  95. * FunctionName : net_tcp_server_accept
  96. * Description : accept the connect.
  97. * Parameters : conn: the accept parameter.
  98. * Returns : none
  99. *******************************************************************************/
  100. void net_tcp_server_accept(struct pando_tcp_conn *conn);
  101. #endif /* _PANDO_NET_TCP_H_ */