Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Ruby (http://www.velocityreviews.com/forums/f66-ruby.html)
-   -   C socket to Ruby socket (http://www.velocityreviews.com/forums/t833272-c-socket-to-ruby-socket.html)

Andre Nathan 09-05-2006 03:53 PM

C socket to Ruby socket
 
Hello

What is the correct way to convert a C socket (int) to a Ruby Socket
object in a C extension? Something like

int s = socket(...);
VALUE sock = rb_some_func(s);

In my extension there's a callback function that receives a socket as an
argument, and I'd like to pass that socket as an argument to a ruby
block, so I need to convert it to a Socket object first.

Thanks in advance,
Andre



Francis Cianfrocca 09-05-2006 04:02 PM

Re: C socket to Ruby socket
 
On 9/5/06, Andre Nathan <andre@digirati.com.br> wrote:
> Hello
>
> What is the correct way to convert a C socket (int) to a Ruby Socket
> object in a C extension? Something like
>
> int s = socket(...);
> VALUE sock = rb_some_func(s);
>
> In my extension there's a callback function that receives a socket as an
> argument, and I'd like to pass that socket as an argument to a ruby
> block, so I need to convert it to a Socket object first.
>
> Thanks in advance,
> Andre
>
>
>


does it need to be a Socket? class IO can be initialized with a file descriptor.


Andre Nathan 09-06-2006 03:09 AM

Re: C socket to Ruby socket
 
Hi!

On Wed, 2006-09-06 at 01:17 +0900, Kent Sibilev wrote:
> You probably can call Socket.for_fd using rb_funcall.


I got it to work with an IO:

rb_funcall(rb_cIO, rb_intern("for_fd"), 1, INT2NUM(socket));

However I can't seem to be able to make rb_cSocket visible to my
extension. Any hints on how to do that?

Thanks,
Andre




All times are GMT. The time now is 04:34 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.