Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > sysread and buffered I/O

Reply
Thread Tools

sysread and buffered I/O

 
 
Hal Fulton
Guest
Posts: n/a
 
      07-21-2004
I've been playing with telnet (and ssh) and I've been
pondering something.

Mixing sysread with buffered I/O is a Bad Thing (TM).

In fact, when I try to treat a telnet object as a socket
(which it is) and read from it using gets(), it crashes.
Not surprising.

So I was wondering: Would it make sense to have something like
"class SysIO < IO" where SysIO would do its own internal buffering
(and do everything in terms of sysread/-write at the lowest level)?

It would be a little like wheel-reinventing, but it would provide
an IO object on which these operations could be mixed.

Does this make sense or not?


Hal




 
Reply With Quote
 
 
 
 
Tanaka Akira
Guest
Posts: n/a
 
      07-21-2004
In article <(E-Mail Removed)>,
Hal Fulton <(E-Mail Removed)> writes:

> I've been playing with telnet (and ssh) and I've been
> pondering something.
>
> Mixing sysread with buffered I/O is a Bad Thing (TM).
>
> In fact, when I try to treat a telnet object as a socket
> (which it is) and read from it using gets(), it crashes.
> Not surprising.


I proposed stdio friendly sysread like method: readpartial.
[ruby-dev:23247] [ruby-talk:96220]

However it is not incorporated into ruby just because the name is not
good enough. Currently I think readchunk is better, though.

If net/telnet use readchunk instead of sysread, gets and other stdio
methods can be used as usual without buffering problem, maybe.

> So I was wondering: Would it make sense to have something like
> "class SysIO < IO" where SysIO would do its own internal buffering
> (and do everything in terms of sysread/-write at the lowest level)?
>
> It would be a little like wheel-reinventing, but it would provide
> an IO object on which these operations could be mixed.
>
> Does this make sense or not?


The new class SysIO is not required.
I think matz will accept stdio-less implementation for IO.
--
Tanaka Akira


 
Reply With Quote
 
 
 
 
Hal Fulton
Guest
Posts: n/a
 
      07-21-2004
Tanaka Akira wrote:
> I proposed stdio friendly sysread like method: readpartial.
> [ruby-dev:23247] [ruby-talk:96220]


Very interesting, I did not notice that. Thank you.

> However it is not incorporated into ruby just because the name is not
> good enough. Currently I think readchunk is better, though.


I am not sure I like readchunk. I think I prefer an underscore
at least. Other ideas might be:
read_partial # looks better with underscore?
read_part
read_any
read_all (?)
read_waiting (?)
read_avail # meaning "available"
read_bytes
readbytes # looks ok without underscore?

> The new class SysIO is not required.
> I think matz will accept stdio-less implementation for IO.


OK, I see. The code is already written? Are we just seeking
a name?


Hal



 
Reply With Quote
 
Tanaka Akira
Guest
Posts: n/a
 
      07-21-2004
In article <(E-Mail Removed)>,
Hal Fulton <(E-Mail Removed)> writes:

> I am not sure I like readchunk. I think I prefer an underscore
> at least. Other ideas might be:
> read_partial # looks better with underscore?
> read_part
> read_any
> read_all (?)
> read_waiting (?)
> read_avail # meaning "available"
> read_bytes
> readbytes # looks ok without underscore?


An underscore is inconsistent with other IO read??? methods: readchar,
readline, readlines.

Also, readbytes is already used by lib/readbytes.rb.

> OK, I see. The code is already written? Are we just seeking
> a name?


Currently Ruby uses stdio because no one write it.
--
Tanaka Akira


 
Reply With Quote
 
Hal Fulton
Guest
Posts: n/a
 
      07-21-2004
Tanaka Akira wrote:

>>I am not sure I like readchunk. I think I prefer an underscore
>>at least. Other ideas might be:
>> read_partial # looks better with underscore?
>> read_part
>> read_any
>> read_all (?)
>> read_waiting (?)
>> read_avail # meaning "available"
>> read_bytes
>> readbytes # looks ok without underscore?

>
> An underscore is inconsistent with other IO read??? methods: readchar,
> readline, readlines.


I see. Well, maybe:
readchars # with an s
readstr # could be 'string' or 'stream'
readsys # reminds us of sysread

But I do not really care much, readchunk is ok if it works.


> Currently Ruby uses stdio because no one write it.


I do not know much about low-level I/O. How hard would this
be to do?


Hal



 
Reply With Quote
 
