Return-Path: Message-ID: <46A9A4F1.8090009@yandex.ru> Date: Fri, 27 Jul 2007 11:55:29 +0400 From: Irakli Tsagareli MIME-Version: 1.0 To: BlueZ development Subject: [Bluez-devel] simultaneous read/write on SCO channel Reply-To: BlueZ development List-Id: BlueZ development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: multipart/mixed; boundary="===============0197369768==" Sender: bluez-devel-bounces@lists.sourceforge.net Errors-To: bluez-devel-bounces@lists.sourceforge.net --===============0197369768== Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Hi all,

I asked this question in bluez-users list, but did not get an answer. may be bluez-devel is wrong place to ask such things, but I stuck on problem that looks VERY simple, but I can't find a way to correct  it. it's terrible to know, that 99.99%-percent-done application does not work because of only one send() function....

I'm writing a small code to test HandsFree capabilities between my phone and PC. everything works fine for audio playback (on the PC, I can hear sound file played on the phone and in case of incoming call, I can hear a voice of remote subscriber) but when I try at the same time to send some audio data to the handset via same socket, send() function returns "Invalid argument" error. I tried to create new socket for writing (same way I created listening socket). creation succeeds, but connect fails with "Device or resource busy". can anybody be so kind and explain, how can I read and write data through SCO channel simultaneously ?

thank you and best regards,
kern.

P.S. here is code snippet, that do actual SCO link setup and data transfer:

    int scosock, cli_scosock, snd_fd, nbytes;
    socklen_t addrlen;
    struct sockaddr_sco addr;

    unsigned char buffer[1024];
       
    snd_fd = init_sound();
    while(1)
    {
        if((scosock = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_SCO)) < 0)
        {
            perror("could not create SCO channel socket");
            continue;
        }
   
        memset(&addr, 0, sizeof(struct sockaddr_sco));
        addr.sco_family = AF_BLUETOOTH;
        bacpy(&addr.sco_bdaddr, BDADDR_ANY);
        if(bind(scosock, (struct sockaddr *)&addr, sizeof(struct sockaddr)) < 0)
        {
            perror("could not bind SCO channel to local address");
            close(scosock);
            continue;
        }
      
        listen(scosock, 20);
       
        memset(&addr, 0, sizeof(struct sockaddr_sco));
        addrlen = sizeof(struct sockaddr);
   
        printf("waiting for SCO connection\n");
       
        if(wait4data(scosock) < 0 || (cli_scosock = accept(scosock, (struct sockaddr *)&addr, &addrlen)) < 0)
        {
            printf("could not accept SCO link, socket error, reconnecting\n");
            close(scosock);
            continue;
        }

        printf("accepted voice channel from MT\n");

        while(1)
        {
            memset(buffer, 0, 1024);
            if(wait4data(cli_scosock) < 0 || (nbytes = read(cli_scosock, buffer, 1024)) < 0)
            {
                printf("could not read from SCO link, socket error, reconnecting\n");
                close(cli_scosock);
                close(scosock);
                break;
            }
            write(snd_fd, buffer, nbytes);
            memset(buffer, 0, 1024);
            read(snd_fd, buffer, 48);
            if(send(cli_scosock, buffer, 48, 0) < 0)             << --- send() fails here with "Invalid argument"
            {
                perror("send failed");
            }
        }
    }
}

--===============0197369768== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ --===============0197369768== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Bluez-devel mailing list Bluez-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bluez-devel --===============0197369768==--