netclient.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. #ifdef LUAT_USE_SSL_MBEDTLS
  28. #include "mbedtls/ssl.h"
  29. #include "mbedtls/entropy.h"
  30. #include "mbedtls/ctr_drbg.h"
  31. #include "capi.h"
  32. #endif
  33. #define NETC_TYPE_TCP 0
  34. #define NETC_TYPE_UDP 1
  35. #define NETC_EVENT_CONNECT_OK 1
  36. #define NETC_EVENT_CONNECT_FAIL 2
  37. #define NETC_EVENT_RECV 4
  38. #define NETC_EVENT_ERROR 7
  39. #define NETC_EVENT_CLOSE 8
  40. #define NETC_EVENT_END 9
  41. typedef struct netc_ent {
  42. int netc_id;
  43. int lua_ref;
  44. int event;
  45. size_t len;
  46. void* buff;
  47. }netc_ent_t;
  48. typedef int (*tpc_cb_t)(netc_ent_t* ent);
  49. typedef struct netclient
  50. {
  51. #ifdef LUAT_USE_SSL_MBEDTLS
  52. //tls+++
  53. mbedtls_ssl_context ssl;
  54. mbedtls_entropy_context entropy;
  55. mbedtls_ctr_drbg_context ctr_drbg;
  56. mbedtls_ssl_config config;
  57. mbedtls_x509_crt cacert;
  58. mbedtls_x509_crt clicert;
  59. mbedtls_pk_context pkey;
  60. Buffer_Struct rx_buffer;
  61. int keepalive;
  62. int recvmode;
  63. uint8_t is_tls;
  64. uint8_t tls_init;
  65. //tls---
  66. #endif
  67. int id;
  68. char idStr[10];
  69. char hostname[64];
  70. uint32_t ipv4;
  71. int port;
  72. int type;
  73. int closed;
  74. int sock_fd;
  75. int pipe_read_fd;
  76. int pipe_write_fd;
  77. char pipe_name[12];
  78. tpc_cb_t rx;
  79. // Lua callback function
  80. int cb_recv;
  81. //int cb_close;
  82. int cb_connect;
  83. int cb_any;
  84. int cb_error;
  85. int self_ref;
  86. }netclient_t;
  87. uint32_t netc_next_no(void);
  88. //netclient_t *netclient_create(void);
  89. int32_t netclient_start(netclient_t * thiz);
  90. int32_t netclient_rebind(netclient_t * thiz);
  91. void netclient_close(netclient_t *thiz);
  92. //int32_t netclient_attach_rx_cb(netclient_t *thiz, tpc_cb_t cb);
  93. int32_t netclient_send(netclient_t *thiz, const void *buff, size_t len, int flags);
  94. #endif