[Ironruby-core] Patch submission - sockets

John Messerly jomes at microsoft.com
Thu Jan 10 18:56:00 EST 2008

Terence Lewis:

> > 3. TCPSocket#open needed a different implementation. This is a thing
> to watch out for in singleton methods--do they return an instance of
> the derived type, if you call them from a derived class? For example,
> if you do "class MyTCPSocket < TCPSocket; end" then MyTCPSocket.open,
> you actually get back an instance of MyTCPSocket. The way to do this in
> our system is to create a dynamic site that calls "new". Also,
> TCPSocket#open needed to yield to the block. I added that, which had
> the nice side effect of removing the need for TCPServer#open.
> 1) I don't see any "open" method anywhere in Socket.cs anymore. I
> tested it though and it still works, so I did a quick search through
> the code and came up with [RubyMethod("open")] in IoOps.cs. I assume
> this is what's being called now for both TCPSocket.open and
> TCPServer.open because of BasicSocket's inheritance from RubyIO - this
> is the dynamic site to which you refer? It is a nice side effect not
> having to handle the block :)

Yup, there's just IO#open. I think it's that way in MRI:

[BasicSocket,IPSocket,TCPSocket,TCPServer].any? { |x| x.methods(false).include? "open" } # => false

IO.methods(false).include? "open" # => true

> 2) Regarding the ConvertToPort function (which is currently incorrectly
> spelled with only 1 t in the middle), there is a function in the
> winsock dll called getservbyname which will do this conversion for you
> - unfortunately it's not exposed to .NET at all as far as I can tell.
> It's also exposed directly by Ruby's socket class as the method
> "getservbyname", so we are going to need to call it. I've written a
> simple P/Invoke call which will call into ws2_32.dll to get this
> information, but I realized only after almost finishing the code that
> you guys may want to steer clear of P/Invoke for compatibility reasons.
> Is that true and if so, how can I go about implementing this function
> manually - does anybody know where I can get a list of what it can
> return? If not (i.e p/invoke is OK), does something special have to be
> done to make that code work on mono? I thought I'd get an answer on
> these questions before tidying up my code and submitting it.

Yup, we're trying to avoid pinvokes. Would be better if we could find a managed way to do it. Unfortunately this post suggests there isn't a nice API: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=347426&SiteID=1.

> 3) Can I get a quick yes/no answer as to whether I'm allowed to look at
> MRI's source code and still contribute to this project? Also, are you
> guys (Microsoft employees) allowed to look at this code - and if you're
> not, can I still refer to MRI source code in questions I post to this
> list regarding implementation details?

Not sure whether you're allowed to look at MRI code. We aren't.

- John

More information about the Ironruby-core mailing list