public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* [Bluez-devel] Problem detecting closed connection
@ 2007-10-03  8:40 Mikael Bengtsson
  2007-10-15  8:54 ` Mikael Bengtsson
  0 siblings, 1 reply; 3+ messages in thread
From: Mikael Bengtsson @ 2007-10-03  8:40 UTC (permalink / raw)
  To: bluez-devel


[-- Attachment #1.1: Type: text/plain, Size: 792 bytes --]


Hello!
 
I have a problem detecting a device that has closed it's connection.
 
The software I'm developing sends and receives data through sockets to a slave device. When I switch of the slave device I expect that send and receive should return the value 0, as in ordinary sockets programming for TCP and UDP sockets. But instead send happily always returns a value which is bigger than 0. Why? Shouldn't Bluetooth sockets behave the same way as ordinary sockets? I have a quite old Bluez, version 2.15. Is there another way of detecting closed connections?
 
Regards:
-Mikael
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/

[-- Attachment #1.2: Type: text/html, Size: 977 bytes --]

[-- Attachment #2: Type: text/plain, Size: 228 bytes --]

-------------------------------------------------------------------------
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/

[-- Attachment #3: Type: text/plain, Size: 164 bytes --]

_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Bluez-devel] Problem detecting closed connection
  2007-10-03  8:40 [Bluez-devel] Problem detecting closed connection Mikael Bengtsson
@ 2007-10-15  8:54 ` Mikael Bengtsson
  2007-10-26  6:22   ` Mikael Bengtsson
  0 siblings, 1 reply; 3+ messages in thread
From: Mikael Bengtsson @ 2007-10-15  8:54 UTC (permalink / raw)
  To: BlueZ development


I have an example of this problem. The following code snippet show a thread that controls a SCO connection. 


...
do
{
     poll_result = poll(ufds, 1, 1000);
     printf("Hello\n");
     if (poll_result == -1)
     {
          printf("Device got POLL-ERROR\n");
     }
     else if (poll_result == 0)
     {
          printf("Timeout\n");
     }
     else if (ufds[0].revents & POLLIN)
     {
         memset(buffer, 0, sizeof(buffer));
         bytes_read = read(ufds[0].fd, buffer, sizeof(buffer));
         printf("bytes_read == %d\n", bytes_read);
         if (bytes_read == 0)
            exit(1);
         ....
     }
} while (poll_result> 0);

Since this is a SCO connection, the read operation will always return 60 bytes every 3.75 ms. I observe that "Hello" and "bytes_read == %60" is written which is correct. When i switch off the slave, "Hello" and "bytes_read = 60" will continue for about 20 about seconds. This is also correct since it may take that long for a connection to be disconnected. After this, only the text "Hello" is written. However, I expected that the timeout event also should occur, that is, poll_result should have returned 0, or that the text "bytes_read == 0" should occur, and in that case the program should end. But the program prints "Hello" endlessly. Why doesn't this work?

I'm thinking of doing a thread with low level checks on the connections, I have two SCO and three ACL connections. This thread may check the connections periodically, but I don't have a clue what low level functions in BlueZ I should use.

I used hcitool to check what happened with a connection when switching off a slave. This program detected a closed connection after about 20 seconds. Maybe I could use something from that program?

-Mikael
________________________________
From: micke_b.b@hotmail.com
To: bluez-devel@lists.sourceforge.net
Date: Wed, 3 Oct 2007 10:40:08 +0200
Subject: [Bluez-devel] Problem detecting closed connection

Hello!

I have a problem detecting a device that has closed it's connection.

The software I'm developing sends and receives data through sockets to a slave device. When I switch of the slave device I expect that send and receive should return the value 0, as in ordinary sockets programming for TCP and UDP sockets. But instead send happily always returns a value which is bigger than 0. Why? Shouldn't Bluetooth sockets behave the same way as ordinary sockets? I have a quite old Bluez, version 2.15. Is there another way of detecting closed connections?

Regards:
-Mikael

________________________________
Express yourself instantly with MSN Messenger! MSN Messenger

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
-------------------------------------------------------------------------
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] 3+ messages in thread

* Re: [Bluez-devel] Problem detecting closed connection
  2007-10-15  8:54 ` Mikael Bengtsson
