[#1263] Draft of the updated Ruby FAQ — Dave Thomas <Dave@...>

33 messages 2000/02/08

[#1376] Re: Scripting versus programming — Andrew Hunt <andy@...>

Conrad writes:

13 messages 2000/02/15

[#1508] Ruby/GTK and the mainloop — Ian Main <imain@...>

17 messages 2000/02/19
[#1544] Re: Ruby/GTK and the mainloop — Yasushi Shoji <yashi@...> 2000/02/23

Hello Ian,

[#1550] Re: Ruby/GTK and the mainloop — Ian Main <imain@...> 2000/02/23

On Wed, Feb 23, 2000 at 02:56:10AM -0500, Yasushi Shoji wrote:

[#1516] Ruby: PLEASE use comp.lang.misc for all Ruby programming/technical questions/discussions!!!! — "Conrad Schneiker" <schneiker@...>

((FYI: This was sent to the Ruby mail list.))

10 messages 2000/02/19

[#1569] Re: Ruby: constructors, new and initialise — Yukihiro Matsumoto <matz@...>

The following message is a courtesy copy of an article

12 messages 2000/02/25

[ruby-talk:01345] thread specific data in Ruby

From: Tomoyuki Kosimizu <greentea@...2.so-net.ne.jp>
Date: 2000-02-14 22:46:10 UTC
List: ruby-talk #1345
Hi,

I wanted another version of IO#gets which limits line length
read. Although this is not good example, I should be happy to be of
any help to you.

BUFSIZ = 8192

def read_char(io)
  str = result = nil
  if not Thread.current[:_read_char_count] or
      Thread.current[:_read_char_count] == 0
    begin
      str = io.sysread(BUFSIZ)
    rescue Errno::EINTR
      retry
    rescue EOFError
      if str.nil? or str.size == 0
	Thread.current[:_read_char_buff] = nil
	Thread.current[:_read_char_count] = 0
	return -1
      end
    end
    Thread.current[:_read_char_buff] = str
    Thread.current[:_read_char_count] = str.size
  end
  result =
    Thread.current[:_read_char_buff][Thread.current[:_read_char_buff].size -
                                     Thread.current[:_read_char_count]]
  Thread.current[:_read_char_count] -= 1
  result
end

def read_line(io, maxlen)
  line = ''
  for i in 1..maxlen
    c = read_char(io)
    if c < 0
      if line.size == 0
	return nil
      else
	break
      end
    end
    line << c.chr
    if c == ?\n
      break
    end
  end
  if i == maxlen and line[-1] != ?\n
    raise 'too long line'
  end
  line
end

require 'socket'

accepter = TCPServer.open(0)
print('server is on ', (accepter.addr)[1], $/)

loop do
  conn = accepter.accept
  print(conn, ' is accepted', $/)
  Thread.start {
    soc = conn
    while (line = read_line(soc, 1024))
      line.chomp!
      soc.write(line << "\r\n")
    end
    print(soc, ' is gone', $/)
    soc.close
  }
end

# tomoyuki kosimizu
# greentea@fa2.so-net.ne.jp

In This Thread

Prev Next