2019-10-20 11:09:51

by Ordit Gross

[permalink] [raw]
Subject: mgmt_new_default sometimes fail

hi all,
On our application we used the code sample btmgmt.c
which uses mgmt_new_default, this function will fail if
fd >127 (because mainloop_add_fd will fail in io_new function).

mgmt_new_default:
fd = socket(PF_BLUETOOTH, SOCK_RAW | SOCK_CLOEXEC | SOCK_NONBLOCK, BTPROTO_HCI);

what is the best way to workaround this issue assuming I have only
btmgmt.c code and would rather not change other files?

thanks in advance
Ordit


2019-10-20 17:09:06

by Marcel Holtmann

[permalink] [raw]
Subject: Re: mgmt_new_default sometimes fail

Hi Ordit,

> On our application we used the code sample btmgmt.c
> which uses mgmt_new_default, this function will fail if
> fd >127 (because mainloop_add_fd will fail in io_new function).
>
> mgmt_new_default:
> fd = socket(PF_BLUETOOTH, SOCK_RAW | SOCK_CLOEXEC | SOCK_NONBLOCK, BTPROTO_HCI);
>
> what is the best way to workaround this issue assuming I have only
> btmgmt.c code and would rather not change other files?

because we have #define MAX_MAINLOOP_ENTRIES 128 in the mainloop.c code. I assumed that 127 file descriptors is plenty for what any BlueZ application is doing.

Regards

Marcel