@ 2007-10-26  6:22   ` Mikael Bengtsson
  0 siblings, 0 replies; 3+ messages in thread
From: Mikael Bengtsson @ 2007-10-26  6:22 UTC (permalink / raw)
  To: BlueZ development


[-- Attachment #1.1: Type: text/plain, Size: 4363 bytes --]


Hello!
 
Am I the only one that have a problem detecting a closed connection? I made workaround in which a thread periodically issues ECHO_REQ with L2CAP to a connected device. If the device doesn't answer within a few seconds the connection is considered down. Unfortunately, this method doesn't always work as it seems. Sometimes there is no reply from the connected device. It could be that the SCO messages "drowns" the reply. What I would like to do, is to use ordinary recv, and if equal to 0, the connection is broken, but it doesn't seem to work. The application just stops and waits on recv, which, in the RFCOMM case, never returns. 
 
The BlueZ I'm using is 2.15 which is running on an Intel Xscale PXA255.
 
-Mikael
> From: micke_b.b@hotmail.com> To: bluez-devel@lists.sourceforge.net> Date: Mon, 15 Oct 2007 10:54:24 +0200> Subject: Re: [Bluez-devel] Problem detecting closed connection> > > I have an example of this problem. The following code snippet show a thread that controls a SCO connection. > > > ...> do> {> poll_result = poll(ufds, 1, 1000);> printf("Hello\n");> if (poll_result == -1)> {> printf("Device got POLL-ERROR\n");> }> else if (poll_result == 0)> {> printf("Timeout\n");> }> else if (ufds[0].revents & POLLIN)> {> memset(buffer, 0, sizeof(buffer));> bytes_read = read(ufds[0].fd, buffer, sizeof(buffer));> printf("bytes_read == %d\n", bytes_read);> if (bytes_read == 0)> exit(1);> ....> }> } while (poll_result> 0);> > Since this is a SCO connection, the read operation will always return 60 bytes every 3.75 ms. I observe that "Hello" and "bytes_read == %60" is written which is correct. When i switch off the slave, "Hello" and "bytes_read = 60" will continue for about 20 about seconds. This is also correct since it may take that long for a connection to be disconnected. After this, only the text "Hello" is written. However, I expected that the timeout event also should occur, that is, poll_result should have returned 0, or that the text "bytes_read == 0" should occur, and in that case the program should end. But the program prints "Hello" endlessly. Why doesn't this work?> > I'm thinking of doing a thread with low level checks on the connections, I have two SCO and three ACL connections. This thread may check the connections periodically, but I don't have a clue what low level functions in BlueZ I should use.> > I used hcitool to check what happened with a connection when switching off a slave. This program detected a closed connection after about 20 seconds. Maybe I could use something from that program?> > -Mikael> ________________________________> From: micke_b.b@hotmail.com> To: bluez-devel@lists.sourceforge.net> Date: Wed, 3 Oct 2007 10:40:08 +0200> Subject: [Bluez-devel] Problem detecting closed connection> > Hello!> > I have a problem detecting a device that has closed it's connection.> > The software I'm developing sends and receives data through sockets to a slave device. When I switch of the slave device I expect that send and receive should return the value 0, as in ordinary sockets programming for TCP and UDP sockets. But instead send happily always returns a value which is bigger than 0. Why? Shouldn't Bluetooth sockets behave the same way as ordinary sockets? I have a quite old Bluez, version 2.15. Is there another way of detecting closed connections?> > Regards:> -Mikael> > ________________________________> Express yourself instantly with MSN Messenger! MSN Messenger> > _________________________________________________________________> Express yourself instantly with MSN Messenger! Download today it's FREE!> http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/> -------------------------------------------------------------------------> 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
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/

[-- Attachment #1.2: Type: text/html, Size: 5069 bytes --]

[-- Attachment #2: Type: text/plain, Size: 314 bytes --]

-------------------------------------------------------------------------
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/

[-- Attachment #3: Type: text/plain, Size: 164 bytes --]

_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-10-26  6:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-03  8:40 [Bluez-devel] Problem detecting closed connection Mikael Bengtsson
2007-10-15  8:54 ` Mikael Bengtsson
2007-10-26  6:22   ` Mikael Bengtsson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox