* [Bluez-devel] select(2) or read(2) on bluetooth sockets not working correctly?
@ 2007-11-15 14:15 Pawel Kot
2007-11-15 18:00 ` Marcel Holtmann
2007-11-18 21:27 ` Pawel Kot
0 siblings, 2 replies; 4+ messages in thread
From: Pawel Kot @ 2007-11-15 14:15 UTC (permalink / raw)
To: bluez-devel
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
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [Bluez-devel] select(2) or read(2) on bluetooth sockets not working correctly?
2007-11-15 14:15 [Bluez-devel] select(2) or read(2) on bluetooth sockets not working correctly? Pawel Kot
@ 2007-11-15 18:00 ` Marcel Holtmann
2007-11-18 21:27 ` Pawel Kot
1 sibling, 0 replies; 4+ messages in thread
From: Marcel Holtmann @ 2007-11-15 18:00 UTC (permalink / raw)
To: BlueZ development
Hi Pawel,
> 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).
which kernel version? Can you construct a simple demo program that shows
this effect easily with a 2.6.24-rc2 kernel?
Regards
Marcel
-------------------------------------------------------------------------
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
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [Bluez-devel] select(2) or read(2) on bluetooth sockets not working correctly?
2007-11-15 14:15 [Bluez-devel] select(2) or read(2) on bluetooth sockets not working correctly? Pawel Kot
2007-11-15 18:00 ` Marcel Holtmann
@ 2007-11-18 21:27 ` Pawel Kot
2007-11-26 9:14 ` Marcel Holtmann
1 sibling, 1 reply; 4+ messages in thread
From: Pawel Kot @ 2007-11-18 21:27 UTC (permalink / raw)
To: bluez-devel
Hi,
I have put simple program demonstrating the problem at
http://tfuj.pl/gnokii/bt.c with compilation hints and usage.
The testing I did was on Ubuntu kernels, so that's for sure not the
recent one, but I think it is really easy to reproduce if the problem
still persists.
You may catch me on #bluez if needed.
take care,
pkot
PS. I'm really not subscribed, so please Cc on reply.
--
Pawel Kot
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Bluez-devel] select(2) or read(2) on bluetooth sockets not working correctly?
2007-11-18 21:27 ` Pawel Kot
@ 2007-11-26 9:14 ` Marcel Holtmann
0 siblings, 0 replies; 4+ messages in thread
From: Marcel Holtmann @ 2007-11-26 9:14 UTC (permalink / raw)
To: BlueZ development
Hi Pawel,
> I have put simple program demonstrating the problem at
> http://tfuj.pl/gnokii/bt.c with compilation hints and usage.
> The testing I did was on Ubuntu kernels, so that's for sure not the
> recent one, but I think it is really easy to reproduce if the problem
> still persists.
this from the select() manual page:
Those listed in readfds will be watched to see if characters become
available for reading (more precisely, to see if a read will not
block; in particular, a file descriptor is also ready on end-of-file)
If a device disconnects or gets out of range, it is considered to be an
end of file situation. It might help to also watch the exceptfds for the
hangup signal. The read() should return an error if the connection has
been terminated. So that part is strange.
It means that if you connect, then poweroff and then call read() you
would see the same effect. The read() command will block. Can you
confirm this?
Regards
Marcel
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-11-26 9:14 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-15 14:15 [Bluez-devel] select(2) or read(2) on bluetooth sockets not working correctly? Pawel Kot
2007-11-15 18:00 ` Marcel Holtmann
2007-11-18 21:27 ` Pawel Kot
2007-11-26 9:14 ` Marcel Holtmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox