public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
From: Eiko Oltmanns <eiko.oltmanns@web.de>
To: linux-bluetooth@vger.kernel.org
Subject: Re: problem with reading from rfcomm socket
Date: Mon, 06 Apr 2009 21:04:41 +0200	[thread overview]
Message-ID: <49DA5249.30008@web.de> (raw)
In-Reply-To: <49D511C2.5040304@web.de>

Eiko Oltmanns schrieb:
> Hi!
>
>
> I have a problem, with reading from rfcomm sockets. I wrote a little 
> client application, that connects to an other device and just prints 
> all received data. I want to receive data as soon as it is sent from 
> the remove device. The problem is, that the read function blocks, 
> until 4k of data are sent on the remote side, although the number of 
> requested bytes passed to read is much lower. Then read starts to read 
> out the received data. When all data has been read, the next call 
> again blocks until the next 4 kb are available.
>
> Distribution: Debian, "Lenny"
> Kernelversion: 2.6.26-13
> Bluez-libs: 3.36-1
> Bluez-utils: 3.36-3
>
>
> Here is the minimal code, which reproduces my problem:
>
>
> int main(int argc, char **argv)
> {
>     int sock = hci_open_dev( devId );
>
>     if ( sock < 0 ) return -1;
>
>     int rfcommSocket = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
>     if ( rfcommSocket < 0 ) return -1;
>
>     struct sockaddr_rc addr;
>     addr.rc_family = AF_BLUETOOTH;
>     addr.rc_channel = channel;
>     str2ba("00:09:DD:50:72:0F", &addr.rc_bdaddr );
>     
>     // connect to server
>     int status = connect(rfcommSocket, (struct sockaddr *)&addr, 
> sizeof(addr));
>
>     if (  status < 0 ) rerurn - 1;
>
>     int bytes = write(rfcommSocket,"Test",4);    /* works as expected. 
> Data is received immediately by the remote device */
>
>     if ( bytes != 4 ) return - 1; //tested only for 4 for simplicity
>
>     while (1)     {
>         unsigned char buf[10];        /* the buf size seems to have no 
> influence on my problem */
>         memset( buf, 0, sizeof(buf));
>         int bytes = read(rfcommSocket, buf, sizeof(buf)-1); /* blocks 
> until 4k of data are available */
>
>         if ( bytes > 0 )
>             cout << buf;
>         if ( bytes < 0 )
>         {
>             return -1;
>         }
>
>     }
>     return 0;
> }
>
> Greetings,
> Eiko

I think my code should be correct, isn't it? Is there maybe an option in 
the kernel config, that could cause such a behaviour of the socket? I am 
running a self configured kernel on an embedded hardware. Any other 
suggestions?


  reply	other threads:[~2009-04-06 19:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-02 19:28 problem with reading from rfcomm socket Eiko Oltmanns
2009-04-06 19:04 ` Eiko Oltmanns [this message]
2009-04-06 19:34   ` Johan Hedberg
2009-04-06 19:39     ` Johan Hedberg

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=49DA5249.30008@web.de \
    --to=eiko.oltmanns@web.de \
    --cc=linux-bluetooth@vger.kernel.org \
    /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