Please find attached another patch for Socket.cs with the following
- 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
- 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
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 exception.
- 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
- Not sure if Flush is efficient - should I somehow use an array
rather than a list of bytes?
Thanks for your time