[Ironruby-core] New sockets.cs patch submission
Peter Bacon Darwin
bacondarwin at googlemail.com
Sun Jan 20 13:44:45 EST 2008
By the way, the latest Rubinius specs have a host of specs for Socket et al:
Sadly most of them are empty at this stage. But at least it gives you
something to start testing with.
From: ironruby-core-bounces at rubyforge.org
[mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Terence Lewis
Sent: Monday,14 January 14, 2008 21:30
To: ironruby-core at rubyforge.org
Subject: [Ironruby-core] New sockets.cs patch submission
Please find attached another patch for Socket.cs with the following changes:
1) Added class SocketStream : System.IO.Stream which wraps the socket
and provides some stream-like functionality which RubyIO can use. I've
tested the following methods and they appear to work well now on
puts also works, but I'm not as confident that it's correct - see below
under "Issues". I've also included a test file I used to compare output
between ruby.exe and rbx.exe (I tested against a default install of IE7 -
which returns a 404 for the address requested and both executables appear to
produce the same output except for line-ending issues)
2) Fixed up the spacing/tabbing issues in the file as per Seo's
comments - everything is now 4 spaces and no tabs, and I also moved the
opening curly braces up to match the style in the rest of the solution.
I know this code isn't perfect - but I think it is a step in the right
direction. I have some concerns about it which I've listed below - any
comments or suggestions will be most welcome.
- Can only peek 1 byte - there is no buffering of data off the socket
- I don't know if this will have a performance / efficiency impact?
- There is no error handling code around the socket calls - is this OK? If
not, what should be done?
- The third parameter passed to RubyIO's constructor - "r+" - what should
this be? "r+" allows me to read and write to the socket through the stream
interface so maybe it's OK?
- None of the IO mode checking referred to in the TODO comment above the
SocketStream class has been implemented - I presume this means checking
whether the socket has been shutdown either for sending or receiving before
actually trying to do the read/write - instead of letting it throw an
- How should I trigger a flush on write? At the moment it's done on seeing a
newline (hard-coded) in the stream, but I don't think that's clean or
correct (certainly ruby.exe seems to send my test request (which has 2
newlines at the end) in one go - not in two separate pieces - which is the
minor difference I referred to above regarding "puts")..
- Not sure if Flush is efficient - should I somehow use an array rather than
a list of bytes?
Thanks for your time
More information about the Ironruby-core