Hi Nocera,

      Thanks for your reply. What I have seen is that my socket's fd is by default blocking, every time it returns -1 after waiting for sometime. If I set it as non-blocking then it returns -1 immediately.  

      I have set up a watcher with select() and getsockopt() call.

It's like that ....

 

s = socket(AF_BLUETOOTH, SOCK_STREAM/*SOCK_SEQPACKET*/, BTPROTO_RFCOMM);

 

remote_addr.rc_family = AF_BLUETOOTH; // specifies the addressing family of the socket

remote_addr.rc_channel = (uint8_t)4; // port no to connect to

str2ba(dest, &remote_addr.rc_bdaddr); // address to connect to

 

status = connect(s, (struct sockaddr*)&remote_addr, sizeof(struct sockaddr_rc));

 

if(status < 0)

      {

            if(errno == EINPROGRESS)

            {

                  printf("EINPROGRESS : %s\n",strerror(errno));

                  do

                  {

                        timeout.tv_sec = 25;

                        timeout.tv_usec = 0;

                        FD_ZERO(&wr);

                        FD_ZERO(&rd);    

                        FD_ZERO(&exceptfds);

 

                        FD_SET(s,&wr);

                        FD_SET(s,&rd);

                        FD_SET(s,&exceptfds);

 

                        if((status = select(s+1,&rd,&wr,&exceptfds,&timeout)) >0 )

                        {

                              //struct protoent *result;

                              len = sizeof(int);

                              //while((result = getprotoent()) != NULL)

                              //printf("name = %s, protocol = %d\n",result->p_name,result->p_proto);

 

                             

                  if(getsockopt(s,SOL_RFCOMM,SO_ERROR,(void*)&valopt,&len) < 0)

                              {

                                    printf("Error in getsockopt() %d - %s\n",errno,strerror(errno));

                                    _exit(0);

                              }

                       

                              if(valopt) // check the value returned

                              {    

                                    printf("Error in delayed connection() %d - %s\n",valopt,strerror(valopt));

                                    _exit(0);

                              }

                              printf("before break\n");

                              break;

                        }

                        else if(status < 0 && errno != EINTR)

                        {

                              printf("Error connecting %d - %s\n",errno, strerror(errno));

                              _exit(0);

                        }

                        else

                        {

                              printf("errno = %d\n",errno);

                              perror("Timeout in select(). exiting... ");

                              _exit(0);

                        }

                  }while(1); /**/

            }

            else

            {

                  printf("errno = %d\n",errno);

                  perror("Error in connect. exiting... ");

                  _exit(0);

            }

      }

 

But for SOL_RFCOMM in getsockopt() I get an error message at run time ……  Error in getsockopt() 92 – Protocol not available …………… although SOL_RFCOMM is defined in ‘/usr/include/Bluetooth/bluetooth.h’. Is it the right way to implement a watcher on a socket fd ?

 

One thing I forgot to mention that after making connect() call, my mobile phone ask for ‘accept connection request’, and after pressing ‘yes’ connect() returns -1 with error value ‘Operation now in progress’.    

 

Unfortunately I couldn’t find ‘manager.c’ in ‘bluez-utils-3.9/serial/’. The folder doesn’t contain any .c file except Makefile, Makefile.am and Makefile.in. ‘manager.c’ is present only in ‘bluez-utils-3.9/daemon’ folder, but there is no ‘rfcomm_connect()’ implementation. Probably we are using different utils version.

Thanks again for your time.

 

 

-----Original Message-----
From: Bastien Nocera [mailto:hadess@hadess.net]
Sent
: Thursday, May 31, 2007 8:38 PM
To: BlueZ development
Cc: bluez-users@lists.sourceforge.net
Subject: Re: [Bluez-devel] connect fail : Operation now in progress

 

On Thu, 2007-05-31 at 16:44 +0530, Aveek Audhya wrote:

> Hi,

>

>             I am trying to communicate with a J2ME application running

> on my mobile phone(Nokia 6600) using a client program running on a

> Linux machine (FC6). The ‘sdptool browse’ reports that the J2ME

> application is listening on channel 4. The J2ME application is using

> btspp protocol whereas my client side application is using RFCOMM. But

> when I run the client application, the ‘connect’ system-call fails

> (returns -1) with error value “Operation now in progress”. I am using

> BlueZ protocol stack.

>

> What can be the probable reason for this kind of behavior? Any

> suggestion is appreciated.

 

You probably made the socket's fd non-blocking. Either make it blocking,

or setup a watcher on the fd to wait for the link to be created.

 

See rfcomm_connect() in bluez-utils/serial/manager.c

 

--

Bastien Nocera <hadess@hadess.net>

 

 

-------------------------------------------------------------------------

This SF.net email is sponsored by DB2 Express

Download DB2 Express C - the FREE version of DB2 express and take

control of your XML. No limits. Just data. Click to get it now.

http://sourceforge.net/powerbar/db2/

_______________________________________________

Bluez-devel mailing list

Bluez-devel@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/bluez-devel