Sha256: 79c17e91cbbbc521116027d1e38bdc992e4151bb25241655657d2dee251cea0b
Contents?: true
Size: 1.03 KB
Versions: 3
Compression:
Stored size: 1.03 KB
Contents
#!/usr/bin/env ruby # # A simple example showing how to use Einhorn's shared-socket # features. Einhorn translates the (addr:port[,flags...]) bind spec in # into a file descriptor number in the EINHORN_FDS environment variable. # # Invoke through Einhorn as # # einhorn -b 127.0.0.1:2345,r ./time_server # # or, if you want to try out preloading: # # einhorn -b 127.0.0.1:2345,r -p ./time_server ./time_server require 'rubygems' require 'einhorn/worker' def einhorn_main puts "Called with ENV['EINHORN_FDS']: #{ENV['EINHORN_FDS']}" fd_num = Einhorn::Worker.socket! socket = Socket.for_fd(fd_num) # Came up successfully, so let's set up graceful handler and ACK the # master. Einhorn::Worker.graceful_shutdown do puts "Goodbye from #{$$}" exit(0) end Einhorn::Worker.ack! # Real work happens here. begin while true accepted, _ = socket.accept accepted.write("[#{$$}] The current time is: #{Time.now}!\n") accepted.close end rescue Exception end end if $0 == __FILE__ einhorn_main end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
einhorn-0.4.2 | example/time_server |
einhorn-0.4.1 | example/time_server |
einhorn-0.4.0 | example/time_server |