Return-Path: MIME-Version: 1.0 Date: Mon, 23 Sep 2013 11:04:30 +0200 Message-ID: Subject: Problems with too many connections From: Markus Roppelt To: linux-bluetooth@vger.kernel.org Content-Type: multipart/mixed; boundary=bcaec520ea79d93d0e04e7094ec7 Sender: linux-bluetooth-owner@vger.kernel.org List-ID: --bcaec520ea79d93d0e04e7094ec7 Content-Type: text/plain; charset=ISO-8859-1 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 --bcaec520ea79d93d0e04e7094ec7 Content-Type: text/x-csrc; charset=US-ASCII; name="loop.c" Content-Disposition: attachment; filename="loop.c" Content-Transfer-Encoding: base64 X-Attachment-Id: f_hlxgw1lz0 LyoKICoKICogIEJsdWVaIC0gQmx1ZXRvb3RoIHByb3RvY29sIHN0YWNrIGZvciBMaW51eAogKgog KiAgQ29weXJpZ2h0IChDKSAyMDExICBOb2tpYSBDb3Jwb3JhdGlvbgogKgogKgogKiAgVGhpcyBw cm9ncmFtIGlzIGZyZWUgc29mdHdhcmU7IHlvdSBjYW4gcmVkaXN0cmlidXRlIGl0IGFuZC9vciBt b2RpZnkKICogIGl0IHVuZGVyIHRoZSB0ZXJtcyBvZiB0aGUgR05VIEdlbmVyYWwgUHVibGljIExp Y2Vuc2UgYXMgcHVibGlzaGVkIGJ5CiAqICB0aGUgRnJlZSBTb2Z0d2FyZSBGb3VuZGF0aW9uOyBl aXRoZXIgdmVyc2lvbiAyIG9mIHRoZSBMaWNlbnNlLCBvcgogKiAgKGF0IHlvdXIgb3B0aW9uKSBh bnkgbGF0ZXIgdmVyc2lvbi4KICoKICogIFRoaXMgcHJvZ3JhbSBpcyBk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