TuyaOS
宏定义 | 函数 | 常量
tal_network.h 文件参考

Common process - Initialization 更多...

#include "tuya_cloud_types.h"
tal_network.h 的引用(Include)关系图:
此图展示该文件直接或间接的被哪些文件引用了:

浏览源代码.

宏定义

#define TAL_FD_CLR(n, p)   tal_net_fd_clear(n, p)
 
#define TAL_FD_ISSET(n, p)   tal_net_fd_isset(n,p)
 
#define TAL_FD_SET(n, p)   tal_net_fd_set(n, p)
 
#define TAL_FD_ZERO(p)   tal_net_fd_zero(p)
 
#define TY_IP6_ADDR_ANY   ty_ip6_addr_any
 
#define TY_IPADDR_ANY   ty_ip_addr_any
 
#define TY_IPADDR_BROADCAST   ty_ip_addr_broadcast
 
#define TY_IPADDR_LOOPBACK   ty_ip_addr_loopback
 

函数

INT_T tal_net_accept (CONST INT_T fd, TUYA_IP_ADDR_T *addr, UINT16_T *port)
 Accept the coming socket connection of the server fd 更多...
 
OPERATE_RET tal_net_add_membership (CONST INT_T fd, TUYA_IP_ADDR_T src_addr, TUYA_IP_ADDR_T group_addr)
 add member ship 更多...
 
CHAR_T * tal_net_addr2str (TUYA_IP_ADDR_T ipaddr)
 Change ip address to string 更多...
 
TUYA_ERRNO tal_net_bind (CONST INT_T fd, CONST TUYA_IP_ADDR_T addr, CONST UINT16_T port)
 Bind to network 更多...
 
TUYA_ERRNO tal_net_close (CONST INT_T fd)
 Close file descriptors 更多...
 
TUYA_ERRNO tal_net_connect (CONST INT_T fd, CONST TUYA_IP_ADDR_T addr, CONST UINT16_T port)
 Connect to network 更多...
 
TUYA_ERRNO tal_net_connect_raw (CONST INT_T fd, VOID_T *p_socket, CONST INT_T len)
 Connect to network with raw data 更多...
 
OPERATE_RET tal_net_disable_nagle (CONST INT_T fd)
 Disable nagle option of socket fd 更多...
 
OPERATE_RET tal_net_fd_clear (INT_T fd, TUYA_FD_SET_T *fds)
 Clear file descriptor from set 更多...
 
OPERATE_RET tal_net_fd_isset (INT_T fd, TUYA_FD_SET_T *fds)
 Check file descriptor is in set 更多...
 
OPERATE_RET tal_net_fd_set (INT_T fd, TUYA_FD_SET_T *fds)
 Add file descriptor to set 更多...
 
OPERATE_RET tal_net_fd_zero (TUYA_FD_SET_T *fds)
 Clear all file descriptor in set 更多...
 
TUYA_ERRNO tal_net_get_errno (VOID)
 Get error code of network 更多...
 
INT_T tal_net_get_nonblock (CONST INT_T fd)
 Get no block file descriptors 更多...
 
OPERATE_RET tal_net_get_socket_ip (INT_T fd, TUYA_IP_ADDR_T *addr)
 Get ip address by socket fd 更多...
 
OPERATE_RET tal_net_gethostbyname (IN CONST CHAR_T *domain, IN CONST DNS_MODE_E mode, OUT TUYA_IP_ADDR_T *addr)
 Get address information by domain 更多...
 
OPERATE_RET tal_net_getsockopt (CONST INT_T fd, CONST TUYA_OPT_LEVEL level, CONST TUYA_OPT_NAME optname, VOID_T *optval, INT_T *optlen)
 Get socket options 更多...
 
TUYA_ERRNO tal_net_listen (CONST INT_T fd, CONST INT_T backlog)
 Listen to network 更多...
 
TUYA_ERRNO tal_net_recv (CONST INT_T fd, VOID_T *buf, CONST UINT_T nbytes)
 Receive data from network 更多...
 
INT_T tal_net_recv_nd_size (CONST INT_T fd, VOID_T *buf, CONST UINT_T buf_size, CONST UINT_T nd_size)
 Receive data from network with need size 更多...
 
TUYA_ERRNO tal_net_recvfrom (CONST INT_T fd, VOID_T *buf, CONST UINT_T nbytes, TUYA_IP_ADDR_T *addr, UINT16_T *port)
 Receive data from specified server 更多...
 
