RT-Thread-packages / at_device

AT component porting or samples for different devices
Apache License 2.0
214 stars 181 forks source link

Support alloc socket dynamically #126

Closed luhuadong closed 4 years ago

luhuadong commented 4 years ago

由于部分 AT 模块/固件(比如 BC28)在申请 socket 时并不一定从 0 开始,运行过程的其他服务也可能会占用 socket(比如 DNS 域名解析),因此造成申请的 socket 并不连续。这种情况与 at socket 框架的实现存在冲突,对 at device 的实现造成较大限制。

因此我提出了一种修改方案 #3755,在 at_socket_ops 结构体增加一个成员函数 at_socket,用于申请并返回 AT 设备真实可用的 socket 号,at device 模块可以根据自身情况决定是否需要实现该函数。

同时,为了兼容本次修改,我在 at_device 其他所有设备的 at_socket_ops 构造中均添加了 at_socket 指向 RT_NULL。所以不会影响其他模块的使用。

static const struct at_socket_ops rw007_socket_ops =
{
    RT_NULL,
    rw007_socket_connect,
    rw007_socket_close,
    rw007_socket_send,
    rw007_domain_resolve,
    rw007_socket_set_event_cb,
};
luhuadong commented 4 years ago

已经调整了成员函数的位置,并且在 at_socket_ops 中增加了版本号判断