Hi,
I’ve some trouble reading an IO after a select
Here is the code.
while sock = tunnel.accept
Thread.start(sock) do |s|
ssl_sock = get_ssl_socket("ssl.gwikzone.org", 443)
#set_non_blocking ssl_sock.to_io
#set_non_blocking s.to_io
STDERR.puts "thread start
#{Thread.current.object_id}/#{s.object_id}/#{ssl_sock.object_id}"
while true
STDERR.puts "select..."
res = select([s, ssl_sock])
unless res.nil?
for rsock in res[0]
#delete closed connections
if rsock.eof? || ssl_sock.closed?
s.close
ssl_sock.close
Thread.current.terminate
end
if rsock == s
STDERR.puts "read s"
buf = s.read
STDERR.puts "s: \n#{send}"
ssl_sock.write buf unless buf.nil? || buf.empty?
end
if rsock == ssl_sock
STDERR.puts "read ssl"
buf = rsock.read
STDERR.puts "ssl: \n#{send}"
s.write buf unless buf.nil? || buf.empty?
end
end #for
end #unless
end #while true
end #Thread.start
end #while
output :
thread start 539408208/539408228/539408078
select…
read s
<<— get stuck here
I tried to use non-blocking io but same thing happened which is very
strange.
Thank’s for help