INT_T tal_net_select (CONST INT_T maxfd, TUYA_FD_SET_T *readfds, TUYA_FD_SET_T *writefds, TUYA_FD_SET_T *errorfds, CONST UINT_T ms_timeout)
 Get available file descriptors 更多...
 
TUYA_ERRNO tal_net_send (CONST INT_T fd, CONST VOID_T *buf, CONST UINT_T nbytes)
 Send data to network 更多...
 
TUYA_ERRNO tal_net_send_to (CONST INT_T fd, CONST VOID_T *buf, CONST UINT_T nbytes, CONST TUYA_IP_ADDR_T addr, CONST UINT16_T port)
 Send data to specified server 更多...
 
OPERATE_RET tal_net_set_block (CONST INT_T fd, CONST BOOL_T block)
 Set block flag for file descriptors 更多...
 
OPERATE_RET tal_net_set_broadcast (CONST INT_T fd)
 Enable broadcast option of socket fd 更多...
 
OPERATE_RET tal_net_set_bufsize (CONST INT_T fd, CONST INT_T buf_size, CONST TUYA_TRANS_TYPE_E type)
 Set buffer_size option of socket fd 更多...
 
OPERATE_RET tal_net_set_keepalive (INT_T fd, CONST BOOL_T alive, CONST UINT_T idle, CONST UINT_T intr, CONST UINT_T cnt)
 Set keepalive option of socket fd to monitor the connection 更多...
 
OPERATE_RET tal_net_set_reuse (CONST INT_T fd)
 Enable reuse option of socket fd 更多...
 
OPERATE_RET tal_net_set_timeout (CONST INT_T fd, CONST INT_T ms_timeout, CONST TUYA_TRANS_TYPE_E type)
 Set timeout option of socket fd 更多...
 
OPERATE_RET tal_net_sethostname (CONST CHAR_T *hostname)
 Set the system hostname 更多...
 
OPERATE_RET tal_net_setsockopt (CONST INT_T fd, CONST TUYA_OPT_LEVEL level, CONST TUYA_OPT_NAME optname, CONST VOID_T *optval, CONST INT_T optlen)
 Set socket options 更多...
 
INT_T tal_net_socket_create (CONST TUYA_PROTOCOL_TYPE_E type)
 Create a tcp/udp socket 更多...
 
INT_T tal_net_socket_create_v6 (IN CONST TUYA_PROTOCOL_TYPE_E type)
 Create a IPv6 tcp/udp socket 更多...
 
TUYA_IP_ADDR_T tal_net_str2addr (CONST CHAR_T *ip_str)
 Change ip string to address 更多...
 

常量

const TUYA_IP_ADDR_T ty_ip6_addr_any
 
const TUYA_IP_ADDR_T ty_ip_addr_any
 
const TUYA_IP_ADDR_T ty_ip_addr_broadcast
 
const TUYA_IP_ADDR_T ty_ip_addr_loopback
 

详细描述

Common process - Initialization

版本
0.1
日期
2020-11-09

函数说明

◆ tal_net_accept()

INT_T tal_net_accept ( CONST INT_T  fd,
TUYA_IP_ADDR_T *  addr,
UINT16_T *  port 
)

Accept the coming socket connection of the server fd

参数
[in]fdfile descriptor
[in]addraddress information of server
[in]portport information of server
注解
This API is used for accepting the coming socket connection of the server fd.
返回
>0 the file descriptor, <=0 means failed

◆ tal_net_add_membership()

OPERATE_RET tal_net_add_membership ( CONST INT_T  fd,
TUYA_IP_ADDR_T  src_addr,
TUYA_IP_ADDR_T  group_addr 
)

add member ship

参数
[in]fdsocket id
[in]src_addrsource addr
[in]group_addrgroup addr
返回
0 on success. Others on error, please refer to the error no of the target system

◆ tal_net_addr2str()

CHAR_T * tal_net_addr2str ( TUYA_IP_ADDR_T  ipaddr)

Change ip address to string

参数
[in]ipaddrip address
注解
This API is used to change ip address(in host byte order) to string(in IPv4 numbers-and-dots(xx.xx.xx.xx) notion).
返回
ip string

◆ tal_net_bind()

