TCPSocket subclass & TCPServer.accept

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 :wink:

something like:
class MyKlass < Klass

end

MyKlass.get_instance_from(Klass.new)

Hi,

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.

···

At Wed, 10 Sep 2003 05:46:37 +0900, gabriele renzi wrote:


Nobu Nakada