[macruby-changes] [4233] MacRuby/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Wed Jun 16 18:03:18 PDT 2010
Revision: 4233
http://trac.macosforge.org/projects/ruby/changeset/4233
Author: martinlagardette at apple.com
Date: 2010-06-16 18:03:18 -0700 (Wed, 16 Jun 2010)
Log Message:
-----------
Fix some reading issues in the Net library
- Use #bytesize instead of #size (it returns an incorrect size causing the lib to try reading when nothing is available)
- Fix IO#sysread to resize the buffer to whatever was read (needed when reading over a socket).
- Fixes <rdar://problem/7932773>
Modified Paths:
--------------
MacRuby/trunk/io.c
MacRuby/trunk/lib/net/protocol.rb
Modified: MacRuby/trunk/io.c
===================================================================
--- MacRuby/trunk/io.c 2010-06-16 22:45:30 UTC (rev 4232)
+++ MacRuby/trunk/io.c 2010-06-17 01:03:18 UTC (rev 4233)
@@ -1114,9 +1114,13 @@
uint8_t *bytes = rb_bstr_bytes(buffer);
- if (read(io->read_fd, bytes, (size_t)to_read) == -1) {
+ long r;
+ r = read(io->read_fd, bytes, (size_t)to_read);
+ if (r == -1) {
rb_sys_fail("read(2) failed.");
}
+ // Resize the buffer to whatever was read
+ rb_bstr_resize(buffer, r);
return buffer;
}
Modified: MacRuby/trunk/lib/net/protocol.rb
===================================================================
--- MacRuby/trunk/lib/net/protocol.rb 2010-06-16 22:45:30 UTC (rev 4232)
+++ MacRuby/trunk/lib/net/protocol.rb 2010-06-17 01:03:18 UTC (rev 4233)
@@ -80,13 +80,13 @@
LOG "reading #{len} bytes..."
read_bytes = 0
begin
- while read_bytes + @rbuf.size < len
- dest << (s = rbuf_consume(@rbuf.size))
- read_bytes += s.size
+ while read_bytes + @rbuf.bytesize < len
+ dest << (s = rbuf_consume(@rbuf.bytesize))
+ read_bytes += s.bytesize
rbuf_fill
end
dest << (s = rbuf_consume(len - read_bytes))
- read_bytes += s.size
+ read_bytes += s.bytesize
rescue EOFError
raise unless ignore_eof
end
@@ -99,8 +99,8 @@
read_bytes = 0
begin
while true
- dest << (s = rbuf_consume(@rbuf.size))
- read_bytes += s.size
+ dest << (s = rbuf_consume(@rbuf.bytesize))
+ read_bytes += s.bytesize
rbuf_fill
end
rescue EOFError
@@ -115,10 +115,10 @@
until idx = @rbuf.index(terminator)
rbuf_fill
end
- return rbuf_consume(idx + terminator.size)
+ return rbuf_consume(idx + terminator.bytesize)
rescue EOFError
raise unless ignore_eof
- return rbuf_consume(@rbuf.size)
+ return rbuf_consume(@rbuf.bytesize)
end
end
@@ -131,9 +131,10 @@
BUFSIZE = 1024 * 16
def rbuf_fill
- timeout(@read_timeout) {
+ # XXX MacRuby timeout doesn't really work right now actually
+ # timeout(@read_timeout) {
@rbuf << @io.sysread(BUFSIZE)
- }
+ #}
# XXX MacRuby : Until we implement read_nonblock, write_nonbloick,
# IO::WaitReadable and IO::WaitWritable, let's use the old method using timeout
# begin
@@ -235,7 +236,7 @@
LOG_off()
read_bytes = 0
while (line = readuntil("\r\n")) != ".\r\n"
- read_bytes += line.size
+ read_bytes += line.bytesize
yield line.sub(/\A\./, '')
end
LOG_on()
@@ -316,7 +317,7 @@
def buffer_filling(buf, src)
case src
when String # for speeding up.
- 0.step(src.size - 1, 1024) do |i|
+ 0.step(src.bytesize - 1, 1024) do |i|
buf << src[i, 1024]
yield
end
@@ -328,7 +329,7 @@
else # generic reader
src.each do |str|
buf << str
- yield if buf.size > 1024
+ yield if buf.bytesize > 1024
end
yield unless buf.empty?
end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100616/0be24ed3/attachment.html>
More information about the macruby-changes
mailing list