[Ironruby-core] Patch submission - sockets

Terence Lewis lewistm at gmail.com
Fri Jan 11 08:04:39 EST 2008

> In theory, getservbyname returns IANA-specified port numbers.
> http://www.iana.org/assignments/port-numbers
> In practice, implementing common ports like FTP and HTTP would suffice.

Cool - will leave it as is for now.

On a slightly different tack then, there is the following comment in the code:

// TODO: this won't work at all with the existing RubyIO
implementation until I implement a proxy class that wraps Socket in a
// TODO: i think that stream should do all of the IO mode checking and
throw where appropriate ... in the case of sockets, only
// the socket class knows whether it can read or write from a given
socket - the IOMode flags don't exist at all ...

I tried to use the System.IO.NetworkStream class to pass a stream
object through to RubyIO (John - was this what you meant by the above
comment?), but I ran into a few problems - notably:

1) RubyIO calls IsEndOfStream which tries to do a peek, which in turn
tries to get the stream's position - NetworkStream throws an exception
when Position is called. As a temporary solution to work around this I
made IsEndOfStream virtual and overrode it in BasicSocket to always
return false, which lead me onto...
2) I could then read data off the socket via the NetworkStream in
RubyIOOps.ReadLine, but as soon as I hit '\r' GetChar() again does a
peek to see if a '\n' is coming and NetworkStream once again throws an

These hacks on my part lead me to believe that you do not intend to
use NetworkStream directly, but rather a custom stream implementation
that will behave itself properly according to how RubyIO uses the
System.IO.Stream interface. Is that correct? If so, I'm going to try
and make a start on that custom stream (I'll look at ConsoleStream for
insipration) - but in that case I have a few more questions (for now
:) : For peek to work properly, I assume I'm going to have to read
data off the socket and buffer it inside the stream-socket-wrapper
class - is that correct? If so, I suppose the stream's Position
property will have to not throw an exception (else we're no better off
than NetworkStream when it comes to peeking), but what should it do
instead? Should it just be a do-nothing getter and setter to satisfy
RubyIO's peek?

Thanks for your patience


More information about the Ironruby-core mailing list