| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- /*
- * File : netclient.h
- * This file is part of RT-Thread
- * COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Change Logs:
- * Date Author Notes
- * 2018-08-10 never the first version
- */
- #ifndef __netCLIENT_H__
- #define __netCLIENT_H__
- #include "luat_base.h"
- #ifdef LUAT_USE_SSL_MBEDTLS
- #include "mbedtls/ssl.h"
- #include "mbedtls/entropy.h"
- #include "mbedtls/ctr_drbg.h"
- #include "capi.h"
- #endif
- #define NETC_TYPE_TCP 0
- #define NETC_TYPE_UDP 1
- #define NETC_EVENT_CONNECT_OK 1
- #define NETC_EVENT_CONNECT_FAIL 2
- #define NETC_EVENT_RECV 4
- #define NETC_EVENT_ERROR 7
- #define NETC_EVENT_CLOSE 8
- #define NETC_EVENT_END 9
- typedef struct netc_ent {
- int netc_id;
- int lua_ref;
- int event;
- size_t len;
- void* buff;
- }netc_ent_t;
- typedef int (*tpc_cb_t)(netc_ent_t* ent);
- typedef struct netclient
- {
- #ifdef LUAT_USE_SSL_MBEDTLS
- //tls+++
- mbedtls_ssl_context ssl;
- mbedtls_entropy_context entropy;
- mbedtls_ctr_drbg_context ctr_drbg;
- mbedtls_ssl_config config;
- mbedtls_x509_crt cacert;
- mbedtls_x509_crt clicert;
- mbedtls_pk_context pkey;
- Buffer_Struct rx_buffer;
- int keepalive;
- int recvmode;
- uint8_t is_tls;
- uint8_t tls_init;
- //tls---
- #endif
- int id;
- char idStr[10];
- char hostname[64];
- uint32_t ipv4;
- int port;
- int type;
- int closed;
- int sock_fd;
- int pipe_read_fd;
- int pipe_write_fd;
- char pipe_name[12];
- tpc_cb_t rx;
- // Lua callback function
- int cb_recv;
- //int cb_close;
- int cb_connect;
- int cb_any;
- int cb_error;
- int self_ref;
- }netclient_t;
- uint32_t netc_next_no(void);
- //netclient_t *netclient_create(void);
- int32_t netclient_start(netclient_t * thiz);
- int32_t netclient_rebind(netclient_t * thiz);
- void netclient_close(netclient_t *thiz);
- //int32_t netclient_attach_rx_cb(netclient_t *thiz, tpc_cb_t cb);
- int32_t netclient_send(netclient_t *thiz, const void *buff, size_t len, int flags);
- #endif
|