Wrong errno
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel
Quoted 89 lines · Xavier Garreau
Hi,
I'm currently developping an application with bluez. I wrote a little code to test the alarm behaviour with bluez sockets code.
The connect and read (or recv) get interrupted but errno is set to ESPIPE (29) instead of EINTR (4). Does any one of you guys know why i'm getting this 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) { printf ("IN alarm_handler\n"); }int get_socket(char* watch_addr) { int s; struct sockaddr_l2 addr; bdaddr_t bdaddr; if ((s = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP)) < 0) { perror("Can't create socket "); return 0; } bacpy(&bdaddr, BDADDR_ANY); memset(&addr, 0, sizeof(addr)); addr.l2_family = AF_BLUETOOTH; addr.l2_bdaddr = bdaddr; addr.l2_psm = htobs(0XCC33); if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) { perror("Can't bind socket "); return 0; } baswap(&addr.l2_bdaddr, strtoba(watch_addr)); if (connect(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) { perror("Can't connect "); printf ("errno : %d\n", errno); return 0; } return s; }char* attends_data(int s) { int i; int encore = 0; char buff[256]; encore = read(s, buff, 256); if (encore == -1 || errno) { perror("Echec lors de la lecture"); return NULL; } return NULL; }int main (void) { int aSocket; signal (SIGALRM, alarm_handler); siginterrupt (SIGALRM, 1); alarm(20); printf ("Connexion ! \n"); aSocket = get_socket ("00:04:76:f1:6c:f9"); if (aSocket) { printf ("Connecté ! \n"); alarm(5); printf ("Lecture ! \n"); if (!attends_data (aSocket)) { printf ("errno : %d\n", errno);
Quoted 9 lines
} else {
printf ("OK !\n");
alarm(0);
}
shutdown (aSocket, 2);
}
close (aSocket);
}Hi Xavier,
I don't know why ESPIPE error.
But after a connect I negociate the MTU and MRU and I haven'y noticed any error with a recv() :
(g_error()/g_message are GTK+ functions)
struct l2cap_options opts;
int opt;
.......
opt = sizeof(opts);if( getsockopt(montre->sk_bluez, SOL_L2CAP, L2CAP_OPTIONS, &opts, &opt) < 0 )
g_error("Can't get L2CAP options. %s(%d)", strerror(errno), errno);
else
g_message("Actual MTU is %d & MRU is %d ",opts.omtu,opts.imtu);opts.imtu = MY_IMTU ;
opts.omtu = MY_OMTU ;
if (setsockopt(montre->sk_bluez, SOL_L2CAP, L2CAP_OPTIONS, &opts, opt) < 0)
g_error("Can't set L2CAP options. %s(%d)", strerror(errno), errno);
else
g_message("Setting MTU to %d & MRU to %d ",opts.omtu,opts.imtu);.......
r=recv(s,&buff,sizeof(buff),0))
regards
Aurelien
-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program. Does SourceForge.net help you be more productive? Does it
help you create better code? SHARE THE LOVE, and help us help
YOU! Click Here: http://sourceforge.net/donate/
_______________________________________________
Bluez-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel
Hi,
This code does not use alarm, sigaction, signal or siginterrrupt and thus won't be interrupted by SIGALRM. My question is about bluez socket implementation behaviour when a system call is interrupted.
Quoted 9 lines
I don't know why ESPIPE error.
But after a connect I negociate the MTU and MRU and I haven'y noticed any error with arecv():(g_error()/g_message are GTK+ functions)
struct
l2cap_optionsopts;
int opt;
.......
Regards,
Signature · 15 lines
Xavier Garreau <[email protected]> Prim'Time Technology http://www.prim-time.fr/ ------------------------------------------------------- This SF.net email is sponsored by: SF.net Giveback Program. Does SourceForge.net help you be more productive? Does it help you create better code? SHARE THE LOVE, and help us help YOU! Click Here: http://sourceforge.net/donate/ _______________________________________________ Bluez-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/bluez-devel
Marcel Holtmann
maintainerHi Xavier,
Quoted 6 lines
I'm currently developping an application with bluez. I wrote a little code to test the alarm behaviour with bluez sockets code.
The connect and read (or recv) get interrupted but errno is set to ESPIPE (29) instead of EINTR (4). Does any one of you guys know why i'm getting this illegal seek operation errno ?
I don't see any usage of ESPIPE in L2CAP, so this can be a general behaviour of the socket code. What errno do you get if you try this with TCP socket code?
BTW what kernel and/or patches do you use?
Regards
Marcel
-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program. Does SourceForge.net help you be more productive? Does it
help you create better code? SHARE THE LOVE, and help us help
YOU! Click Here: http://sourceforge.net/donate/
_______________________________________________
Bluez-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel