硬汉嵌入式论坛

 找回密码
 立即注册
查看: 3225|回复: 2
收起左侧

[RL-TCPnet] 关于tcp_get_socket的回调函数返回值

[复制链接]

23

主题

213

回帖

282

积分

高级会员

积分
282
发表于 2019-4-29 16:04:16 | 显示全部楼层 |阅读模式
硬汉你好,这两天一直纠结处理tcp数据到底该用例程里的回调方式,还是阻塞读取模式,给个建议吧。

还有,看到tcp_get_socket的回调函数tcp_callback,为什么会有返回函值?是由系统去判断么?官方文档里只说了0和1的区别,没说有什么后果啊,也搜不到调用的地方
Return Value
The tcp_get_socket function returns the handle of the allocated TCP socket. If the function could not allocate a socket, it returns 0.

回复

使用道具 举报

36

主题

1449

回帖

1557

积分

至尊会员

积分
1557
发表于 2019-4-29 19:33:22 | 显示全部楼层
1.建议回调方式,因为V4.74版本的,如果采用阻塞方式读取的话,将会限制发送。就是说等待接收的过程中,是没法进行数据的发送的。最新版本无限制。
2.TCPnet uses the return value of the callback function listener only when the event is TCP_EVT_CONREQ. It uses the return value to decide whether to accept or reject an incoming connection when the TCP socket is listening. If the listener function returns 1, TCPnet accepts the incoming connection. If the listener function returns 0, TCPnet rejects the incoming connection. You can thus define the listener function to selectively reject incoming connections from particular IP addresses.
只有当事件为tcp_evt_conreq时,tcpnet才使用回调函数listener的返回值。它使用返回值来决定在TCP套接字侦听时是否接受或拒绝传入连接。如果listener函数返回1,tcpnet接受传入连接。如果listener函数返回0,tcpnet将拒绝传入连接。因此,您可以定义listener函数来有选择地拒绝来自特定IP地址的传入连接。(译文来自百度翻译)
回复

使用道具 举报

23

主题

213

回帖

282

积分

高级会员

积分
282
 楼主| 发表于 2019-4-29 23:11:18 | 显示全部楼层
sanit 发表于 2019-4-29 19:33
1.建议回调方式,因为V4.74版本的,如果采用阻塞方式读取的话,将会限制发送。就是说等待接收的过程中,是 ...

感谢回复。

因为看到硬汉在“高效框架”例程中用的是阻塞读取的方式,这种方式和我现在用lwip的方式相同。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-6-4 14:58 , Processed in 0.260366 second(s), 24 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表