public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* [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

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