All of lore.kernel.org
 help / color / mirror / Atom feed
* [Bluez-devel] Wrong errno
@ 2003-10-28 13:37 Xavier Garreau
  2003-10-28 19:11 ` Aurelien Minet
  2003-10-29 15:38 ` Marcel Holtmann
  0 siblings, 2 replies; 4+ messages in thread
From: Xavier Garreau @ 2003-10-28 13:37 UTC (permalink / raw)
  To: bluez-devel

Hi,

I'm currently developping an application with bluez. I wrote a little cod=
e to=20
test the alarm behaviour with bluez sockets code.

The connect and read (or recv) get interrupted but errno is set to ESPIPE=
 (29)=20
instead of EINTR (4). Does any one of you guys know why i'm getting this=20
illegal seek operation errno ?

Regards,

my sample code is below :

#include <signal.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <bluetooth/hci_lib.h>
#include <bluetooth/l2cap.h>
#include <sys/ioctl.h>
#include <errno.h>

extern int errno;

void alarm_handler(int sig) {
=09printf ("IN alarm_handler\n");
}

int get_socket(char* watch_addr) {
=09int s;
=09struct sockaddr_l2 addr;
=09bdaddr_t bdaddr;


=09if ((s =3D socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP)) < 0) {
=09=09perror("Can't create socket ");
=09=09return 0;
=09}

=09bacpy(&bdaddr, BDADDR_ANY);
=09memset(&addr, 0, sizeof(addr));
=09addr.l2_family =3D AF_BLUETOOTH;
=09addr.l2_bdaddr =3D bdaddr;
=09addr.l2_psm =3D htobs(0XCC33);

        if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
=09=09perror("Can't bind socket ");
=09=09return 0;
        }

=09baswap(&addr.l2_bdaddr, strtoba(watch_addr));
        if (connect(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
=09=09perror("Can't connect ");
=09=09printf ("errno : %d\n", errno);
=09=09return 0;
        }
=09return s;
}

char* attends_data(int s) {
=09int i;
=09int encore =3D 0;
=09char buff[256];

=09encore =3D read(s, buff, 256);
=09if (encore =3D=3D -1 || errno) {
=09=09perror("Echec lors de la lecture");
=09=09return NULL;
=09}
=09return NULL;
}


int main (void) {
=09int aSocket;

=09signal (SIGALRM, alarm_handler);
=09siginterrupt (SIGALRM, 1);

=09alarm(20);
=09printf ("Connexion ! \n");
=09aSocket =3D get_socket ("00:04:76:f1:6c:f9");

=09if (aSocket) {
=09=09printf ("Connect=E9 ! \n");
=09=09alarm(5);
=09=09printf ("Lecture ! \n");
=09=09if (!attends_data (aSocket)) {
=09=09=09printf ("errno : %d\n", errno);
=09=09} else {
=09=09=09printf ("OK !\n");
=09=09=09alarm(0);
=09=09}
=09=09shutdown (aSocket, 2);
=09}
=09close (aSocket);
}

--=20
Xavier Garreau
http://www.xgarreau.org



-------------------------------------------------------
This SF.net email is sponsored by: The SF.net Donation Program.
Do you like what SourceForge.net is doing for the Open
Source Community?  Make a contribution, and help us add new
features and functionality. Click here: http://sourceforge.net/donate/
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2003-10-29 15:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-10-28 13:37 [Bluez-devel] Wrong errno Xavier Garreau
2003-10-28 19:11 ` Aurelien Minet
2003-10-29  8:48   ` Xavier Garreau
2003-10-29 15:38 ` Marcel Holtmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.