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: Mon, 15 Oct 2007 10:54:24 +0200	[thread overview]
Message-ID: <BAY114-W26F43C8D90463DC89CF35DD7A30@phx.gbl> (raw)
In-Reply-To: <BAY114-W266FADABD770552606A55AD7AF0@phx.gbl>


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

  reply	other threads:[~2007-10-15  8:54 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 [this message]
2007-10-26  6:22   ` Mikael Bengtsson

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-W26F43C8D90463DC89CF35DD7A30@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