Assessment on resource leakage

Below is the result of a 10 minutes hack to create a simple HTTP-connect
tunnel. I’m not closing sockets since I assume that at some point one end
will close its connection and the thread will die with some exception
such as Errno::EPIPE, Errno::EHOSTUNREACH or EOFError, so that the
sockets are GC’ed (and closed) some time in the future.

Is this assumption correct?

require ‘socket’

port = (ARGV[0] || 6666).to_i
server = TCPServer.new(‘localhost’, port)
puts “Binding to #{port}”
while ( session = server.accept )
Thread.new(session) do |s|
line = s.readline(“\r\n”)
break unless line =~ /CONNECT\s+(.+):([0-9]+)\s+HTTP/1.(?:0|1).*/
_host, _port = $1, $2
while line != “\r\n”
line = s.readline(“\r\n”)
end
out = nil
begin
out = TCPSocket.new( _host, _port.to_i )
rescue
s.print “HTTP/1.0 500 Connection could not be established\r\n\r\n”
break
end
s.print “HTTP/1.0 200 Connection established\r\n\r\n”
loop do
ready = select [s, out]
ready = ready[0]
ready.each do |x|
case x
when s
data = s.sysread(512)
out.syswrite data
when out
data = out.sysread(512)
s.syswrite data
end
end
end
end
end

···


_ _

__ __ | | ___ _ __ ___ __ _ _ __
'_ \ / | __/ __| '_ _ \ / ` | ’ \
) | (| | |
__ \ | | | | | (| | | | |
.__/ _,
|_|/| || ||_,|| |_|
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

If loving linux is wrong, I dont wanna be right.
– Topic for #LinuxGER

Hi,

···

In message “Assessment on resource leakage” on 03/02/07, Mauricio Fernández batsman.geo@yahoo.com writes:

Below is the result of a 10 minutes hack to create a simple HTTP-connect
tunnel. I’m not closing sockets since I assume that at some point one end
will close its connection and the thread will die with some exception
such as Errno::EPIPE, Errno::EHOSTUNREACH or EOFError, so that the
sockets are GC’ed (and closed) some time in the future.

Is this assumption correct?

Correct.

						matz.