Tanaka Akira
Guest
Posts: n/a
 
      07-21-2004
In article <(E-Mail Removed)>,
Hal Fulton <(E-Mail Removed)> writes:

>>>I am not sure I like readchunk. I think I prefer an underscore
>>>at least. Other ideas might be:
>>> read_partial # looks better with underscore?
>>> read_part
>>> read_any
>>> read_all (?)
>>> read_waiting (?)
>>> read_avail # meaning "available"
>>> read_bytes
>>> readbytes # looks ok without underscore?

>>
>> An underscore is inconsistent with other IO read??? methods: readchar,
>> readline, readlines.

>
> I see. Well, maybe:
> readchars # with an s
> readstr # could be 'string' or 'stream'
> readsys # reminds us of sysread


any: doesn't represent readpartial's behavior.
all: readpartial doesn't return all data from a stream.
waiting: readpartial may return non-waiting data if buffer is empty.
avail: readpartial may return data which is not available when readpartial is called.
bytes: doesn't represent the difference from IO#read.
chars: readpartial doesn't treat characters and encodings.
str: doesn't represent the difference from IO#read.
sys: readpartial is not system call.

> But I do not really care much, readchunk is ok if it works.


Good name is necessary to incorporate a method to ruby.
--
Tanaka Akira


 
Reply With Quote
 
Hal Fulton
Guest
Posts: n/a
 
      07-21-2004
Tanaka Akira wrote:
>
> Good name is necessary to incorporate a method to ruby.


Certainly, I agree fully.

How much work is it to implement this method? I may not be
knowledgeable enough to do it myself, but I would be willing
to assist someone if I can.


Hal




 
Reply With Quote
 
Tanaka Akira
Guest
Posts: n/a
 
      07-21-2004
In article <(E-Mail Removed)>,
Hal Fulton <(E-Mail Removed)> writes:

> How much work is it to implement this method? I may not be
> knowledgeable enough to do it myself, but I would be willing
> to assist someone if I can.


See [ruby-dev:23247] and [ruby-dev:23248].

However now I think readpartial should raise EOFError on EOF.
The implementation in [ruby-dev:23247] returns nil on EOF.
--
Tanaka Akira


 
Reply With Quote
 
Mark Firestone
Guest
Posts: n/a
 
      07-21-2004
Does anyone know of a good way to basically seek through a large query
record by record (like we used to do with the SEEK command in Clipper?) ...
I am converting the Ruby BBS to use postgres. Basically, I have real
message numbers and the message numbers displayed by the system (so the
messages can be 1-x) but the real message numbers (which are unique and
assending) can be used to keep track of the last read pointer.

I could make an array of message numbers, each time a user trys to pull a
message up, but this seens wasteful.

Thanks.

Mark

"But Schindler is bueno! Senior Burns is El Diablo!"

--------------------------------------------------------------
Website - http://www.retrobbs.org
Tradewars - telnet tradewars.retrobbs.org
BBS - http://bbs.retrobbs.org:8000
IRC - irc.retrobbs.org #main
WIKI - http://www.tpoh.org/cgi-bin/tpoh-wiki



 
Reply With Quote
 
Gavin Sinclair
Guest
Posts: n/a
 
      07-21-2004
On Wednesday, July 21, 2004, 6:22:19 PM, Tanaka wrote:

>> But I do not really care much, readchunk is ok if it works.


> Good name is necessary to incorporate a method to ruby.


Here's the relevant bit from the relevant ruby-dev summary:

TANAKA Akira suggested a new method IO#readpartial, which is
a better sysread() implementation supporting stdio buffer and
avoiding troubles due to non-blocking I/O.

Tanaka, can you please give a brief description of the method (assume
I know nothing about advanced I/O), and I'll suggest a name. Of
course, other people will too.

Gavin



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Strange Errno::EOVERFLOW error with IO#read and IO#sysread Daniel Berger Ruby 4 09-12-2008 06:44 PM
Read socket using both <> and sysread() Yohan N. Leder Perl Misc 13 08-12-2006 11:21 AM
Buffered socket I/O with sysread-style blocking? James Marshall Perl Misc 21 03-29-2006 03:46 PM
whether is the standard input stream full buffered or line buffered after calling function setbuf()? kernelxu@hotmail.com C Programming 9 08-23-2005 02:24 PM
perl problem with select and non-blocking sysread from multiple pipes john Perl Misc 7 03-04-2005 02:34 PM



Advertisments