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
|
|
|
|
2001-06-26 19:49:21 -04:00
|
|
|
written & 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-07 05:04:25 -05:00
|
|
|
NOTE: You can find Japanese version of this document in
|
|
|
|
the doc/net directory of the standard ruby interpreter package.
|
1999-10-13 03:29:15 -04:00
|
|
|
|
2001-12-13 14:15:21 -05:00
|
|
|
$Id$
|
|
|
|
|
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
|
|
|
|
2001-12-30 14:18:45 -05:00
|
|
|
def initialize( addr, port, otime = nil, rtime = nil, dout = nil )
|
|
|
|
@address = addr
|
|
|
|
@port = port
|
2001-02-06 06:14:51 -05:00
|
|
|
@read_timeout = rtime
|
2002-03-26 06:18:02 -05:00
|
|
|
@debug_output = dout
|
1999-12-17 10:00:13 -05:00
|
|
|
|
2001-12-30 14:18:45 -05:00
|
|
|
@socket = nil
|
|
|
|
@rbuf = nil
|
1999-12-17 10:00:13 -05:00
|
|
|
|
2001-02-22 18:23:57 -05:00
|
|
|
connect otime
|
|
|
|
D 'opened'
|
|
|
|
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
|
|
|
|
@socket or return ''
|
|
|
|
@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
|
|
|
|
2001-12-30 14:18:45 -05:00
|
|
|
def connect( otime )
|
|
|
|
D "opening connection to #{@address}..."
|
2002-11-21 06:50:09 -05:00
|
|
|
timeout(otime) {
|
|
|
|
@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
|
|
|
|
D 'closed'
|
|
|
|
else
|
|
|
|
D 'close call for already closed socket'
|
|
|
|
end
|
|
|
|
@socket = nil
|
2001-12-13 14:15:21 -05:00
|
|
|
@rbuf = ''
|
1999-12-17 10:00:13 -05:00
|
|
|
end
|
|
|
|
|
2001-12-30 14:18:45 -05:00
|
|
|
def reopen( otime = nil )
|
|
|
|
D 'reopening...'
|
|
|
|
close
|
|
|
|
connect otime
|
|
|
|
D '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
|
2002-10-02 12:45:35 -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
|
|
|
|
2001-12-30 14:18:45 -05:00
|
|
|
def read( len, dest = '', ignore = false )
|
2001-02-22 18:23:57 -05:00
|
|
|
D_off "reading #{len} bytes..."
|
1999-12-17 10:00:13 -05:00
|
|
|
|
1999-09-22 03:32:33 -04:00
|
|
|
rsize = 0
|
2001-01-16 02:57:43 -05:00
|
|
|
begin
|
2002-11-21 06:50:09 -05:00
|
|
|
while rsize + @rbuf.size < len
|
2001-12-30 14:18:45 -05:00
|
|
|
rsize += rbuf_moveto(dest, @rbuf.size)
|
2001-02-07 12:17:51 -05:00
|
|
|
rbuf_fill
|
2001-01-16 02:57:43 -05:00
|
|
|
end
|
2001-02-07 12:17:51 -05:00
|
|
|
rbuf_moveto dest, len - rsize
|
2001-01-16 02:57:43 -05:00
|
|
|
rescue EOFError
|
2001-12-30 14:18:45 -05:00
|
|
|
raise unless ignore
|
1999-09-22 03:32:33 -04:00
|
|
|
end
|
|
|
|
|
2001-02-22 18:23:57 -05:00
|
|
|
D_on "read #{len} 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 = '' )
|
2001-02-22 18:23:57 -05:00
|
|
|
D_off 'reading all...'
|
2000-01-21 07:52:24 -05:00
|
|
|
|
|
|
|
rsize = 0
|
|
|
|
begin
|
2002-11-21 06:50:09 -05:00
|
|
|
while true
|
2001-12-30 14:18:45 -05:00
|
|
|
rsize += 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
|
|
|
|
|
2001-02-22 18:23:57 -05:00
|
|
|
D_on "read #{rsize} bytes"
|
2000-03-31 08:02:40 -05:00
|
|
|
dest
|
2000-01-21 07:52:24 -05:00
|
|
|
end
|
|
|
|
|
2001-12-30 14:18:45 -05:00
|
|
|
def readuntil( target, ignore = false )
|
2000-03-31 08:02:40 -05:00
|
|
|
dest = ''
|
2001-01-16 02:57:43 -05:00
|
|
|
begin
|
2002-11-21 06:50:09 -05:00
|
|
|
until idx = @rbuf.index(target)
|
2001-02-07 12:17:51 -05:00
|
|
|
rbuf_fill
|
2001-01-16 02:57:43 -05:00
|
|
|
end
|
2001-02-07 12:17:51 -05:00
|
|
|
rbuf_moveto dest, idx + target.size
|
2001-01-16 02:57:43 -05:00
|
|
|
rescue EOFError
|
2001-12-30 14:18:45 -05:00
|
|
|
raise unless ignore
|
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
|
2001-12-30 14:18:45 -05:00
|
|
|
ret = readuntil("\n")
|
1999-09-22 03:32:33 -04:00
|
|
|
ret.chop!
|
1999-12-17 10:00:13 -05:00
|
|
|
ret
|
1999-09-22 03:32:33 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2002-02-19 07:33:52 -05:00
|
|
|
BLOCK_SIZE = 1024
|
1999-09-22 03:32:33 -04:00
|
|
|
|
2001-02-07 12:17:51 -05:00
|
|
|
def rbuf_fill
|
2002-11-21 06:50:09 -05:00
|
|
|
until IO.select [@socket], nil, nil, @read_timeout
|
2001-02-06 06:14:51 -05:00
|
|
|
on_read_timeout
|
|
|
|
end
|
2001-12-13 14:15:21 -05:00
|
|
|
@rbuf << @socket.sysread(BLOCK_SIZE)
|
2001-02-06 06:14:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def on_read_timeout
|
|
|
|
raise TimeoutError, "socket read timeout (#{@read_timeout} sec)"
|
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
|
|
|
|
2002-02-19 07:33:52 -05:00
|
|
|
#
|
|
|
|
# message read
|
|
|
|
#
|
|
|
|
|
|
|
|
public
|
|
|
|
|
|
|
|
def read_message_to( dest )
|
|
|
|
D_off 'reading text...'
|
|
|
|
|
|
|
|
rsize = 0
|
2002-11-21 06:50:09 -05:00
|
|
|
while (str = readuntil("\r\n")) != ".\r\n"
|
2002-02-19 07:33:52 -05:00
|
|
|
rsize += str.size
|
|
|
|
dest << str.sub(/\A\./, '')
|
|
|
|
end
|
|
|
|
|
|
|
|
D_on "read #{rsize} bytes"
|
|
|
|
dest
|
|
|
|
end
|
|
|
|
|
|
|
|
# private use only (cannot handle 'break')
|
|
|
|
def each_list_item
|
2002-11-21 06:50:09 -05:00
|
|
|
while (str = readuntil("\r\n")) != ".\r\n"
|
2002-02-19 07:33:52 -05:00
|
|
|
yield str.chop
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
1999-09-22 03:32:33 -04:00
|
|
|
|
2001-12-30 14:18:45 -05:00
|
|
|
###
|
|
|
|
### WRITE
|
|
|
|
###
|
|
|
|
|
2001-02-06 06:14:51 -05:00
|
|
|
#
|
2002-02-19 07:33:52 -05:00
|
|
|
# basic write
|
2001-02-06 06:14:51 -05:00
|
|
|
#
|
2000-11-16 09:03:20 -05:00
|
|
|
|
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 {
|
2001-12-30 14:18:45 -05:00
|
|
|
do_write 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 {
|
2001-12-30 14:18:45 -05:00
|
|
|
do_write str + "\r\n"
|
2000-06-27 09:36:17 -04:00
|
|
|
}
|
1999-09-22 03:32:33 -04:00
|
|
|
end
|
|
|
|
|
2002-02-19 07:33:52 -05:00
|
|
|
private
|
|
|
|
|
|
|
|
def writing
|
|
|
|
@writtensize = 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
|
2002-02-19 07:33:52 -05:00
|
|
|
@writtensize
|
|
|
|
end
|
|
|
|
|
|
|
|
def do_write( str )
|
2002-03-26 06:18:02 -05:00
|
|
|
@debug_output << str.dump if @debug_output
|
2002-02-19 07:33:52 -05:00
|
|
|
@writtensize += (n = @socket.write(str))
|
|
|
|
n
|
1999-09-22 03:32:33 -04:00
|
|
|
end
|
|
|
|
|
2001-12-30 14:18:45 -05:00
|
|
|
#
|
2002-02-19 07:33:52 -05:00
|
|
|
# message write
|
2001-12-30 14:18:45 -05:00
|
|
|
#
|
|
|
|
|
|
|
|
public
|
|
|
|
|
2002-02-19 07:33:52 -05:00
|
|
|
def write_message( src )
|
2002-10-02 12:45:35 -04:00
|
|
|
D_off "writing text from #{src.class}"
|
1999-09-22 03:32:33 -04:00
|
|
|
|
2001-12-13 14:15:21 -05:00
|
|
|
wsize = using_each_crlf_line {
|
2002-02-19 07:33:52 -05:00
|
|
|
wpend_in src
|
|
|
|
}
|
|
|
|
|
|
|
|
D_on "wrote #{wsize} bytes text"
|
|
|
|
wsize
|
|
|
|
end
|
|
|
|
|
|
|
|
def through_message
|
|
|
|
D_off 'writing text from block'
|
|
|
|
|
|
|
|
wsize = using_each_crlf_line {
|
|
|
|
yield WriteAdapter.new(self, :wpend_in)
|
2000-06-27 09:36:17 -04:00
|
|
|
}
|
1999-09-22 03:32:33 -04:00
|
|
|
|
2001-02-22 18:23:57 -05:00
|
|
|
D_on "wrote #{wsize} bytes text"
|
1999-12-17 10:00:13 -05:00
|
|
|
wsize
|
1999-09-22 03:32:33 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2000-06-27 09:36:17 -04:00
|
|
|
def wpend_in( src )
|
|
|
|
line = nil
|
2000-08-16 15:26:07 -04:00
|
|
|
pre = @writtensize
|
2002-11-21 06:50:09 -05:00
|
|
|
each_crlf_line(src) do |line|
|
2000-06-27 09:36:17 -04:00
|
|
|
do_write '.' if line[0] == ?.
|
|
|
|
do_write line
|
|
|
|
end
|
2000-08-16 15:26:07 -04:00
|
|
|
|
|
|
|
@writtensize - pre
|
2000-02-21 10:27:49 -05:00
|
|
|
end
|
|
|
|
|
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 = ''
|
2000-02-21 10:27:49 -05:00
|
|
|
|
2001-12-30 14:18:45 -05:00
|
|
|
yield
|
2000-02-21 10:27:49 -05:00
|
|
|
|
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"
|
|
|
|
do_write @wbuf
|
2002-11-21 06:50:09 -05:00
|
|
|
elsif @writtensize == 0 # empty src
|
2001-12-30 14:18:45 -05:00
|
|
|
do_write "\r\n"
|
2000-06-27 09:36:17 -04:00
|
|
|
end
|
2001-12-30 14:18:45 -05:00
|
|
|
do_write ".\r\n"
|
2000-02-21 10:27:49 -05:00
|
|
|
|
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
|
|
|
|
2000-06-27 09:36:17 -04:00
|
|
|
def each_crlf_line( src )
|
2000-07-01 14:28:24 -04:00
|
|
|
str = m = beg = nil
|
1999-09-22 03:32:33 -04:00
|
|
|
|
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
|
2002-11-21 06:50:09 -05:00
|
|
|
if m.begin(0) == buf.size - 1 and buf[-1] == ?\r
|
2000-06-16 09:47:38 -04:00
|
|
|
# "...\r" : can follow "\n..."
|
|
|
|
break
|
|
|
|
end
|
2001-02-22 18:23:57 -05: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
|
2001-02-22 18:23:57 -05:00
|
|
|
@wbuf = buf[ beg ... buf.size ]
|
1999-09-22 03:32:33 -04:00
|
|
|
end
|
2000-02-21 10:27:49 -05:00
|
|
|
end
|
|
|
|
|
2000-06-27 09:36:17 -04:00
|
|
|
def adding( src )
|
2002-11-21 06:50:09 -05:00
|
|
|
i = s = nil
|
2000-02-21 10:27:49 -05:00
|
|
|
|
|
|
|
case src
|
|
|
|
when String
|
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
|
|
|
|
|
|
|
|
when File
|
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
|
|
|
|
|
|
|
|
else
|
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
|
|
|
|
2001-02-07 12:17:51 -05:00
|
|
|
def D_off( msg )
|
2001-02-22 18:23:57 -05:00
|
|
|
D msg
|
2002-03-26 06:18:02 -05:00
|
|
|
@savedo, @debug_output = @debug_output, nil
|
2000-03-31 08:02:40 -05:00
|
|
|
end
|
|
|
|
|
2001-02-07 12:17:51 -05:00
|
|
|
def D_on( msg )
|
2002-03-26 06:18:02 -05:00
|
|
|
@debug_output = @savedo
|
2001-02-22 18:23:57 -05:00
|
|
|
D msg
|
|
|
|
end
|
|
|
|
|
|
|
|
def D( msg )
|
2002-03-26 06:18:02 -05:00
|
|
|
@debug_output or return
|
|
|
|
@debug_output << msg
|
|
|
|
@debug_output << "\n"
|
2000-03-31 08:02:40 -05:00
|
|
|
end
|
2002-02-19 07:33:52 -05:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
class WriteAdapter
|
|
|
|
|
|
|
|
def initialize( sock, mid )
|
|
|
|
@socket = sock
|
|
|
|
@mid = mid
|
|
|
|
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 )
|
|
|
|
@socket.__send__ @mid, str
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
def call_block( str )
|
|
|
|
yield str
|
|
|
|
end
|
|
|
|
|
1999-12-17 10:00:13 -05:00
|
|
|
end
|
1999-09-22 03:32:33 -04:00
|
|
|
|
1999-12-17 10:00:13 -05:00
|
|
|
end # module Net
|