Linux bluetooth development
 help / color / mirror / Atom feed
From: "Victor Shcherbatyuk" <victor@win.tue.nl>
To: <bluez-devel@lists.sourceforge.net>
Subject: [Bluez-devel] RFCOMM non-blocking support
Date: Mon, 11 Apr 2005 00:15:47 +0200	[thread overview]
Message-ID: <000901c53e1a$d8e07e30$0201a8c0@NBVICTOR> (raw)
In-Reply-To: 42582BE5.2050407@xmission.com

[-- Attachment #1: Type: text/plain, Size: 510 bytes --]

Hi Marcel,

This was already discussed a year ago:
question:
http://sourceforge.net/mailarchive/message.php?msg_id=8643791
reply:
http://sourceforge.net/mailarchive/message.php?msg_id=8643793

I have exactly the same problem, I guess.

Instead of EINPROGRESS non-blocking connect() returns EAGAIN (Resource 
temporarily unavailable). The rest seem to be OK (see the source). Select 
waits till the connection is established or an error occurs (at least as it 
looks from hcidump log).

Regards,
      Victor. 

[-- Attachment #2: bluetest.c --]
[-- Type: application/octet-stream, Size: 1962 bytes --]

#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/socket.h>

#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <bluetooth/hci_lib.h>
#include <bluetooth/rfcomm.h>

int btopen( const char* addr, int chan )
{
	struct sockaddr_rc remote_addr, local_addr;
	bdaddr_t bdaddr;
	int s, r;

	str2ba(addr, &bdaddr);
	if ((s = socket(PF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM)) < 0) {
		perror("socket()");
		return -1;
	}

	memset(&local_addr, 0, sizeof(local_addr));
	local_addr.rc_family = AF_BLUETOOTH;
	bacpy(&local_addr.rc_bdaddr, BDADDR_ANY);
	if (bind(s, (struct sockaddr *)&local_addr, sizeof(local_addr)) < 0) {
		perror("bind()");
		close(s);
		return -1;
	}

	if ( fcntl( s, F_SETFL, fcntl( s, F_GETFL ) | O_NONBLOCK ) < 0 )
		perror("fcntl()");

	memset(&remote_addr, 0, sizeof(remote_addr));
	remote_addr.rc_family = AF_BLUETOOTH;
	bacpy(&remote_addr.rc_bdaddr, &bdaddr);
	remote_addr.rc_channel = chan;
	if ( r = connect(s, (struct sockaddr *)&remote_addr, sizeof(remote_addr)) < 0)
		perror("connect()");
	
	//here returns -1 with EAGAIN (11) = Resource temporarily unavailable
	//EINPROGRESS is expected???

	return s;
}

int main( int argc, char** argv )
{
	int fd, r;
	fd_set wfds;
	socklen_t optlen;

	if ( argc < 3 )
	{
		printf("Use: bluetalk <address> <channel>\n");
		exit( 1 );
	}
	printf("Opening socket...\n");	
	if ( ( fd = btopen( argv[1], atoi( argv[2] ) ) ) < 0 )
		exit(1);

	printf("Waiting for open completion...\n");
	r = select(fd + 1, NULL, &wfds, NULL, &tv);
	if (r<0){
		perror("select()");
		close(fd);
		exit(1);
	}
	else
		printf("success\n");

	//check if connect() succeded
	getsockopt(fd, SOL_SOCKET, SO_ERROR, (void*)&r, &optlen);	
	//here  r=0 in case of success or r=errno otherwise
	printf("len=%d, r=%d\n", optlen, r);

	printf("Closing socket...\n");
	close( fd );

	return 0;
}

  reply	other threads:[~2005-04-10 22:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-09 19:24 [Bluez-devel] gumstix & bluez (infineon) Brad Midgley
2005-04-10 22:15 ` Victor Shcherbatyuk [this message]
2005-04-11 12:56   ` [Bluez-devel] RFCOMM non-blocking support Marcel Holtmann

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='000901c53e1a$d8e07e30$0201a8c0@NBVICTOR' \
    --to=victor@win.tue.nl \
    --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