add support for connect with socket buffer size
This commit is contained in:
@@ -21,16 +21,16 @@
|
||||
#include "tos_k.h"
|
||||
#include "tos_hal.h"
|
||||
|
||||
#define AT_DATA_CHANNEL_NUM 6
|
||||
#define AT_DATA_CHANNEL_FIFO_BUFFER_SIZE (2048 + 1024)
|
||||
#define AT_DATA_CHANNEL_NUM 6
|
||||
#define AT_DATA_CHANNEL_FIFO_BUFFER_DEFAULT_SIZE (2048 + 1024)
|
||||
|
||||
#define AT_UART_RX_FIFO_BUFFER_SIZE (2048 + 1024)
|
||||
#define AT_RECV_CACHE_SIZE 2048
|
||||
#define AT_UART_RX_FIFO_BUFFER_SIZE (2048 + 1024)
|
||||
#define AT_RECV_CACHE_SIZE 2048
|
||||
|
||||
#define AT_CMD_BUFFER_SIZE 512
|
||||
#define AT_CMD_BUFFER_SIZE 512
|
||||
|
||||
#define AT_PARSER_TASK_STACK_SIZE 2048
|
||||
#define AT_PARSER_TASK_PRIO 2
|
||||
#define AT_PARSER_TASK_STACK_SIZE 2048
|
||||
#define AT_PARSER_TASK_PRIO 2
|
||||
|
||||
typedef enum at_status_en {
|
||||
AT_STATUS_OK,
|
||||
@@ -210,6 +210,23 @@ __API__ int tos_at_channel_alloc_id(int channel_id, const char *ip, const char *
|
||||
*/
|
||||
__API__ int tos_at_channel_alloc(const char *ip, const char *port);
|
||||
|
||||
/**
|
||||
* @brief Allocate a channel.
|
||||
* Allocate a channel with certain socket buffer size.
|
||||
*
|
||||
* @attention None
|
||||
*
|
||||
* @param[in] channel_id id of the channel.
|
||||
* @param[in] ip remote ip of the channel.
|
||||
* @param[in] port remote port of the channel.
|
||||
* @param[in] socket_buffer_size buffer size of the channel.
|
||||
*
|
||||
* @return errcode
|
||||
* @retval -1 allocate failed(error).
|
||||
* @retval none -1 the id of the channel.
|
||||
*/
|
||||
__API__ int tos_at_channel_alloc_with_size(const char *ip, const char *port, size_t socket_buffer_size);
|
||||
|
||||
/**
|
||||
* @brief Free a channel.
|
||||
* Free a channel with certain id.
|
||||
@@ -458,7 +475,7 @@ __API__ int tos_at_uart_drain(uint8_t *buffer, size_t buffer_len);
|
||||
*
|
||||
* @return remote ip of the channel.
|
||||
*/
|
||||
__API__ const char *tos_at_agent_channel_ip_get(int channel_id);
|
||||
__API__ const char *tos_at_channel_ip_get(int channel_id);
|
||||
|
||||
/**
|
||||
* @brief Get the remote port of a channel.
|
||||
@@ -470,7 +487,7 @@ __API__ const char *tos_at_agent_channel_ip_get(int channel_id);
|
||||
*
|
||||
* @return remote port of the channel.
|
||||
*/
|
||||
__API__ const char *tos_at_agent_channel_port_get(int channel_id);
|
||||
__API__ const char *tos_at_channel_port_get(int channel_id);
|
||||
|
||||
#endif /* _TOS_AT_H_ */
|
||||
|
||||
|
@@ -701,11 +701,12 @@ __API__ int tos_at_channel_write(int channel_id, uint8_t *buffer, size_t buffer_
|
||||
return ret;
|
||||
}
|
||||
|
||||
__STATIC_INLINE__ int at_channel_construct(at_data_channel_t *data_channel, const char *ip, const char *port)
|
||||
__STATIC_INLINE__ int at_channel_construct(at_data_channel_t *data_channel, const char *ip, const char *port, size_t socket_buffer_size)
|
||||
{
|
||||
uint8_t *fifo_buffer = K_NULL;
|
||||
|
||||
fifo_buffer = tos_mmheap_alloc(AT_DATA_CHANNEL_FIFO_BUFFER_SIZE);
|
||||
|
||||
fifo_buffer = tos_mmheap_alloc(socket_buffer_size);
|
||||
|
||||
if (!fifo_buffer) {
|
||||
return -1;
|
||||
}
|
||||
@@ -719,7 +720,7 @@ __STATIC_INLINE__ int at_channel_construct(at_data_channel_t *data_channel, cons
|
||||
}
|
||||
|
||||
data_channel->rx_fifo_buffer = fifo_buffer;
|
||||
tos_chr_fifo_create(&data_channel->rx_fifo, fifo_buffer, AT_DATA_CHANNEL_FIFO_BUFFER_SIZE);
|
||||
tos_chr_fifo_create(&data_channel->rx_fifo, fifo_buffer, socket_buffer_size);
|
||||
data_channel->remote_ip = ip;
|
||||
data_channel->remote_port = port;
|
||||
|
||||
@@ -736,13 +737,15 @@ errout:
|
||||
__API__ int tos_at_channel_alloc_id(int channel_id, const char *ip, const char *port)
|
||||
{
|
||||
at_data_channel_t *data_channel = K_NULL;
|
||||
size_t socket_buffer_size = 0;
|
||||
|
||||
data_channel = at_channel_get(channel_id, K_TRUE);
|
||||
if (!data_channel) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (at_channel_construct(data_channel, ip, port) != 0) {
|
||||
socket_buffer_size = AT_DATA_CHANNEL_FIFO_BUFFER_DEFAULT_SIZE;
|
||||
if (at_channel_construct(data_channel, ip, port, socket_buffer_size) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -750,6 +753,31 @@ __API__ int tos_at_channel_alloc_id(int channel_id, const char *ip, const char *
|
||||
}
|
||||
|
||||
__API__ int tos_at_channel_alloc(const char *ip, const char *port)
|
||||
{
|
||||
int id = 0;
|
||||
at_data_channel_t *data_channel = K_NULL;
|
||||
size_t socket_buffer_size = 0;
|
||||
|
||||
for (id = 0; id < AT_DATA_CHANNEL_NUM; ++id) {
|
||||
data_channel = &AT_AGENT->data_channel[id];
|
||||
if (data_channel->is_free) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (id == AT_DATA_CHANNEL_NUM || !data_channel) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
socket_buffer_size = AT_DATA_CHANNEL_FIFO_BUFFER_DEFAULT_SIZE;
|
||||
if (at_channel_construct(data_channel, ip, port, socket_buffer_size) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
__API__ int tos_at_channel_alloc_with_size(const char *ip, const char *port, size_t socket_buffer_size)
|
||||
{
|
||||
int id = 0;
|
||||
at_data_channel_t *data_channel = K_NULL;
|
||||
@@ -765,7 +793,7 @@ __API__ int tos_at_channel_alloc(const char *ip, const char *port)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (at_channel_construct(data_channel, ip, port) != 0) {
|
||||
if (at_channel_construct(data_channel, ip, port, socket_buffer_size) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -846,7 +874,7 @@ __API__ const char *tos_at_channel_ip_get(int channel_id)
|
||||
return K_NULL;
|
||||
}
|
||||
|
||||
return data_channel[channel_id].remote_ip;
|
||||
return data_channel->remote_ip;
|
||||
}
|
||||
|
||||
__API__ const char *tos_at_channel_port_get(int channel_id)
|
||||
@@ -858,7 +886,7 @@ __API__ const char *tos_at_channel_port_get(int channel_id)
|
||||
return K_NULL;
|
||||
}
|
||||
|
||||
return data_channel[channel_id].remote_port;
|
||||
return data_channel->remote_port;
|
||||
}
|
||||
|
||||
__STATIC__ void at_event_table_set(at_event_t *event_table, size_t event_table_size)
|
||||
|
@@ -43,6 +43,14 @@ int tos_sal_module_connect(const char *ip, const char *port, sal_proto_t proto)
|
||||
return -1;
|
||||
}
|
||||
|
||||
int tos_sal_module_connect_with_size(const char *ip, const char *port, sal_proto_t proto, size_t socket_buffer_size)
|
||||
{
|
||||
if (g_sal_module && g_sal_module->connect_with_size) {
|
||||
return g_sal_module->connect_with_size(ip, port, proto, socket_buffer_size);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int tos_sal_module_send(int sock, const void *buf, size_t len)
|
||||
{
|
||||
if (g_sal_module && g_sal_module->send) {
|
||||
|
@@ -37,6 +37,8 @@ typedef struct sal_module_st {
|
||||
|
||||
int (*connect)(const char *ip, const char *port, sal_proto_t proto);
|
||||
|
||||
int (*connect_with_size)(const char *ip, const char *port, sal_proto_t proto, size_t socket_buffer_size);
|
||||
|
||||
int (*send)(int sock, const void *buf, size_t len);
|
||||
|
||||
int (*recv_timeout)(int sock, void *buf, size_t len, uint32_t timeout);
|
||||
@@ -109,6 +111,20 @@ int tos_sal_module_parse_domain(const char *host_name, char *host_ip, size_t hos
|
||||
*/
|
||||
int tos_sal_module_connect(const char *ip, const char *port, sal_proto_t proto);
|
||||
|
||||
/**
|
||||
* @brief Connect to remote host with socket buffer size.
|
||||
*
|
||||
* @attention None
|
||||
*
|
||||
* @param[in] ip ip address of the remote host
|
||||
* @param[in] port port number of the remote host
|
||||
* @param[in] proto protocol of the connection(TCP/UDP)
|
||||
* @param[in] socket_buffer_size the buffer size of the socket
|
||||
*
|
||||
* @return socket id if succuss, -1 if failed.
|
||||
*/
|
||||
int tos_sal_module_connect_with_size(const char *ip, const char *port, sal_proto_t proto, size_t socket_buffer_size);
|
||||
|
||||
/**
|
||||
* @brief Send data to the remote host(TCP).
|
||||
*
|
||||
|
Reference in New Issue
Block a user