TUYA_ERRNO tal_net_bind ( CONST INT_T  fd,
CONST TUYA_IP_ADDR_T  addr,
CONST UINT16_T  port 
)

Bind to network

参数
[in]fdfile descriptor
[in]addraddress information of server
[in]portport information of server
注解
This API is used for binding to network.
返回
0 on success. Others on error, please refer to the error no of the target system

◆ tal_net_close()

TUYA_ERRNO tal_net_close ( CONST INT_T  fd)

Close file descriptors

参数
[in]fdfile descriptor
注解
This API is used to close file descriptors.
返回
0 on success. Others on error, please refer to the error no of the target system

◆ tal_net_connect()

TUYA_ERRNO tal_net_connect ( CONST INT_T  fd,
CONST TUYA_IP_ADDR_T  addr,
CONST UINT16_T  port 
)

Connect to network

参数
[in]fdfile descriptor
[in]addraddress information of server
[in]portport information of server
注解
This API is used for connecting to network.
返回
0 on success. Others on error, please refer to the error no of the target system

◆ tal_net_connect_raw()

TUYA_ERRNO tal_net_connect_raw ( CONST INT_T  fd,
VOID_T *  p_socket,
CONST INT_T  len 
)

Connect to network with raw data

参数
[in]fdfile descriptor
[in]p_socketraw socket data
[in]lendata lenth
注解
This API is used for connecting to network with raw data.
返回
0 on success. Others on error, please refer to the error no of the target system

◆ tal_net_disable_nagle()

OPERATE_RET tal_net_disable_nagle ( CONST INT_T  fd)

Disable nagle option of socket fd

参数
[in]fdfile descriptor
注解
This API is used to disable nagle option of socket fd.
返回
OPRT_OK on success. Others on error, please refer to tuya_error_code.h

◆ tal_net_fd_clear()

OPERATE_RET tal_net_fd_clear ( INT_T  fd,
TUYA_FD_SET_T *  fds 
)

Clear file descriptor from set

参数
[in]fdfile descriptor
[in]fdsset of file descriptor
注解
This API is used to clear file descriptor from set.
返回
OPRT_OK on success. Others on error, please refer to tuya_error_code.h

◆ tal_net_fd_isset()

OPERATE_RET tal_net_fd_isset ( INT_T  fd,
TUYA_FD_SET_T *  fds 
)

Check file descriptor is in set

参数
[in]fdfile descriptor
[in]fdsset of file descriptor
注解
This API is used to check the file descriptor is in set.
返回
TRUE or FALSE

◆ tal_net_fd_set()

OPERATE_RET tal_net_fd_set ( INT_T  fd,
TUYA_FD_SET_T *  fds 
)

Add file descriptor to set

参数
[in]fdfile descriptor
[in]fdsset of file descriptor
注解
This API is used to add file descriptor to set.
返回
OPRT_OK on success. Others on error, please refer to tuya_error_code.h

◆ tal_net_fd_zero()

OPERATE_RET tal_net_fd_zero ( TUYA_FD_SET_T *  fds)

Clear all file descriptor in set

参数
[in]fdsset of file descriptor
注解
This API is used to clear all file descriptor in set.
返回
OPRT_OK on success. Others on error, please refer to tuya_error_code.h

◆ tal_net_get_errno()

TUYA_ERRNO tal_net_get_errno ( VOID  )

Get error code of network

参数
void
注解
This API is used for getting error code of network.
返回
UNW_SUCCESS on success. Others on error, please refer to tuya_os_adapter_error_code.h

◆ tal_net_get_nonblock()

INT_T tal_net_get_nonblock ( CONST INT_T  fd)

Get no block file descriptors

参数
[in]fdfile descriptor
注解
This API is used to get no block file descriptors.
返回
>0 the count of no block file descriptors, <=0 error.

◆ tal_net_get_socket_ip()

OPERATE_RET tal_net_get_socket_ip ( INT_T  fd,
TUYA_IP_ADDR_T *  addr 
)

Get ip address by socket fd

参数
[in]fdfile descriptor
[out]addrip address
注解
This API is used for getting ip address by socket fd.
返回
OPRT_OK on success. Others on error, please refer to tuya_error_code.h

◆ tal_net_gethostbyname()

OPERATE_RET tal_net_gethostbyname ( IN CONST CHAR_T *  domain,
IN CONST DNS_MODE_E  mode,
OUT TUYA_IP_ADDR_T *  addr 
)

