Return-Path: Message-ID: From: "Albert Huang" To: bluez-devel@lists.sourceforge.net Subject: Re: [Bluez-devel] RFCOMM Server: accept does not block In-Reply-To: <9e3a30280602261839n1e4b9ffby8c003316ff1d08d9@mail.gmail.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_4361_14693538.1141010595368" References: <9e3a30280602261729u52e8b48ap5a90d422e4ddc44@mail.gmail.com> <9e3a30280602261839n1e4b9ffby8c003316ff1d08d9@mail.gmail.com> Sender: bluez-devel-admin@lists.sourceforge.net Errors-To: bluez-devel-admin@lists.sourceforge.net Reply-To: bluez-devel@lists.sourceforge.net List-Unsubscribe: , List-Id: BlueZ development List-Post: List-Help: List-Subscribe: , List-Archive: Date: Sun, 26 Feb 2006 22:23:15 -0500 ------=_Part_4361_14693538.1141010595368 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline one of the other socket functions probably failed. check the return codes for all socket calls (a good practice in general) and use perror again. Yo= u may also want to read through that entire guide if you're not familiar with socket programming. -albert On 2/26/06, Deniz Demir wrote: > > Thank you Albert. > > perror reports the following error message: > > socket: File descriptor in bad state > > > On 2/26/06, Albert Huang wrote: > > Use perror to find out what went wrong. > > > > http://beej.us/guide/bgnet/output/html/errnoman.html > > > > -albert > > > > > > On 2/26/06, Deniz Demir wrote: > > > > > > Hi, > > > > > > I want to run a small rfcomm server, however it does not block on > > > accept, and returns immediately with -1 as socket descriptor (last > > > line prints -1 right away). > > > > > > I have the following code: > > > > > > // allocate socket > > > s =3D socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); > > > > > > // bind socket to port 1 of the first available > > > // local bluetooth adapter > > > loc_addr.rc_family =3D AF_BLUETOOTH; > > > loc_addr.rc_bdaddr =3D *BDADDR_ANY; > > > loc_addr.rc_channel =3D (uint8_t) 1; > > > bind(s, (struct sockaddr *)&loc_addr, sizeof(loc_addr)); > > > > > > // put socket into listening mode > > > listen(s, 1); > > > > > > // accept one connection > > > client =3D accept(s, (struct sockaddr *)&rem_addr, &opt); > > > printf("client: %d \n", client); > > > > > > I expected it would block on accept function until a connection > > > request came in. I appreciate any comments. > > > > > > Thanks, > > > Deniz > > > > > > > > > ------------------------------------------------------- > > > This SF.Net email is sponsored by xPML, a groundbreaking scripting > > language > > > that extends applications into web and mobile media. Attend the live > > webcast > > > and join the prime developer group breaking into this new coding > > territory! > > > > > http://sel.as-us.falkag.net/sel?cmdlnk&kid=110944&bid$1720&dat=121642 > > > _______________________________________________ > > > Bluez-devel mailing list > > > Bluez-devel@lists.sourceforge.net > > > https://lists.sourceforge.net/lists/listinfo/bluez-devel > > > > > > > > > > ------------------------------------------------------- > This SF.Net email is sponsored by xPML, a groundbreaking scripting > language > that extends applications into web and mobile media. Attend the live > webcast > and join the prime developer group breaking into this new coding > territory! > http://sel.as-us.falkag.net/sel?cmdlnk&kid=110944&bid$1720&dat=121642 > _______________________________________________ > Bluez-devel mailing list > Bluez-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/bluez-devel > ------=_Part_4361_14693538.1141010595368 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline one of the other socket functions probably failed.  check the return codes for all socket calls (a good practice in general) and use perror again.  You may also want to read through that entire guide if you're not familiar with socket programming.

-albert

On 2/26/06, Deniz Demir <= denizdemir@gmail.com> wrote:
Thank you Albert.

perror reports the following error message:
socket: File descriptor in bad state


On 2/26/06, Albert Huang &= lt;ashuang@gmail.com> wrote: > Use perror to find out what went wrong.
>
>  http://beej.u= s/guide/bgnet/output/html/errnoman.html
>
>  -alb= ert
>
>
> On 2/26/06, Deniz Demir <denizdemir@gmail.com> wrote:
> >
> > Hi,
>= >
> > I want to run a small rfcomm server, however it does not= block on
> > accept, and returns immediately with -1 as socket descriptor = (last
> > line prints -1 right away).
> >
> > I = have the following code:
> >
> >     = // allocate socket
> >     s =3D socket(AF_BLUETOOTH, SOCK_STREA= M, BTPROTO_RFCOMM);
> >
> >     // bi= nd socket to port 1 of the first available
> >   &n= bsp; // local bluetooth adapter
> >     loc_ad= dr.rc_family =3D AF_BLUETOOTH;
> >     loc_addr.rc_bdaddr =3D *BDADDR_ANY;> >     loc_addr.rc_channel =3D (uint8_t) 1;> >     bind(s, (struct sockaddr *)&loc_addr= , sizeof(loc_addr));
> >
> >     // p= ut socket into listening mode
> >     listen(s, 1);
> >
> &g= t;     // accept one connection
> >  = ;   client =3D accept(s, (struct sockaddr *)&rem_addr, &o= pt);
> >     printf("client: %d \n",= client);
> >
> > I expected it would block on accept function unt= il a connection
> > request came in. I appreciate any comments.> >
> > Thanks,
> > Deniz
> >
> >= ;
> > -------------------------------------------------------
&g= t; > This SF.Net email is sponsored by xPML, a groundbreaking scripting<= br>> language
> > that extends applications into web and mobile= media. Attend the live
> webcast
> > and join the prime developer group breaking i= nto this new coding
> territory!
> >
> http://sel.as-us.falkag.net/sel?cmdlnk&kid=110944&bid$1720&dat= =121642
> > _______________________________________________> > Bluez-devel mailing list
> > Bluez-devel@lists.sourceforge.net
> > https://lists.sourceforge.net/= lists/listinfo/bluez-devel
> >
>
>


----= ---------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting lang= uage
that extends applications into web and mobile media. Attend the liv= e webcast
and join the prime developer group breaking into this new codi= ng territory!
http://sel.as-us.falkag.net/sel?cmdlnk&kid=11094= 4&bid$1720&dat=121642
______________________________________= _________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/= lists/listinfo/bluez-devel

------=_Part_4361_14693538.1141010595368-- ------------------------------------------------------- This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642 _______________________________________________ Bluez-devel mailing list Bluez-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bluez-devel