C socket to Ruby socket

Discussion in 'Ruby' started by Andre Nathan, Sep 5, 2006.

  1. Andre Nathan

    Andre Nathan Guest

    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
     
    Andre Nathan, Sep 5, 2006
    #1
    1. Advertising

  2. On 9/5/06, Andre Nathan <> 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.
     
    Francis Cianfrocca, Sep 5, 2006
    #2
    1. Advertising

  3. Andre Nathan

    Andre Nathan Guest

    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
     
    Andre Nathan, Sep 6, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Laszlo Nagy
    Replies:
    1
    Views:
    4,861
    Mark Wooding
    Jan 27, 2009
  2. Jean-Paul Calderone
    Replies:
    0
    Views:
    974
    Jean-Paul Calderone
    Jan 27, 2009
  3. Laszlo Nagy
    Replies:
    0
    Views:
    554
    Laszlo Nagy
    Feb 1, 2009
  4. Steve Holden
    Replies:
    0
    Views:
    670
    Steve Holden
    Feb 1, 2009
  5. Steve Holden
    Replies:
    1
    Views:
    725
Loading...

Share This Page