2007-02-13 05:56:52

by siddhant tewari

[permalink] [raw]
Subject: [Bluez-users] Problem in doing Obex push though multiple connection using single adapter

hi,
This is the part of code i am using to perform obex push on two
simultaneous connections.The behavior is that while sending through one of
the connections progress in the other process gets stopped and sometimes
causes error. Please tell me whether my method is correct or not.I provide
the bt addr of the remote devices and their obex push channel via command
line.


int main(int argc,char **argv)
{
bdaddr_t sourceBdAddr;
int pid,counter;
str2ba("80:48:40:B0:A2:02",&sourceBdAddr);
for (counter = 0;counter < 2;++counter)
{
if ((pid = fork()) == 0)
{
bdaddr_t destBdAddr;
struct rfcomm_dev_req req;
char tempBuf[20];
int ctl;
int err;
int dev = counter;
int returnVal;
extern char* addressName;
str2ba(argv[dev*2 + 1],&destBdAddr);
addressName = strdup(argv[dev*2 +1]);
//sprintf(addressName,"%s",argv[dev*2 + 1]);
printf ("Sending file to %s\n",argv[dev*2 + 1]);
ctl = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_RFCOMM);
if (ctl < 0) {
perror("Can't open RFCOMM control socket");
exit(1);
}
req.dev_id = dev;
req.flags = 0;
bacpy(&req.src, &sourceBdAddr);
bacpy(&req.dst, &destBdAddr);
req.channel = atoi (argv[dev*2 + 2]);
sprintf(tempBuf,"/dev/rfcomm%d",dev);
//mknod(tempBuf,S_IFCHR,req.dev_id);
{
char cmdBuf[256];
remove (tempBuf);
sprintf(cmdBuf,"mknod %s c 216 %d",tempBuf,dev);
if (system(cmdBuf) != 0 )
{
fprintf(stderr,"\nError in executng mknod\n");
exit(1);
}
}
err = ioctl(ctl, RFCOMMCREATEDEV, &req);
if (err == EOPNOTSUPP)
fprintf(stderr, "RFCOMM TTY support not available\n");
else if (err < 0)
{
perror("Can't create device");
}
returnVal = obex_push(tempBuf,"tf.jpg");

memset(&req, 0, sizeof(req));
req.dev_id = dev;
err = ioctl(ctl, RFCOMMRELEASEDEV, &req);
if (err < 0)
{
perror("Can't release device");
exit(1);
}
close(ctl);
if (returnVal ==0)
printf("Sending file to %s successfull\n",argv[dev*2 + 1]);
else
printf("Sending file to %s unsuccessfull\n",argv[dev*2 +
1]);
exit (0);
}
}
wait();
}



thanks

siddhant


Attachments:
(No filename) (2.68 kB)
(No filename) (9.62 kB)
(No filename) (374.00 B)
(No filename) (164.00 B)
Download all attachments