1999-10-13 03:29:15 -04:00
|
|
|
=begin
|
|
|
|
|
2001-12-13 14:15:21 -05:00
|
|
|
= net/protocol.rb
|
1999-10-13 03:29:15 -04:00
|
|
|
|
2003-05-02 10:35:01 -04:00
|
|
|
Copyright (c) 1999-2003 Yukihiro Matsumoto
|
|
|
|
Copyright (c) 1999-2003 Minero Aoki
|
1999-10-13 03:29:15 -04:00
|
|
|
|
2003-06-06 03:05:52 -04:00
|
|
|
written and maintained by Minero Aoki <aamine@loveruby.net>
|
1999-10-13 03:29:15 -04:00
|
|
|
|
2001-06-26 19:49:21 -04:00
|
|
|
This program is free software. You can re-distribute and/or
|
|
|
|
modify this program under the same terms as Ruby itself,
|
|
|
|
Ruby Distribute License or GNU General Public License.
|
2001-02-23 23:53:50 -05:00
|
|
|
|
2001-12-13 14:15:21 -05:00
|
|
|
$Id$
|
|
|
|
|
2003-06-06 03:05:52 -04:00
|
|
|
WARNING: This file is going to remove.
|
|
|
|
Do not rely on the implementation written in this file.
|
|
|
|
|
1999-10-13 03:29:15 -04:00
|
|
|
=end
|
|
|
|
|
2000-06-16 09:47:38 -04:00
|
|
|
require 'socket'
|
2001-02-06 06:14:51 -05:00
|
|
|
require 'timeout'
|
2000-06-16 09:47:38 -04:00
|
|
|
|
|
|
|
|
|
|
|
module Net
|
|
|
|
|
2003-05-02 11:19:20 -04:00
|
|
|
class Protocol
|
|
|
|
private
|
|
|
|
def Protocol.protocol_param( name, val )
|
|
|
|
module_eval(<<-End, __FILE__, __LINE__ + 1)
|
|
|
|
def #{name}
|
|
|
|
#{val}
|
|
|
|
end
|
|
|
|
End
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2000-03-31 08:02:40 -05:00
|
|
|
class ProtocolError < StandardError; end
|
|
|
|
class ProtoSyntaxError < ProtocolError; end
|
|
|
|
class ProtoFatalError < ProtocolError; end
|
|
|
|
class ProtoUnknownError < ProtocolError; end
|
|
|
|
class ProtoServerError < ProtocolError; end
|
|
|
|
class ProtoAuthError < ProtocolError; end
|
|
|
|
class ProtoCommandError < ProtocolError; end
|
|
|
|
class ProtoRetriableError < ProtocolError; end
|
|
|
|
ProtocRetryError = ProtoRetriableError
|
1999-12-17 10:00:13 -05:00
|
|
|
|
aamine
* lib/net/protocol.rb, smtp.rb, pop.rb, http.rb: 1.1.26.
* lib/net/protocol.rb, smtp.rb, pop.rb, http.rb:
add module Net::NetPrivate and its inner classes
{Read,Write}Adapter, Command, Socket,
SMTPCommand, POP3Command, APOPCommand, HTTPCommand
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@826 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2000-07-12 02:04:40 -04:00
|
|
|
|
2002-02-19 07:33:52 -05:00
|
|
|
class InternetMessageIO
|
1999-12-17 10:00:13 -05:00
|
|
|
|
2001-12-30 14:18:45 -05:00
|
|
|
class << self
|
|
|
|
alias open new
|
|
|
|
end
|
2001-02-06 06:14:51 -05:00
|
|
|
|
2003-07-01 22:34:39 -04:00
|
|
|
def initialize( addr, port,
|
|
|
|
open_timeout = nil, read_timeout = nil,
|
|
|
|
debug_output = nil )
|
2001-12-30 14:18:45 -05:00
|
|
|
@address = addr
|
|
|
|
@port = port
|
2003-07-01 22:34:39 -04:00
|
|
|
@read_timeout = read_timeout
|
|
|
|
@debug_output = debug_output
|
|
|
|
@socket = nil
|
|
|
|
@rbuf = nil # read buffer
|
|
|
|
@wbuf = nil # write buffer
|
|
|
|
connect open_timeout
|
|
|
|
LOG 'opened'
|
2001-02-22 18:23:57 -05:00
|
|
|
end
|
|
|
|
|
2001-12-30 14:18:45 -05:00
|
|
|
attr_reader :address
|
|
|
|
attr_reader :port
|
1999-12-17 10:00:13 -05:00
|
|
|
|
2001-12-30 14:18:45 -05:00
|
|
|
def ip_address
|
2003-07-01 22:34:39 -04:00
|
|
|
return '' unless @socket
|
2001-12-30 14:18:45 -05:00
|
|
|
@socket.addr[3]
|
1999-12-17 10:00:13 -05:00
|
|
|
end
|
|
|
|
|
2002-02-22 07:10:58 -05:00
|
|
|
attr_accessor :read_timeout
|
|
|
|
|
2001-12-30 14:18:45 -05:00
|
|
|
attr_reader :socket
|
2000-06-12 12:42:46 -04:00
|
|
|
|
2003-07-01 22:34:39 -04:00
|
|
|
def connect( open_timeout )
|
|
|
|
LOG "opening connection to #{@address}..."
|
|
|
|
timeout(open_timeout) {
|
|
|
|
@socket = TCPsocket.new(@address, @port)
|
2001-12-30 14:18:45 -05:00
|
|
|
}
|
|
|
|
@rbuf = ''
|
1999-12-17 10:00:13 -05:00
|
|
|
end
|
2001-12-30 14:18:45 -05:00
|
|
|
private :connect
|
1999-12-17 10:00:13 -05:00
|
|
|
|
|
|
|
def close
|
2002-11-21 06:50:09 -05:00
|
|
|
if @socket
|
2001-02-22 18:23:57 -05:00
|
|
|
@socket.close
|
2003-07-01 22:34:39 -04:00
|
|
|
LOG 'closed'
|
2001-02-22 18:23:57 -05:00
|
|
|
else
|
2003-07-01 22:34:39 -04:00
|
|
|
LOG 'close call for already closed socket'
|
2001-02-22 18:23:57 -05:00
|
|
|
end
|
|
|
|
@socket = nil
|
2001-12-13 14:15:21 -05:00
|
|
|
@rbuf = ''
|
1999-12-17 10:00:13 -05:00
|
|
|
end
|
|
|
|
|
2003-07-01 22:34:39 -04:00
|
|
|
def reopen( open_timeout = nil )
|
|
|
|
LOG 'reopening...'
|
2001-12-30 14:18:45 -05:00
|
|
|
close
|
2003-07-01 22:34:39 -04:00
|
|
|
connect open_timeout
|
|
|
|
LOG 'reopened'
|
1999-12-17 10:00:13 -05:00
|
|
|
end
|
|
|
|
|
2001-12-30 14:18:45 -05:00
|
|
|
def closed?
|
|
|
|
not @socket
|
1999-12-17 10:00:13 -05:00
|
|
|
end
|
2000-11-16 09:03:20 -05:00
|
|
|
|
2001-12-30 14:18:45 -05:00
|
|
|
def inspect
|
2003-07-01 22:34:39 -04:00
|
|
|
"#<#{self.class} #{closed?() ? 'closed' : 'opened'}>"
|
1999-12-17 10:00:13 -05:00
|
|
|
end
|
2000-11-16 09:03:20 -05:00
|
|
|
|
2001-12-30 14:18:45 -05:00
|
|
|
###
|
|
|
|
### READ
|
|
|
|
###
|
1999-12-17 10:00:13 -05:00
|
|
|
|
2001-02-06 06:14:51 -05:00
|
|
|
public
|
2000-11-16 09:03:20 -05:00
|
|
|
|
2003-07-01 22:34:39 -04:00
|
|
|
def read( len, dest = '', ignore_eof = false )
|
|
|
|
LOG "reading #{len} bytes..."
|
|
|
|
LOG_off()
|
|
|
|
read_bytes = 0
|
2001-01-16 02:57:43 -05:00
|
|
|
begin
|
2003-07-01 22:34:39 -04:00
|
|
|
while read_bytes + @rbuf.size < len
|
|
|
|
read_bytes += rbuf_moveto(dest, @rbuf.size)
|
2001-02-07 12:17:51 -05:00
|
|
|
rbuf_fill
|
2001-01-16 02:57:43 -05:00
|
|
|
end
|
2003-07-01 22:34:39 -04:00
|
|
|
rbuf_moveto dest, len - read_bytes
|
2001-01-16 02:57:43 -05:00
|
|
|
rescue EOFError
|
2003-07-01 22:34:39 -04:00
|
|
|
raise unless ignore_eof
|
1999-09-22 03:32:33 -04:00
|
|
|
end
|
2003-07-01 22:34:39 -04:00
|
|
|
LOG_on()
|
|
|
|
LOG "read #{read_bytes} bytes"
|
2000-03-31 08:02:40 -05:00
|
|
|
dest
|
1999-09-22 03:32:33 -04:00
|
|
|
end
|
|
|
|
|
2000-03-31 08:02:40 -05:00
|
|
|
def read_all( dest = '' )
|
2003-07-01 22:34:39 -04:00
|
|
|
LOG 'reading all...'
|
|
|
|
LOG_off()
|
|
|
|
read_bytes = 0
|
2000-01-21 07:52:24 -05:00
|
|
|
begin
|
2002-11-21 06:50:09 -05:00
|
|
|
while true
|
2003-07-01 22:34:39 -04:00
|
|
|
read_bytes += rbuf_moveto(dest, @rbuf.size)
|
2001-02-07 12:17:51 -05:00
|
|
|
rbuf_fill
|
2000-01-21 07:52:24 -05:00
|
|
|
end
|
|
|
|
rescue EOFError
|
|
|
|
;
|
|
|
|
end
|
2003-07-01 22:34:39 -04:00
|
|
|
LOG_on()
|
|
|
|
LOG "read #{read_bytes} bytes"
|
2000-03-31 08:02:40 -05:00
|
|
|
dest
|
2000-01-21 07:52:24 -05:00
|
|
|
end
|
|
|
|
|
2003-07-01 22:34:39 -04:00
|
|
|
def readuntil( terminator, ignore_eof = false )
|
2000-03-31 08:02:40 -05:00
|
|
|
dest = ''
|
2001-01-16 02:57:43 -05:00
|
|
|
begin
|
2003-07-01 22:34:39 -04:00
|
|
|
until idx = @rbuf.index(terminator)
|
2001-02-07 12:17:51 -05:00
|
|
|
rbuf_fill
|
2001-01-16 02:57:43 -05:00
|
|
|
end
|
2003-07-01 22:34:39 -04:00
|
|
|
rbuf_moveto dest, idx + terminator.size
|
2001-01-16 02:57:43 -05:00
|
|
|
rescue EOFError
|
2003-07-01 22:34:39 -04:00
|
|
|
raise unless ignore_eof
|
2001-12-13 14:15:21 -05:00
|
|
|
rbuf_moveto dest, @rbuf.size
|
2001-01-16 02:57:43 -05:00
|
|
|
end
|
2000-03-31 08:02:40 -05:00
|
|
|
dest
|
1999-09-22 03:32:33 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def readline
|
2003-07-01 22:34:39 -04:00
|
|
|
readuntil("\n").chop
|
1999-09-22 03:32:33 -04:00
|
|
|
end
|
|
|
|
|
2003-07-01 22:34:39 -04:00
|
|
|
def each_message_chunk
|
|
|
|
LOG 'reading message...'
|
|
|
|
LOG_off()
|
|
|
|
read_bytes = 0
|
|
|
|
while (line = readuntil("\r\n")) != ".\r\n"
|
|
|
|
read_bytes += line.size
|
|
|
|
yield line.sub(/\A\./, '')
|
|
|
|
end
|
|
|
|
LOG_on()
|
|
|
|
LOG "read message (#{read_bytes} bytes)"
|
|
|
|
end
|
|
|
|
|
|
|
|
# *library private* (cannot handle 'break')
|
|
|
|
def each_list_item
|
|
|
|
while (str = readuntil("\r\n")) != ".\r\n"
|
|
|
|
yield str.chop
|
|
|
|
end
|
|
|
|
end
|
1999-09-22 03:32:33 -04:00
|
|
|
|
2003-07-01 22:34:39 -04:00
|
|
|
private
|
1999-09-22 03:32:33 -04:00
|
|
|
|
2001-02-07 12:17:51 -05:00
|
|
|
def rbuf_fill
|
2003-07-01 22:34:39 -04:00
|
|
|
until IO.select([@socket], nil, nil, @read_timeout)
|
|
|
|
raise TimeoutError, "socket read timeout (#{@read_timeout} sec)"
|
2001-02-06 06:14:51 -05:00
|
|
|
end
|
2003-07-01 22:34:39 -04:00
|
|
|
@rbuf << @socket.sysread(1024)
|
1999-09-22 03:32:33 -04:00
|
|
|
end
|
|
|
|
|
2001-02-07 12:17:51 -05:00
|
|
|
def rbuf_moveto( dest, len )
|
2001-12-13 14:15:21 -05:00
|
|
|
dest << (s = @rbuf.slice!(0, len))
|
2002-03-26 06:18:02 -05:00
|
|
|
@debug_output << %Q[-> #{s.dump}\n] if @debug_output
|
2000-01-21 07:52:24 -05:00
|
|
|
len
|
1999-12-17 10:00:13 -05:00
|
|
|
end
|
1999-09-22 03:32:33 -04:00
|
|
|
|
2001-12-30 14:18:45 -05:00
|
|
|
###
|
|
|
|
### WRITE
|
|
|
|
###
|
|
|
|
|
1999-09-22 03:32:33 -04:00
|
|
|
public
|
|
|
|
|
2000-03-26 03:48:15 -05:00
|
|
|
def write( str )
|
2000-06-27 09:36:17 -04:00
|
|
|
writing {
|
2003-07-01 22:34:39 -04:00
|
|
|
write0 str
|
2000-06-27 09:36:17 -04:00
|
|
|
}
|
1999-09-22 03:32:33 -04:00
|
|
|
end
|
|
|
|
|
2000-03-26 03:48:15 -05:00
|
|
|
def writeline( str )
|
2000-06-27 09:36:17 -04:00
|
|
|
writing {
|
2003-07-01 22:34:39 -04:00
|
|
|
write0 str + "\r\n"
|
2000-06-27 09:36:17 -04:00
|
|
|
}
|
1999-09-22 03:32:33 -04:00
|
|
|
end
|
|
|
|
|
2003-07-01 22:34:39 -04:00
|
|
|
def write_message( src )
|
|
|
|
LOG "writing message from #{src.class}"
|
|
|
|
LOG_off()
|
|
|
|
len = using_each_crlf_line {
|
|
|
|
write_message_0 src
|
|
|
|
}
|
|
|
|
LOG_on()
|
|
|
|
LOG "wrote #{len} bytes"
|
|
|
|
len
|
|
|
|
end
|
|
|
|
|
|
|
|
def write_message_by_block( &block )
|
|
|
|
LOG 'writing message from block'
|
|
|
|
LOG_off()
|
|
|
|
len = using_each_crlf_line {
|
|
|
|
begin
|
|
|
|
block.call(WriteAdapter.new(self, :write_message_0))
|
|
|
|
rescue LocalJumpError
|
|
|
|
# allow `break' from writer block
|
|
|
|
end
|
|
|
|
}
|
|
|
|
LOG_on()
|
|
|
|
LOG "wrote #{len} bytes"
|
|
|
|
len
|
|
|
|
end
|
|
|
|
|
2002-02-19 07:33:52 -05:00
|
|
|
private
|
|
|
|
|
|
|
|
def writing
|
2003-07-01 22:34:39 -04:00
|
|
|
@written_bytes = 0
|
2002-03-26 06:18:02 -05:00
|
|
|
@debug_output << '<- ' if @debug_output
|
2002-02-19 07:33:52 -05:00
|
|
|
yield
|
|
|
|
@socket.flush
|
2002-03-26 06:18:02 -05:00
|
|
|
@debug_output << "\n" if @debug_output
|
2003-07-01 22:34:39 -04:00
|
|
|
bytes = @written_bytes
|
|
|
|
@written_bytes = nil
|
|
|
|
bytes
|
2002-02-19 07:33:52 -05:00
|
|
|
end
|
|
|
|
|
2003-07-01 22:34:39 -04:00
|
|
|
def write0( str )
|
2002-03-26 06:18:02 -05:00
|
|
|
@debug_output << str.dump if @debug_output
|
2003-07-01 22:34:39 -04:00
|
|
|
len = @socket.write(str)
|
|
|
|
@written_bytes += len
|
|
|
|
len
|
1999-09-22 03:32:33 -04:00
|
|
|
end
|
|
|
|
|
2001-12-30 14:18:45 -05:00
|
|
|
#
|
2003-07-01 22:34:39 -04:00
|
|
|
# Reads string from src calling :each, and write to @socket.
|
|
|
|
# Escapes '.' on the each line head.
|
2001-12-30 14:18:45 -05:00
|
|
|
#
|
2003-07-01 22:34:39 -04:00
|
|
|
def write_message_0( src )
|
|
|
|
prev = @written_bytes
|
2002-11-21 06:50:09 -05:00
|
|
|
each_crlf_line(src) do |line|
|
2003-07-01 22:34:39 -04:00
|
|
|
if line[0] == ?.
|
|
|
|
then write0 '.' + line
|
|
|
|
else write0 line
|
|
|
|
end
|
2000-06-27 09:36:17 -04:00
|
|
|
end
|
2003-07-01 22:34:39 -04:00
|
|
|
@written_bytes - prev
|
2000-02-21 10:27:49 -05:00
|
|
|
end
|
|
|
|
|
2003-07-01 22:34:39 -04:00
|
|
|
#
|
|
|
|
# setup @wbuf for each_crlf_line.
|
|
|
|
#
|
2001-12-13 14:15:21 -05:00
|
|
|
def using_each_crlf_line
|
2000-06-27 09:36:17 -04:00
|
|
|
writing {
|
2001-12-30 14:18:45 -05:00
|
|
|
@wbuf = ''
|
|
|
|
yield
|
2002-11-21 06:50:09 -05:00
|
|
|
if not @wbuf.empty? # unterminated last line
|
|
|
|
if @wbuf[-1] == ?\r
|
2001-12-30 14:18:45 -05:00
|
|
|
@wbuf.chop!
|
|
|
|
end
|
|
|
|
@wbuf.concat "\r\n"
|
2003-07-01 22:34:39 -04:00
|
|
|
write0 @wbuf
|
|
|
|
elsif @written_bytes == 0 # empty src
|
|
|
|
write0 "\r\n"
|
2000-06-27 09:36:17 -04:00
|
|
|
end
|
2003-07-01 22:34:39 -04:00
|
|
|
write0 ".\r\n"
|
2001-12-30 14:18:45 -05:00
|
|
|
@wbuf = nil
|
2000-06-27 09:36:17 -04:00
|
|
|
}
|
|
|
|
end
|
1999-09-22 03:32:33 -04:00
|
|
|
|
2003-07-01 22:34:39 -04:00
|
|
|
#
|
|
|
|
# extract a CR-LF-terminating-line from @wbuf and yield it.
|
|
|
|
#
|
2000-06-27 09:36:17 -04:00
|
|
|
def each_crlf_line( src )
|
2002-11-21 06:50:09 -05:00
|
|
|
adding(src) do
|
2000-07-01 14:28:24 -04:00
|
|
|
beg = 0
|
2000-06-27 09:36:17 -04:00
|
|
|
buf = @wbuf
|
2002-11-21 06:50:09 -05:00
|
|
|
while buf.index(/\n|\r\n|\r/, beg)
|
2001-02-22 18:23:57 -05:00
|
|
|
m = Regexp.last_match
|
2003-07-01 22:34:39 -04:00
|
|
|
if (m.begin(0) == buf.length - 1) and buf[-1] == ?\r
|
2000-06-16 09:47:38 -04:00
|
|
|
# "...\r" : can follow "\n..."
|
|
|
|
break
|
|
|
|
end
|
2003-07-01 22:34:39 -04:00
|
|
|
str = buf[beg ... m.begin(0)]
|
2000-06-16 09:47:38 -04:00
|
|
|
str.concat "\r\n"
|
2000-06-27 09:36:17 -04:00
|
|
|
yield str
|
|
|
|
beg = m.end(0)
|
1999-09-22 03:32:33 -04:00
|
|
|
end
|
2003-07-01 22:34:39 -04:00
|
|
|
@wbuf = buf[beg ... buf.length]
|
1999-09-22 03:32:33 -04:00
|
|
|
end
|
2000-02-21 10:27:49 -05:00
|
|
|
end
|
|
|
|
|
2003-07-01 22:34:39 -04:00
|
|
|
#
|
|
|
|
# Reads strings from SRC and add to @wbuf, then yield.
|
|
|
|
#
|
2000-06-27 09:36:17 -04:00
|
|
|
def adding( src )
|
2000-02-21 10:27:49 -05:00
|
|
|
case src
|
2003-07-01 22:34:39 -04:00
|
|
|
when String # for speeding up.
|
2002-11-21 06:50:09 -05:00
|
|
|
0.step(src.size - 1, 2048) do |i|
|
2000-06-27 09:36:17 -04:00
|
|
|
@wbuf << src[i,2048]
|
2000-02-21 10:27:49 -05:00
|
|
|
yield
|
|
|
|
end
|
|
|
|
|
2003-07-01 22:34:39 -04:00
|
|
|
when File # for speeding up.
|
2002-11-21 06:50:09 -05:00
|
|
|
while s = src.read(2048)
|
|
|
|
s[0,0] = @wbuf
|
|
|
|
@wbuf = s
|
2000-02-21 10:27:49 -05:00
|
|
|
yield
|
|
|
|
end
|
|
|
|
|
2003-07-01 22:34:39 -04:00
|
|
|
else # generic reader
|
2002-11-21 06:50:09 -05:00
|
|
|
src.each do |s|
|
|
|
|
@wbuf << s
|
|
|
|
yield if @wbuf.size > 2048
|
2000-02-21 10:27:49 -05:00
|
|
|
end
|
2001-01-13 14:07:15 -05:00
|
|
|
yield unless @wbuf.empty?
|
2000-02-21 10:27:49 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2001-12-30 14:18:45 -05:00
|
|
|
###
|
|
|
|
### DEBUG
|
|
|
|
###
|
|
|
|
|
|
|
|
private
|
2000-03-31 08:02:40 -05:00
|
|
|
|
2003-07-01 22:34:39 -04:00
|
|
|
def LOG_off
|
|
|
|
@save_debug_out = @debug_output
|
|
|
|
@debug_output = nil
|
2000-03-31 08:02:40 -05:00
|
|
|
end
|
|
|
|
|
2003-07-01 22:34:39 -04:00
|
|
|
def LOG_on
|
|
|
|
@debug_output = @save_debug_out
|
2001-02-22 18:23:57 -05:00
|
|
|
end
|
|
|
|
|
2003-07-01 22:34:39 -04:00
|
|
|
def LOG( msg )
|
|
|
|
return unless @debug_output
|
2002-03-26 06:18:02 -05:00
|
|
|
@debug_output << msg
|
|
|
|
@debug_output << "\n"
|
2000-03-31 08:02:40 -05:00
|
|
|
end
|
2002-02-19 07:33:52 -05:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2003-07-01 22:34:39 -04:00
|
|
|
#
|
|
|
|
# The writer adapter class
|
|
|
|
#
|
2002-02-19 07:33:52 -05:00
|
|
|
class WriteAdapter
|
|
|
|
|
|
|
|
def initialize( sock, mid )
|
|
|
|
@socket = sock
|
2003-07-01 22:34:39 -04:00
|
|
|
@method_id = mid
|
2002-02-19 07:33:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def inspect
|
2002-10-02 12:45:35 -04:00
|
|
|
"#<#{self.class} socket=#{@socket.inspect}>"
|
2002-02-19 07:33:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def write( str )
|
2003-07-01 22:34:39 -04:00
|
|
|
@socket.__send__(@method_id, str)
|
2002-02-19 07:33:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
alias print write
|
|
|
|
|
|
|
|
def <<( str )
|
|
|
|
write str
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
def puts( str = '' )
|
|
|
|
write str.sub(/\n?/, "\n")
|
|
|
|
end
|
|
|
|
|
|
|
|
def printf( *args )
|
|
|
|
write sprintf(*args)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2003-07-01 22:34:39 -04:00
|
|
|
#
|
|
|
|
# The reader adapter class for internal use only.
|
|
|
|
#
|
2002-02-19 07:33:52 -05:00
|
|
|
class ReadAdapter
|
|
|
|
|
|
|
|
def initialize( block )
|
|
|
|
@block = block
|
|
|
|
end
|
2000-03-31 08:02:40 -05:00
|
|
|
|
2002-02-19 07:33:52 -05:00
|
|
|
def inspect
|
2002-10-02 12:45:35 -04:00
|
|
|
"#<#{self.class}>"
|
2002-02-19 07:33:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def <<( str )
|
2002-11-21 06:50:09 -05:00
|
|
|
call_block(str, &@block) if @block
|
2002-02-19 07:33:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2003-07-01 22:34:39 -04:00
|
|
|
#
|
|
|
|
# This method is needed because @block must be called by yield,
|
|
|
|
# not Proc#call. You can see difference when using `break' in
|
|
|
|
# the block.
|
|
|
|
#
|
2002-02-19 07:33:52 -05:00
|
|
|
def call_block( str )
|
|
|
|
yield str
|
|
|
|
end
|
|
|
|
|
1999-12-17 10:00:13 -05:00
|
|
|
end
|
1999-09-22 03:32:33 -04:00
|
|
|
|
2003-07-01 22:05:35 -04:00
|
|
|
|
|
|
|
# For backward compatibility
|
|
|
|
module NetPrivate
|
|
|
|
Socket = ::Net::InternetMessageIO
|
|
|
|
end
|
|
|
|
|
1999-12-17 10:00:13 -05:00
|
|
|
end # module Net
|