espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
12.86k stars 7.08k forks source link

BT VFS SPP should use errno 'EWOULDBLOCK' (IDFGH-13060) #14005

Open LucasSaintrain opened 1 week ago

LucasSaintrain commented 1 week ago

Is your feature request related to a problem?

I'm using the Bluetooth Classic SPP profile provided by esp-idf bluedroid, in VFS mode.

The VFS mode allows the user to mak non-blocking calls to read() write() and close() functions. I expected the interface to behave just like fd streams or sockets opened with the O_NONBLOCK flag, but this is not the case.

Assume the call "len = read(fd, ...);"

Expected: if the user disconnected: len=0 if there's no data available: len=-1 and errno=EWOULDBLOCK

BT SPP VFS: if the user disconnected: nothing if there's no data available: len=0

This divergence divergence doesn't allow SPP fds to be used like normal fds.

In my current project, for example, I use both TCP sockets and SPP fds in two separate arrays. Since they work differently, I need to have some almost duplicate code to treat the inputs.

Describe the solution you'd like.

The bluetooth SPP VFS should set len=-1 and errno=EWOULDBLOCK when no data is available.

It would also be interesting to have a VFS blocking mode for the SPP API.

Describe alternatives you've considered.

No response

Additional context.

No response

Alvin1Zhang commented 1 week ago

Thanks for reporting.