Get address information by domain

参数
[in]domaindomain information
[in]addraddress information
注解
This API is used for getting address information by domain.
返回
OPRT_OK on success. Others on error, please refer to tuya_error_code.h

◆ tal_net_getsockopt()

OPERATE_RET tal_net_getsockopt ( CONST INT_T  fd,
CONST TUYA_OPT_LEVEL  level,
CONST TUYA_OPT_NAME  optname,
VOID_T *  optval,
INT_T *  optlen 
)

Get socket options

参数
[in]fdfile descriptor
[in]levelgetting level
[in]optnamethe name of the option
[out]optvalthe value of option
[out]optlenthe length of the option value
注解
This API is used for getting socket options.
返回
OPRT_OK on success. Others on error, please refer to tuya_error_code.h

◆ tal_net_listen()

TUYA_ERRNO tal_net_listen ( CONST INT_T  fd,
CONST INT_T  backlog 
)

Listen to network

参数
[in]fdfile descriptor
[in]backlogmax count of backlog connection
注解
This API is used for listening to network.
返回
0 on success. Others on error, please refer to the error no of the target system

◆ tal_net_recv()

TUYA_ERRNO tal_net_recv ( CONST INT_T  fd,
VOID_T *  buf,
CONST UINT_T  nbytes 
)

Receive data from network

参数
[in]fdfile descriptor
[in]bufreceive data buffer
[in]nbytesbuffer lenth
注解
This API is used for receiving data from network
返回
>0 on num of recv, <0 please refer to the error no of the target system

◆ tal_net_recv_nd_size()

INT_T tal_net_recv_nd_size ( CONST INT_T  fd,
VOID_T *  buf,
CONST UINT_T  buf_size,
CONST UINT_T  nd_size 
)

Receive data from network with need size

参数
[in]fdfile descriptor
[in]bufreceive data buffer
[in]nbytesbuffer lenth
[in]nd_sizethe need size
注解
This API is used for receiving data from network with need size
返回
>0 on success. Others on error

◆ tal_net_recvfrom()

TUYA_ERRNO tal_net_recvfrom ( CONST INT_T  fd,
VOID_T *  buf,
CONST UINT_T  nbytes,
TUYA_IP_ADDR_T *  addr,
UINT16_T *  port 
)

Receive data from specified server

参数
[in]fdfile descriptor
[in]bufreceive data buffer
[in]nbytesbuffer lenth
[in]addraddress information of server
[in]portport information of server
注解
This API is used for receiving data from specified server
返回
>0 on num of recv, <0 please refer to the error no of the target system

◆ tal_net_select()

INT_T tal_net_select ( CONST INT_T  maxfd,
TUYA_FD_SET_T *  readfds,
TUYA_FD_SET_T *  writefds,
TUYA_FD_SET_T *  errorfds,
CONST UINT_T  ms_timeout 
)

Get available file descriptors

参数
[in]maxfdmax count of file descriptor
[out]readfdsa set of readalbe file descriptor
[out]writefdsa set of writable file descriptor
[out]errorfdsa set of except file descriptor
[in]ms_timeouttime out
注解
This API is used to get available file descriptors.
返回
>0 the count of available file descriptors, <=0 error.

◆ tal_net_send()

TUYA_ERRNO tal_net_send ( CONST INT_T  fd,
CONST VOID_T *  buf,
CONST UINT_T  nbytes 
)

Send data to network

参数
[in]fdfile descriptor
[in]bufsend data buffer
[in]nbytesbuffer lenth
注解
This API is used for sending data to network
返回
>0 on num of send, <0 please refer to the error no of the target system

◆ tal_net_send_to()

TUYA_ERRNO tal_net_send_to ( CONST INT_T  fd,
CONST VOID_T *  buf,
CONST UINT_T  nbytes,
CONST TUYA_IP_ADDR_T  addr,
CONST UINT16_T  port 
)

Send data to specified server

参数
[in]fdfile descriptor
[in]bufsend data buffer
[in]nbytesbuffer lenth
[in]addraddress information of server
[in]portport information of server
注解
This API is used for sending data to network
返回
>0 on num of send, <0 please refer to the error no of the target system

◆ tal_net_set_block()

OPERATE_RET tal_net_set_block ( CONST INT_T  fd,
CONST BOOL_T  block 
)

Set block flag for file descriptors

