Hi,
my name is Claudio and this my first post in this ml,
i'm a Ruby user from over 2 years and happy with it.
I'm porting the Bluez library(linux bluetooth library)
to Ruby so with it you can do bluetooth things.
I'm doing this since 2 weeks during my free time after work,
and i learned many things about writing Ruby extension...and im
happy! :)
Here the source file:
http://github.com/cfiorini/rbluez/tree/master/rbluez.c
...and now my problem:
i have already ported some HCI functions and they works,
after i started with regular TCP/IP socket functions
so i can do simple connection between BT adapter and transfer
strings.
Looking inside ext/socket/socket.c i read how the socket system
in Ruby works so i did the same in my file and the C socket function
is ok but when i register the result in a file using MakeOpenFile
i get a segmantation fault. By using gdb the first error he gives to me
is at MakeOpenFile. At the beginnig i declared my class as rb_cObject
but after looking better in ext/socket/socket.c i switched to rb_cIO
but is the same, here some code
static VALUE
method_rfcomm_initialize(VALUE sock)
{
int fd;
OpenFile *fp;
rb_secure(3);
fd = ruby_socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
if (fd < 0) rb_sys_fail("socket(2)");
MakeOpenFile(sock, fp); /* HERE I GET THE SEG FAULT */
fp->f = rb_fdopen(fd, "r");
fp->f2 = rb_fdopen(fd, "w");
fp->mode = FMODE_READWRITE;
rb_io_synchronized(fp);
return sock;
}
and this is how i declare my class
Rbluez = rb_define_class("Rbluez", rb_cIO);
rb_define_singleton_method(Rbluez, "new", method_rbluez_initialize,0);
Now i don't know how figure out this because i'm not a expert C
developer so specially i don't know Ruby internals system well,
but one things that make me thinking about is this:
MakeOpenFile expect that first value is a T_FILE
because it uses RFILE but the value there is T_DATA
could be this? and if it is what can i do to change?
Thanks for your time reading my email, for your answer, to make
Ruby better everyday and if i did something wrong
on writing in this ml, sorry.
Thanks
Claudio