<commit_before>require_relative 'service'

module EventMachine::Wssh
module Ephemeral
  extend Service

  @options={
    base: '.',
    proxy: 'log/ephemeral.log',
    tls: 'log/tls.log',
  }

  class Accept
    def initialize
      require 'socket'
      @sock=Addrinfo.tcp('127.0.0.1', 0).listen 1
    end

    def myport
      Socket.unpack_sockaddr_in(@sock.getsockname).first
    end

    def port
      sock=@sock.accept.first
      at_exit{sock}
      sock.gets.to_i
    end
  end

  def self.allocate uri
  end

  def self.help
    require_relative 'exe'
    puts <<-EOF
Run HTTP proxy on ephemeral port

#{Exe.usage} <port> <uri>

For internal use.
    EOF
    exit
  end

  def self.go!
    help if 2!=ARGV.length
  end

end
end<commit_msg>Start Connect loop<commit_after>require_relative 'service'

module EventMachine::Wssh
module Ephemeral
  extend Service

  @options={
    base: '.',
    proxy: 'log/ephemeral.log',
    tls: 'log/tls.log',
  }

  class Accept
    def initialize
      require 'socket'
      @sock=Addrinfo.tcp('127.0.0.1', 0).listen 1
    end

    def myport
      Socket.unpack_sockaddr_in(@sock.getsockname).first
    end

    def port
      sock=@sock.accept.first
      at_exit{sock}
      sock.gets.to_i
    end
  end

  def self.allocate uri
  end

  def self.help
    require_relative 'exe'
    puts <<-EOF
Run HTTP proxy on ephemeral port

#{Exe.usage} <port> <uri>

For internal use.
    EOF
    exit
  end

  def self.go!
    help if 2!=ARGV.length
    require_relative 'connect'

    Connect.options.merge!(
      port: 0,
      onlisten: Proc.new{|port| onlisten port}
    )
    Connect.loop!
  end

  def onlisten port
  end

end
end
{'fraction_non_alphanumeric': 0.10190703218116806, 'fraction_numerical': 0.01132300357568534, 'mean_word_length': 2.41260162601626, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3066805', 'n_tokens_mistral': 635, 'n_tokens_neox': 591, 'n_words': 151}