public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
From: Mikael Bengtsson <micke_b.b@hotmail.com>
To: BlueZ development <bluez-devel@lists.sourceforge.net>
Subject: Re: [Bluez-devel] Problem detecting closed connection
Date: Fri, 26 Oct 2007 08:22:14 +0200	[thread overview]
Message-ID: <BAY114-W400A60A0890B62845C2FA3D7960@phx.gbl> (raw)
In-Reply-To: <BAY114-W26F43C8D90463DC89CF35DD7A30@phx.gbl>


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

      reply	other threads:[~2007-10-26  6:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

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=BAY114-W400A60A0890B62845C2FA3D7960@phx.gbl \
    --to=micke_b.b@hotmail.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