Linux bluetooth development
 help / color / mirror / Atom feed
From: Stephen Crane <steve.crane@rococosoft.com>
To: bluez-devel@lists.sourceforge.net
Cc: maxk@qualcomm.com, marcel@rvs.uni-bielefeld.de
Subject: EBADFD on RFComm connect
Date: 22 Jul 2003 14:29:31 +0100	[thread overview]
Message-ID: <1058880571.1670.425.camel@baroque.rococosoft.com> (raw)

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

Hi Max, Marcel,
Under what circumstances can connect() return EBADFD?

I have a couple of programs (attached) one of which opens a listening
socket and accepts 32 connections. The other loops attempting 32
connections to the same channel. On the second connection connect()
always fails with EBADFD. (If I leave in the 0.5 second delay it all
works fine.)

I've also attached hcidumps from each machine --- each is running kernel
2.4.21-mh2.

Thanks,
Steve
-- 
Stephen Crane, Rococo Software Ltd. http://www.rococosoft.com
steve.crane@rococosoft.com +353-1-6601315 (ext 209)

[-- Attachment #2: connector.c --]
[-- Type: text/x-c, Size: 678 bytes --]

#include <sys/socket.h>
#include <netinet/in.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/rfcomm.h>
#include <unistd.h>
#include <errno.h>

int main(int argc, char *argv[])
{
	struct sockaddr_rc addr;
	int addr_len = sizeof(addr);
	int i;

	addr.rc_channel = 2;
	addr.rc_family = AF_BLUETOOTH;
	baswap(&addr.rc_bdaddr, strtoba(argv[1]));
	for (i = 0; i < 32; i++) {
		int s = socket(PF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
		char c;
		while (0 > connect(s, (struct sockaddr *)&addr, sizeof(addr)))
			if (errno != EBUSY) {
				perror("connect");
				return -1;
			}
		printf("connected %d\n", i);
		read(s, &c, 1);
		close(s);
//		usleep(500000);
	}
	return 0;
}

[-- Attachment #3: listener.c --]
[-- Type: text/x-c, Size: 914 bytes --]

#include <unistd.h>
#include <malloc.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/rfcomm.h>

int main(int argc, char *argv[])
{
	int l = socket(PF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
	struct sockaddr_rc addr, myaddr;
	int i, addr_len = sizeof(addr);

	if (0 > l) {
		perror("socket");
		return -1;
	}
	memset(&addr, 0, sizeof(addr));
	addr.rc_family = AF_BLUETOOTH;
	addr.rc_channel = 2;
	bacpy(&addr.rc_bdaddr, BDADDR_ANY); 
	if (0 > bind(l, (struct sockaddr *)&addr, sizeof(addr))) { 
		perror("bind");
		return -1;
	}
	if (0 > listen(l, 10)) {
		perror("listen");
		return -1;
	}
	for (i=0; i < 32; i++) {
		int s = accept(l, (struct sockaddr *)&addr, &addr_len);
		char c;
		if (0 > s) {
			perror("accept");
			return -1;
		}
		printf("accepted %d\n", i);
		write(s, &c, 1);
		close(s);
	}
	return 0;
}

[-- Attachment #4: connect --]
[-- Type: application/octet-stream, Size: 1254 bytes --]

[-- Attachment #5: listen --]
[-- Type: application/octet-stream, Size: 1274 bytes --]

             reply	other threads:[~2003-07-22 13:29 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-07-22 13:29 Stephen Crane [this message]
2003-07-23  0:33 ` [Bluez-devel] EBADFD on RFComm connect Max Krasnyansky
2003-07-24 14:09   ` Stephen Crane
2003-07-24 17:38     ` Max Krasnyansky

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=1058880571.1670.425.camel@baroque.rococosoft.com \
    --to=steve.crane@rococosoft.com \
    --cc=bluez-devel@lists.sourceforge.net \
    --cc=marcel@rvs.uni-bielefeld.de \
    --cc=maxk@qualcomm.com \
    /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