2003-07-22 13:29:31

by Stephen Crane

[permalink] [raw]
Subject: EBADFD on RFComm connect

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
[email protected] +353-1-6601315 (ext 209)


Attachments:
connector.c (678.00 B)
listener.c (914.00 B)
connect (1.22 kB)
listen (1.24 kB)
Download all attachments

2003-07-24 17:38:23

by Max Krasnyansky

[permalink] [raw]
Subject: Re: [Bluez-devel] EBADFD on RFComm connect

At 07:09 AM 7/24/2003, Stephen Crane wrote:
>On Wed, 2003-07-23 at 01:33, Max Krasnyansky wrote:
>
>> You can not do this
>> while (0 > connect(s, (struct sockaddr *)&addr, sizeof(addr)))
>> if (errno != EBUSY) {
>> perror("connect");
>> return -1;
>> }
>>
>> If connect returns EBUSY error you have to close() the socket. And it does
>> indeed return EBUSY in your case (I ran the progs) because close() is asynchronous
>> and that channel still exist (two connections on the same channel are not allowed
>> in RFCOMM). What you can do to avoid that error is to enable SO_LINGER option on that
>> socket, in which case close() will be synchronous.
>
>Thanks Max. That's fixed it. Another one for the programming manual?
Yep.

Max

2003-07-24 14:09:54

by Stephen Crane

[permalink] [raw]
Subject: Re: [Bluez-devel] EBADFD on RFComm connect

On Wed, 2003-07-23 at 01:33, Max Krasnyansky wrote:

> You can not do this
> while (0 > connect(s, (struct sockaddr *)&addr, sizeof(addr)))
> if (errno != EBUSY) {
> perror("connect");
> return -1;
> }
>
> If connect returns EBUSY error you have to close() the socket. And it does
> indeed return EBUSY in your case (I ran the progs) because close() is asynchronous
> and that channel still exist (two connections on the same channel are not allowed
> in RFCOMM). What you can do to avoid that error is to enable SO_LINGER option on that
> socket, in which case close() will be synchronous.

Thanks Max. That's fixed it. Another one for the programming manual?

Steve
--
Stephen Crane, Rococo Software Ltd. http://www.rococosoft.com
[email protected] +353-1-6601315 (ext 209)

2003-07-23 00:33:15

by Max Krasnyansky

[permalink] [raw]
Subject: Re: [Bluez-devel] EBADFD on RFComm connect

At 06:29 AM 7/22/2003, Stephen Crane wrote:
>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.)

You can not do this
while (0 > connect(s, (struct sockaddr *)&addr, sizeof(addr)))
if (errno != EBUSY) {
perror("connect");
return -1;
}

If connect returns EBUSY error you have to close() the socket. And it does
indeed return EBUSY in your case (I ran the progs) because close() is asynchronous
and that channel still exist (two connections on the same channel are not allowed
in RFCOMM). What you can do to avoid that error is to enable SO_LINGER option on that
socket, in which case close() will be synchronous.

Max