patacongo commented on issue #1639:
URL:
https://github.com/apache/incubator-nuttx/issues/1639#issuecomment-682163587
>
>
> What If we don't change `sock_intf_s` would you be open to having multiple
versions for the different socket protocols. The reason being that the HCI
socket is very different than L2CAP. For example it does not support
connections. The code is going to get really ugly handling both of these in the
same place. This is further complicated because with the bind there are then
multiple "channels" defined inside the address which changes how the writes and
reads are handled.
>
> If we store the protocol inside the socket struct it is fairly easy to
handle the ioctl and socket option calls without changing sock_intf_s.
>
> ```
> FAR const struct sock_intf_s *
> net_sockif(sa_family_t family, int type, int protocol)
> {
> FAR const struct sock_intf_s *sockif = NULL;
> switch (family)
> {
> #ifdef CONFIG_NET_BLUETOOTH
> case PF_BLUETOOTH:
> switch (protocol)
> {
> case BTPROTO_HCI:
> sockif = &g_bluetooth_hcisockif;
> break
> case BTPROTO_L2CAP:
> default:
> sockif = &g_bluetooth_sockif;
> break
> }
> break;
> #endif
> default:
> nerr("ERROR: Address family unsupported: %d\n", family);
> }
> return sockif;
> }
> ```
All sockets support connection, even connection-less sockets like UDP. When
you connect a UDP socket it just remembers the peer address so that you can use
recv() instead of recvfrom().
The current L2CAP sockets are currently only connection-less, raw sockets so
I am not sure what are getting at exactly. See net/bluetooth/bluetooth_sockif.c:
189 if (psock->s_type == SOCK_RAW)
190 {
191 return bluetooth_sockif_alloc(psock);
192 }
193 else
194 {
195 return -EPROTONOSUPPORT;
196 }
Connected L2CAP sockets are not supported. That would, indeed, probably
have to be implemented in the net/ layer.
What you suggest a reasonable thing to do if you believe that the network
layer needs to make a distinction between the protocols. That is basically
how many of the other sockets work as well. Like PF_INET and PF_INET6 with
SOCK_DGRAM or SOCK_STREAM.
It would make sense for the protocol to be stored in struct socket because
that is common to all address families. But the address specific channel would
need to be saved in the struct bluetooth_conn_s that is linked with the struct
socket instance.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]