TCPSocket subclass & TCPServer.accept

Discussion in 'Ruby' started by gabriele renzi, Sep 9, 2003.

  1. Hi gurus and nubys,

    The problem I'm facing is:
    I wanto to use a subclass of TCPSocket.
    Everything works fine while I'm using it to connect outside.

    But now I'd like to use a MySocket even when I'm receiving
    connections.
    BTW, TCPServer.accept just gives me a classic vanilla TCPSocket.

    now I have 3 way to go:
    -add methods to TCPSocket instead of subclass it
    -add a MyServer class as a subclass of TCPServer
    -wriap up a TCPSocket in a MySocket class instead of subclassing it.

    My point is: this ways are ugly to me.

    So, is there a way in ruby to get a subclass instance from a
    superclass instance?

    I know that often this could be impossible, but who knows ;)

    something like:
    class MyKlass < Klass
    ...
    end

    MyKlass.get_instance_from(Klass.new)
    gabriele renzi, Sep 9, 2003
    #1
    1. Advertising

  2. gabriele renzi

    Guest

    Hi,

    At Wed, 10 Sep 2003 05:46:37 +0900,
    gabriele renzi wrote:
    > But now I'd like to use a MySocket even when I'm receiving
    > connections.
    > BTW, TCPServer.accept just gives me a classic vanilla TCPSocket.


    In 1.7 or later:

    class MyServer < TCPServer
    def accept
    MySocket.for_fd(sysaccept)
    end
    end

    Note that this is not exception safe. It might leak file
    descriptors.

    --
    Nobu Nakada
    , Sep 9, 2003
    #2
    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. oziris
    Replies:
    5
    Views:
    2,711
  2. jstorta
    Replies:
    3
    Views:
    430
    jstorta
    Feb 20, 2006
  3. Shea Martin
    Replies:
    6
    Views:
    188
    Shea Martin
    Mar 22, 2006
  4. Alex MacCaw

    TCPServer locking when calling accept

    Alex MacCaw, Apr 3, 2007, in forum: Ruby
    Replies:
    2
    Views:
    80
    Louis R. Marascio
    Apr 4, 2007
  5. Steve Lewis
    Replies:
    4
    Views:
    108
    Steve Lewis
    Sep 7, 2008
Loading...

Share This Page