Sha256: d496773ddfd62f32ccf47173083065b3dbc4b8ee93b1c968bc7f35e4019977ba

Contents?: true

Size: 665 Bytes

Versions: 6

Compression:

Stored size: 665 Bytes

Contents

require 'lightio'

# apply monkey patch as early as possible
# after monkey patch, it just normal ruby code
LightIO::Monkey.patch_all!


TCPServer.open('localhost', 3000) do |server|
  while (socket = server.accept)
    _, port, host = socket.peeraddr
    puts "accept connection from #{host}:#{port}"

    # Don't worry, Thread.new create green threads, it cost very light
    Thread.new(socket) do |socket|
      data = nil
      begin
        socket.write(data) while (data = socket.readpartial(4096))
      rescue EOFError
        _, port, host = socket.peeraddr
        puts "*** #{host}:#{port} disconnected"
        socket.close
      end
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
lightio-0.4.4 examples/monkey_patch.rb
lightio-0.4.3 examples/monkey_patch.rb
lightio-0.4.2 examples/monkey_patch.rb
lightio-0.4.1 examples/monkey_patch.rb
lightio-0.4.0 examples/monkey_patch.rb
lightio-0.4.0.pre examples/monkey_patch.rb