From: "Pawel Kot" <gnokii@gmail.com>
To: bluez-devel@lists.sourceforge.net
Subject: [Bluez-devel] select(2) or read(2) on bluetooth sockets not working correctly?
Date: Thu, 15 Nov 2007 15:15:53 +0100 [thread overview]
Message-ID: <a96155200711150615q38dcf09g140d2386830e9e23@mail.gmail.com> (raw)
Hi,
In gnokii project, we use Bluetooth sockets as one of the phone
communication medium. We use it in quite usual way (simplified code):
fd = socket(PF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
[...]
bind(fd, (struct sockaddr *)&laddr, sizeof(laddr));
[...]
connect(fd, (struct sockaddr *)&raddr, sizeof(raddr));
Then we have (simplified code again):
while (1) {
[...]
write(fd, write_buf, size);
[...]
FD_ZERO(&readfds);
FD_SET(fd, &readfds);
if (select(fd + 1, &readfds, NULL, NULL, &timeout) > 0) {
read(fd, read_buf, size);
[...]
}
[...]
}
The problem is (or rather was) that then bluetooth device gets out of
range (or bluetooth gets disabled in the device) the program hangs on
read(2). So select(2) went OK and told us that there's something to be
read, but actually nothing can be read. According to select(2) manual
page, after the successful select(2), read(2) should not hang (it may
fail though).
It can be workarounded by setting O_NONBLOCK flag on the socket, but
still I consider it as a bug that read(2) hangs after successful
select(2).
take care,
pkot
PS. Please Cc me on replies.
--
Pawel Kot
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
next reply other threads:[~2007-11-15 14:15 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-15 14:15 Pawel Kot [this message]
2007-11-15 18:00 ` [Bluez-devel] select(2) or read(2) on bluetooth sockets not working correctly? Marcel Holtmann
2007-11-18 21:27 ` Pawel Kot
2007-11-26 9:14 ` Marcel Holtmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a96155200711150615q38dcf09g140d2386830e9e23@mail.gmail.com \
--to=gnokii@gmail.com \
--cc=bluez-devel@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox