2013-09-23 09:04:30

by Markus Roppelt

[permalink] [raw]
Subject: Problems with too many connections

Hi,

I want to write an application which repeats the following procedure
for several (100+) bluetooth (low energy) devices:

1. connect
2. read register values
3. disconnect

Therefore I modified the source code from /attrib/interactive.c. For
testing purposes I am only looping over one device. See attached
source code.

The code works fine. It connects, reads the values and disconnects.
However, after 1020 repetitions, the following error occurs:
(process:10205): GLib-WARNING **: poll(2) failed due to: Invalid argument.

I think the problem has to do with some sockets / file descriptors not
being closed properly.

Can someone help me to get this fixed?

Thank you
Markus


Attachments:
loop.c (22.14 kB)

2013-09-27 01:53:00

by Marcel Holtmann

[permalink] [raw]
Subject: Re: Problems with too many connections

Hi Markus,

> I want to write an application which repeats the following procedure
> for several (100+) bluetooth (low energy) devices:
>
> 1. connect
> 2. read register values
> 3. disconnect
>
> Therefore I modified the source code from /attrib/interactive.c. For
> testing purposes I am only looping over one device. See attached
> source code.
>
> The code works fine. It connects, reads the values and disconnects.
> However, after 1020 repetitions, the following error occurs:
> (process:10205): GLib-WARNING **: poll(2) failed due to: Invalid argument.
>
> I think the problem has to do with some sockets / file descriptors not
> being closed properly.
>
> Can someone help me to get this fixed?

have you considered trying to write this from scratch and not basing this off existing code.

And yes, this will be most likely an issues with GSource handling of the attribute IO channel, but since you hacked the code is extremely hard to debug. It was never designed for what you are doing.

Regards

Marcel


2013-11-12 08:29:49

by Markus Roppelt

[permalink] [raw]
Subject: Re: Problems with too many connections

2013/9/27 Marcel Holtmann <[email protected]>
>
> Hi Markus,
>
> > I want to write an application which repeats the following procedure
> > for several (100+) bluetooth (low energy) devices:
> >
> > 1. connect
> > 2. read register values
> > 3. disconnect
> >
> > Therefore I modified the source code from /attrib/interactive.c. For
> > testing purposes I am only looping over one device. See attached
> > source code.
> >
> > The code works fine. It connects, reads the values and disconnects.
> > However, after 1020 repetitions, the following error occurs:
> > (process:10205): GLib-WARNING **: poll(2) failed due to: Invalid argument.
> >
> > I think the problem has to do with some sockets / file descriptors not
> > being closed properly.
> >
> > Can someone help me to get this fixed?
>
> have you considered trying to write this from scratch and not basing this off existing code.
>
> And yes, this will be most likely an issues with GSource handling of the attribute IO channel, but since you hacked the code is extremely hard to debug. It was never designed for what you are doing.
>
> Regards
>
> Marcel
>

I found a solution myself. I quote from:
https://github.com/webOS-ports/nyx-modules/commit/bbcbbd64000ba76f39215e43a5179408ff96e097

"When a watch is added to the
glib mainloop it references internally a file descriptor to pass it
later to the poll
function (see poll(2)). Every watch gets an id which should be used by
the user to refer
to the watch whenever needed. When the io channel is destroyed the
watch should be remove
from the mainloop as well. If this isn't done probably by the user it
will cause the
internal list of fds which are passed to the poll function to exceed
the maximum of 256.
This finally results in poll returning EINVAL as error code."

With the additions from there my code runs without problems.

Greetings
Markus