# File iowa.rb, line 170
        def Iowa.handleConnection(socket)
                begin
                        Thread.current.priority = 2
                        start_time = Time.now
                        mylog = Logger['iowa_log']
                        # Having two logfiles with much the same data in them is stupid.  Fix this.
                        myapachelikelog = Logger['iowa_apachelike_log']
                        message = ''
                        while (recv = socket.recv(1024)) != ""
                                message << recv
                        end
                        socket.shutdown(0)
                        read_time = Time.now
                        status = 'OK'
                rescue Exception => exception
                        mylog.error "Failure While Reading Inbound Data: #{exception}"
                        status = "EIN"
                end

                begin
                        request = Marshal.load(message)
                rescue Exception => exception
                        mylog.error "Inbound Data Corruption: #{exception}"
                        status = 'EIN'
                end

                buffer = ''
                context = nil
                exception = nil
                exception = catch(:session_error) do
                        begin
                                context = Iowa::Context.new(request, buffer)
                                app.handleRequest(context)
                        rescue Exception => exception
                        end
                end

                if exception.to_s != '' and exception.kind_of? Exception
                        buffer << "<p>#{exception}<br/>"
                        buffer << exception.backtrace.join("<br/>\n").to_s
                        buffer << "</p>"
                        mylog.warn "Execution Error: #{exception} :: " + exception.backtrace.join(".....").to_s
                        status = 'EOUT'
                end

                begin
                        request.content = buffer.to_s
                        message = Marshal.dump(request)
                        socket.write(message.to_s)
                        socket.flush
                        socket.shutdown(1)
                        end_time = Time.now
                rescue Exception => exception
                        mylog.error "Failure While Writing Outbound Data: #{exception}"
                end

                vhost = nil
                request.unparsed_uri =~ /http:\/\/([^\/]*)\//
                vhost = $1
                referer = request.headers_in['Referer'] != '' ? request.headers_in['Referer'] : request.uri
                myapachelikelog.info "#{request.remote_host} #{request.hostname} - [#{Time.now.strftime('%d/%b/%Y:%H:%M:%S')}] #{buffer.length} \"#{request.request_method} #{request.unparsed_uri} HTTP/1.1\" 200 #{buffer.length} \"#{referer}\" \"#{request.headers_in['User-Agent']}\" \"#{request.headers_in['Cookie']}\""
                mylog.info "#{start_time} (#{read_time.to_f - start_time.to_f}/#{end_time.to_f - start_time.to_f}) :: #{request.uri} #{status} #{buffer.length}B"
        end