[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

TCPSocket subclass & TCPServer.accept

gabriele renzi

9/9/2003 8:30:00 PM

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)
1 Answer

nobu.nokada

9/9/2003 10:35:00 PM

0

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