参数
[in]fdfile descriptor
[in]blockblock flag
注解
This API is used to set block flag for file descriptors.
返回
OPRT_OK on success. Others on error, please refer to tuya_error_code.h

◆ tal_net_set_broadcast()

OPERATE_RET tal_net_set_broadcast ( CONST INT_T  fd)

Enable broadcast option of socket fd

参数
[in]fdfile descriptor
注解
This API is used to enable broadcast option of socket fd.
返回
OPRT_OK on success. Others on error, please refer to tuya_error_code.h

◆ tal_net_set_bufsize()

OPERATE_RET tal_net_set_bufsize ( CONST INT_T  fd,
CONST INT_T  buf_size,
CONST TUYA_TRANS_TYPE_E  type 
)

Set buffer_size option of socket fd

参数
[in]fdfile descriptor
[in]buf_sizebuffer size in byte
[in]typetransfer type, receive or send
注解
This API is used for setting buffer_size option of socket fd.
返回
OPRT_OK on success. Others on error, please refer to tuya_error_code.h

◆ tal_net_set_keepalive()

OPERATE_RET tal_net_set_keepalive ( INT_T  fd,
CONST BOOL_T  alive,
CONST UINT_T  idle,
CONST UINT_T  intr,
CONST UINT_T  cnt 
)

Set keepalive option of socket fd to monitor the connection

参数
[in]fdfile descriptor
[in]alivekeepalive option, enable or disable option
[in]idlekeep idle option, if the connection has no data exchange with the idle time(in seconds), start probe.
[in]intrkeep interval option, the probe time interval.
[in]cntkeep count option, probe count.
注解
This API is used to set keepalive option of socket fd to monitor the connection.
返回
OPRT_OK on success. Others on error, please refer to tuya_error_code.h

◆ tal_net_set_reuse()

OPERATE_RET tal_net_set_reuse ( CONST INT_T  fd)

Enable reuse option of socket fd

参数
[in]fdfile descriptor
注解
This API is used to enable reuse option of socket fd.
返回
OPRT_OK on success. Others on error, please refer to tuya_error_code.h

◆ tal_net_set_timeout()

OPERATE_RET tal_net_set_timeout ( CONST INT_T  fd,
CONST INT_T  ms_timeout,
CONST TUYA_TRANS_TYPE_E  type 
)

Set timeout option of socket fd

参数
[in]fdfile descriptor
[in]ms_timeouttimeout in ms
[in]typetransfer type, receive or send
注解
This API is used for setting timeout option of socket fd.
返回
OPRT_OK on success. Others on error, please refer to tuya_error_code.h

◆ tal_net_sethostname()

OPERATE_RET tal_net_sethostname ( CONST CHAR_T *  hostname)

Set the system hostname

参数
[in]hostnamehostname to set
注解
This API is used to set the system hostname.
返回
OPRT_OK on success. Others on error, please refer to tuya_error_code.h

◆ tal_net_setsockopt()

OPERATE_RET tal_net_setsockopt ( CONST INT_T  fd,
CONST TUYA_OPT_LEVEL  level,
CONST TUYA_OPT_NAME  optname,
CONST VOID_T *  optval,
CONST INT_T  optlen 
)

Set socket options

参数
[in]fdfile descriptor
[in]levelsetting level
[in]optnamethe name of the option
[in]optvalthe value of option
[in]optlenthe length of the option value
注解
This API is used for setting socket options.
返回
OPRT_OK on success. Others on error, please refer to tuya_error_code.h

◆ tal_net_socket_create()

INT_T tal_net_socket_create ( CONST TUYA_PROTOCOL_TYPE_E  type)

Create a tcp/udp socket

参数
[in]typeprotocol type, tcp or udp
注解
This API is used for creating a tcp/udp socket.
返回
file descriptor

◆ tal_net_socket_create_v6()

INT_T tal_net_socket_create_v6 ( IN CONST TUYA_PROTOCOL_TYPE_E  type)

Create a IPv6 tcp/udp socket

参数
[in]typeprotocol type, tcp or udp
注解
This API is used for creating a tcp/udp socket.
返回
file descriptor

◆ tal_net_str2addr()

TUYA_IP_ADDR_T tal_net_str2addr ( CONST CHAR_T *  ip_str)

Change ip string to address

参数
[in]ip_strip string
注解
This API is used to change ip string to address.
返回
ip address