netclient.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * File : netclient.h
  3. * This file is part of RT-Thread
  4. * COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2018-08-10 never the first version
  23. */
  24. #ifndef __netCLIENT_H__
  25. #define __netCLIENT_H__
  26. #include "luat_base.h"
  27. #define NETC_TYPE_TCP 0
  28. #define NETC_TYPE_UDP 1
  29. #define NETC_EVENT_CONNECT_OK 1
  30. #define NETC_EVENT_CONNECT_FAIL 2
  31. #define NETC_EVENT_RECV 4
  32. #define NETC_EVENT_ERROR 7
  33. //#define NETC_EVENT_CLOSE 8
  34. #define NETC_EVENT_END 9
  35. typedef struct netc_ent {
  36. int netc_id;
  37. int lua_ref;
  38. int event;
  39. size_t len;
  40. void* buff;
  41. }netc_ent_t;
  42. typedef int (*tpc_cb_t)(netc_ent_t* ent);
  43. typedef struct netclient
  44. {
  45. int id;
  46. char idStr[10];
  47. char hostname[64];
  48. uint32_t ipv4;
  49. int port;
  50. int type;
  51. int closed;
  52. int sock_fd;
  53. int pipe_read_fd;
  54. int pipe_write_fd;
  55. char pipe_name[12];
  56. tpc_cb_t rx;
  57. // Lua callback function
  58. int cb_recv;
  59. //int cb_close;
  60. int cb_connect;
  61. int cb_any;
  62. int cb_error;
  63. int self_ref;
  64. }netclient_t;
  65. uint32_t netc_next_no(void);
  66. //netclient_t *netclient_create(void);
  67. int32_t netclient_start(netclient_t * thiz);
  68. int32_t netclient_rebind(netclient_t * thiz);
  69. void netclient_close(netclient_t *thiz);
  70. //int32_t netclient_attach_rx_cb(netclient_t *thiz, tpc_cb_t cb);
  71. int32_t netclient_send(netclient_t *thiz, const void *buff, size_t len, int flags);
  72. #endif