Sha256: 73aa9efb0c3906614e1904057de7c7bc057cf1455c19702d0f2b7b3e27dc6c5f

Contents?: true

Size: 866 Bytes

Versions: 13

Compression:

Stored size: 866 Bytes

Contents

# frozen_string_literal: true

require 'bundler/setup'
require 'polyphony'

DESTINATION = ['127.0.0.1', 1234]

def handle_client(conn)
  spin do
    dest = TCPSocket.new(*DESTINATION)
    # w_buffer = Polyphony.pipe
    # r_buffer = Polyphony.pipe

    # spin { IO.splice(conn, w_buffer, -1000) }
    # spin { IO.splice(w_buffer, dest, -1000) }

    # spin { IO.splice(dest, r_buffer, -1000) }
    # spin { IO.splice(r_buffer, conn, -1000) }

    # Fiber.current.await_all_children

    f = spin do
      IO.double_splice(conn, dest)
      raise EOFError
    end
    IO.double_splice(dest, conn)
    f.await
  rescue EOFError, SystemCallError
    # ignore
  ensure
    conn.close rescue nil
    dest.close rescue nil
  end
end

puts "Serving TCP proxy on port 4321..."
server = TCPServer.new('127.0.0.1', 4321)
while (conn = server.accept)
  handle_client(conn)
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
polyphony-1.6 examples/pipes/tcp_proxy.rb
polyphony-1.5 examples/pipes/tcp_proxy.rb
polyphony-1.4 examples/pipes/tcp_proxy.rb
polyphony-1.3 examples/pipes/tcp_proxy.rb
polyphony-1.2.1 examples/pipes/tcp_proxy.rb
polyphony-1.2 examples/pipes/tcp_proxy.rb
polyphony-1.1.1 examples/pipes/tcp_proxy.rb
polyphony-1.1 examples/pipes/tcp_proxy.rb
polyphony-1.0.2 examples/pipes/tcp_proxy.rb
polyphony-1.0.1 examples/pipes/tcp_proxy.rb
polyphony-1.0 examples/pipes/tcp_proxy.rb
polyphony-0.99.6 examples/pipes/tcp_proxy.rb
polyphony-0.99.5 examples/pipes/tcp_proxy.rb