summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorRoberto De Ioris <roberto@unbit.it>2012-12-28 14:33:12 +0100
committerRoberto De Ioris <roberto@unbit.it>2012-12-28 14:33:12 +0100
commitdd983135c6ee30fd290a28676d9eb9722b712c17 (patch)
tree52c2909ebabd420da13a8ef0a548116ea17e3195 /examples
parent09fe2960b5496996706aab6852b68185644f2e8c (diff)
downloaduwsgi-dd983135c6ee30fd290a28676d9eb9722b712c17.tar.gz
another cleanup [2]
Diffstat (limited to 'examples')
-rw-r--r--examples/config.ru18
-rw-r--r--examples/config17.ru25
-rw-r--r--examples/config2.ru7
-rw-r--r--examples/config30.ru68
-rw-r--r--examples/fibers.ru47
-rw-r--r--examples/sputnik.ws9
6 files changed, 174 insertions, 0 deletions
diff --git a/examples/config.ru b/examples/config.ru
new file mode 100644
index 00000000..faddae81
--- /dev/null
+++ b/examples/config.ru
@@ -0,0 +1,18 @@
+require 'fiber'
+require 'sinatra'
+
+get '/hi' do
+
+ class Response
+ def each
+ for i in 1..10
+ yield "ciao<br/>"
+ Fiber.yield
+ end
+ end
+ end
+
+ Response.new
+end
+
+run Sinatra::Application
diff --git a/examples/config17.ru b/examples/config17.ru
new file mode 100644
index 00000000..f80e14cb
--- /dev/null
+++ b/examples/config17.ru
@@ -0,0 +1,25 @@
+require 'stringio'
+
+hello = proc do |signum|
+ puts "Hello i am signal #{signum}"
+end
+
+file_changed = proc do |signum|
+ puts "/tmp has been modified"
+end
+
+UWSGI.register_signal(17, '', hello)
+UWSGI.register_signal(30, '', file_changed)
+
+UWSGI.add_rb_timer(17 , 2)
+UWSGI.add_timer(17 , 1)
+UWSGI.add_file_monitor(30 , '/tmp')
+
+puts UWSGI.signal_registered(1)
+puts UWSGI.signal_registered(17)
+
+run lambda { |env|
+ puts env.inspect
+ UWSGI.signal(17)
+ [200, {'Content-Type'=>'text/plain'}, StringIO.new("Hello World!\n")]
+}
diff --git a/examples/config2.ru b/examples/config2.ru
new file mode 100644
index 00000000..f07832cf
--- /dev/null
+++ b/examples/config2.ru
@@ -0,0 +1,7 @@
+require 'sinatra'
+
+get '/hi' do
+ "Hello World"
+end
+
+run Sinatra::Application
diff --git a/examples/config30.ru b/examples/config30.ru
new file mode 100644
index 00000000..dd5beafc
--- /dev/null
+++ b/examples/config30.ru
@@ -0,0 +1,68 @@
+require 'stringio'
+require 'uwsgidsl'
+
+
+
+signal 17,'mule5' do |signum|
+end
+
+puts UWSGI::VERSION
+puts UWSGI::NUMPROC
+puts UWSGI::HOSTNAME
+
+puts UWSGI::OPT.inspect
+
+timer 2 do |signum|
+ puts "ciao sono un dsl ruby: #{signum} #{UWSGI::OPT.inspect}"
+end
+
+timer 1,'mule1' do |signum|
+ puts "1 second elapsed (signum #{signum})"
+end
+
+filemon '/tmp' do |signum|
+ puts "/tmp has been modified"
+end
+
+cron 5,-1,-1,-1,-1 do |signum|
+ puts "cron ready #{signum}"
+end
+
+cron 58,-1,-1,-1,-1 do |signum|
+ puts "cron ready #{signum}"
+end
+
+postfork do
+ puts "fork() called"
+end
+
+rpc 'pippo' do
+ "i am an rpc function"
+end
+
+rpc 'pluto' do |x,y|
+ "i am another rpc function #{x} #{y}"
+end
+
+begin
+ foo_func
+rescue
+end
+
+puts UWSGI.cache_exists('nilkey')
+puts UWSGI.cache_exists?('nilkey')
+
+UWSGI.cache_set!('foobar_key?a=1', UWSGI::OPT.inspect)
+begin
+puts UWSGI.cache_get(nil)
+rescue
+end
+puts UWSGI.cache_get('foobar_key?a=1')
+
+
+run lambda { |env|
+ puts env.inspect
+ UWSGI.setprocname("i am the uWSGI rack plugin")
+ UWSGI.signal(17)
+ [200, {'Content-Type'=>'text/plain'}, StringIO.new("Hello World! #{UWSGI.mem.inspect}\n")]
+}
diff --git a/examples/fibers.ru b/examples/fibers.ru
new file mode 100644
index 00000000..8de53956
--- /dev/null
+++ b/examples/fibers.ru
@@ -0,0 +1,47 @@
+require 'fiber'
+class SuspendingBody
+
+ def each
+ for i in 1..3
+ yield "number: #{i}\n"
+ UWSGI.async_sleep(1)
+ puts "sleep..."
+ Fiber.yield
+ end
+
+ fd = UWSGI.async_connect("81.174.68.52:80")
+ UWSGI.wait_fd_write(fd, 3)
+ Fiber.yield
+ io = IO.new(fd)
+ puts "connected"
+ io.syswrite("GET /uwsgi/export/1081%3A362d695b2f25/plugins/fiber/fiber.c HTTP/1.0\r\n")
+ io.syswrite("Host: projects.unbit.it\r\n")
+ io.syswrite("\r\n")
+
+ UWSGI.wait_fd_read(fd, 3)
+ Fiber.yield
+
+ puts "data available"
+
+ begin
+ while body = io.sysread(fd)
+ yield body
+ Fiber.yield
+ end
+ rescue
+ end
+
+ io.close
+ end
+
+end
+
+class RackFoo
+
+ def call(env)
+ [200, { 'Content-Type' => 'text/plain'}, SuspendingBody.new]
+ end
+
+end
+
+run RackFoo.new
diff --git a/examples/sputnik.ws b/examples/sputnik.ws
new file mode 100644
index 00000000..2d1599f7
--- /dev/null
+++ b/examples/sputnik.ws
@@ -0,0 +1,9 @@
+require('sputnik')
+return sputnik.wsapi_app.new{
+ VERSIUM_STORAGE_MODULE = "versium.sqlite3",
+ VERSIUM_PARAMS = {'/tmp/sputnik.db'},
+ SHOW_STACK_TRACE = true,
+ TOKEN_SALT = 'xxx',
+ BASE_URL = '/',
+}
+