Sha256: 43f4535d66a284f6f81be08800bce92f03b8aaaa8633adf17309b3a97e8c1227
Contents?: true
Size: 705 Bytes
Versions: 3
Compression:
Stored size: 705 Bytes
Contents
require_relative '../lib/uringmachine' require 'socket' socket = TCPServer.open('127.0.0.1', 1234) puts 'Listening on port 1234...' $machine = UringMachine.new $bgid = $machine.setup_buffer_ring(4096, 1024) def handle_connection(fd) $machine.read_each(fd, $bgid) do |buf| $machine.write(fd, buf) end puts "Connection closed by client fd #{fd}" rescue Exception => e puts "Got error #{e.inspect}, closing connection" $machine.close(fd) rescue nil end $machine.spin do loop do $machine.sleep 5 puts "pending: #{$machine.pending_count}" end end $machine.accept_each(socket.fileno) do |fd| puts "Connection accepted fd #{fd}" $machine.spin(fd) { handle_connection(_1) } end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
uringmachine-0.5.1 | examples/echo_server.rb |
uringmachine-0.5 | examples/echo_server.rb |
uringmachine-0.4 | examples/echo_server.rb |