iodine 0.5.2 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of iodine might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/README.md +63 -100
- data/bin/raw-rbhttp +12 -7
- data/examples/config.ru +8 -7
- data/examples/echo.ru +8 -7
- data/examples/info.md +41 -35
- data/examples/pubsub_engine.ru +12 -12
- data/examples/redis.ru +10 -12
- data/examples/shootout.ru +19 -42
- data/exe/iodine +116 -1
- data/ext/iodine/defer.c +1 -1
- data/ext/iodine/facil.c +12 -8
- data/ext/iodine/facil.h +2 -2
- data/ext/iodine/iodine.c +177 -343
- data/ext/iodine/iodine.h +18 -72
- data/ext/iodine/iodine_caller.c +132 -0
- data/ext/iodine/iodine_caller.h +21 -0
- data/ext/iodine/iodine_connection.c +841 -0
- data/ext/iodine/iodine_connection.h +55 -0
- data/ext/iodine/iodine_defer.c +391 -0
- data/ext/iodine/iodine_defer.h +7 -0
- data/ext/iodine/{rb-fiobj2rb.h → iodine_fiobj2rb.h} +6 -6
- data/ext/iodine/iodine_helpers.c +51 -5
- data/ext/iodine/iodine_helpers.h +2 -3
- data/ext/iodine/iodine_http.c +284 -141
- data/ext/iodine/iodine_http.h +2 -2
- data/ext/iodine/iodine_json.c +13 -13
- data/ext/iodine/iodine_json.h +1 -1
- data/ext/iodine/iodine_pubsub.c +573 -823
- data/ext/iodine/iodine_pubsub.h +15 -27
- data/ext/iodine/{rb-rack-io.c → iodine_rack_io.c} +30 -8
- data/ext/iodine/{rb-rack-io.h → iodine_rack_io.h} +1 -0
- data/ext/iodine/iodine_store.c +136 -0
- data/ext/iodine/iodine_store.h +20 -0
- data/ext/iodine/iodine_tcp.c +385 -0
- data/ext/iodine/iodine_tcp.h +9 -0
- data/lib/iodine.rb +73 -171
- data/lib/iodine/connection.rb +34 -0
- data/lib/iodine/pubsub.rb +5 -18
- data/lib/iodine/rack_utils.rb +43 -0
- data/lib/iodine/version.rb +1 -1
- data/lib/rack/handler/iodine.rb +1 -182
- metadata +17 -18
- data/ext/iodine/iodine_protocol.c +0 -689
- data/ext/iodine/iodine_protocol.h +0 -13
- data/ext/iodine/iodine_websockets.c +0 -550
- data/ext/iodine/iodine_websockets.h +0 -17
- data/ext/iodine/rb-call.c +0 -156
- data/ext/iodine/rb-call.h +0 -70
- data/ext/iodine/rb-defer.c +0 -124
- data/ext/iodine/rb-registry.c +0 -150
- data/ext/iodine/rb-registry.h +0 -34
- data/lib/iodine/cli.rb +0 -89
- data/lib/iodine/monkeypatch.rb +0 -46
- data/lib/iodine/protocol.rb +0 -42
- data/lib/iodine/websocket.rb +0 -16
data/ext/iodine/rb-registry.h
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
Copyright: Boaz segev, 2016-2017
|
3
|
-
License: MIT
|
4
|
-
|
5
|
-
Feel free to copy, use and enjoy according to the license provided.
|
6
|
-
*/
|
7
|
-
#ifndef RB_REGISTRY_HELPER_H
|
8
|
-
#define RB_REGISTRY_HELPER_H
|
9
|
-
#include <ruby.h>
|
10
|
-
|
11
|
-
/**
|
12
|
-
This is a "Registry" helper for Ruby extentions.
|
13
|
-
|
14
|
-
The registry allows "registering" Ruby objects to be marked by the Ruby's GC.
|
15
|
-
This prevents the need for global variables such as Ruby arrays or Hashes
|
16
|
-
with Ruby objects and allows easy management of Ruby objects owned by C code.
|
17
|
-
|
18
|
-
GC requires a callback "mark" to inform it which objects are still
|
19
|
-
referenced.
|
20
|
-
|
21
|
-
Our library creates, holds and releases myriad Ruby objects.
|
22
|
-
|
23
|
-
Hence, our server class needs to include an object binary tree to
|
24
|
-
handle ruby registry and keep references to the Ruby objects.
|
25
|
-
*/
|
26
|
-
extern struct ___RegistryClass___ {
|
27
|
-
void (*init)(VALUE owner);
|
28
|
-
void (*remove)(VALUE obj);
|
29
|
-
VALUE (*add)(VALUE obj);
|
30
|
-
void (*print)(void);
|
31
|
-
void (*on_fork)(void);
|
32
|
-
} Registry;
|
33
|
-
|
34
|
-
#endif // RB_REGISTRY_HELPER_H
|
data/lib/iodine/cli.rb
DELETED
@@ -1,89 +0,0 @@
|
|
1
|
-
require 'iodine'
|
2
|
-
require 'rack'
|
3
|
-
|
4
|
-
module Iodine
|
5
|
-
# The Iodine::Base namespace is reserved for internal use and is NOT part of the public API.
|
6
|
-
module Base
|
7
|
-
# Command line interface. The Ruby CLI might be changed in future versions.
|
8
|
-
module CLI
|
9
|
-
|
10
|
-
def print_help
|
11
|
-
puts <<-EOS
|
12
|
-
|
13
|
-
Iodine's HTTP/Websocket server version #{Iodine::VERSION}
|
14
|
-
|
15
|
-
Use:
|
16
|
-
|
17
|
-
iodine <options> <filename>
|
18
|
-
|
19
|
-
Both <options> and <filename> are optional.
|
20
|
-
|
21
|
-
Available options:
|
22
|
-
-b Binding address. Default: nil (same as 0.0.0.0).
|
23
|
-
-p Port number. Default: 3000.
|
24
|
-
-t Number of threads. Default: CPU core count.
|
25
|
-
-w Number of worker processes. Default: CPU core count.
|
26
|
-
-www Public folder for static file serving. Default: nil (none).
|
27
|
-
-v Log responses. Default: never log responses.
|
28
|
-
-warmup Warmup invokes autoloading (lazy loading) during server startup.
|
29
|
-
-tout HTTP inactivity connection timeout. Default: 40 seconds.
|
30
|
-
-maxhead Maximum total headers length per HTTP request. Default: 32Kb.
|
31
|
-
-maxbd Maximum Mb per HTTP message (max body size). Default: 50Mb.
|
32
|
-
-maxms Maximum Bytes per Websocket message. Default: 250Kb.
|
33
|
-
-ping Websocket ping interval in seconds. Default: 40 seconds.
|
34
|
-
<filename> Defaults to: config.ru
|
35
|
-
|
36
|
-
Example:
|
37
|
-
|
38
|
-
iodine -p 80
|
39
|
-
|
40
|
-
iodine -p 8080 path/to/app/conf.ru
|
41
|
-
|
42
|
-
iodine -p 8080 -w 4 -t 16
|
43
|
-
|
44
|
-
EOS
|
45
|
-
end
|
46
|
-
|
47
|
-
|
48
|
-
def try_file filename
|
49
|
-
return nil unless File.exist? filename
|
50
|
-
return ::Rack::Builder.parse_file filename
|
51
|
-
end
|
52
|
-
|
53
|
-
def call
|
54
|
-
if ARGV[0] =~ /(\-\?)|(help)|(\?)|(h)|(\-h)$/
|
55
|
-
return print_help
|
56
|
-
end
|
57
|
-
|
58
|
-
app, opt = nil, nil
|
59
|
-
filename = ((ARGV[-2].to_s[0] != '-' || ARGV[-2].to_s == '-warmup' || ARGV[-2].to_s == '-v' || ARGV[-2].to_s == '-q') && ARGV[-1].to_s[0] != '-' && ARGV[-1])
|
60
|
-
if filename
|
61
|
-
app, opt = try_file filename;
|
62
|
-
unless opt
|
63
|
-
puts "* Couldn't find #{filename}\n testing for config.ru\n"
|
64
|
-
app, opt = try_file "config.ru"
|
65
|
-
end
|
66
|
-
else
|
67
|
-
app, opt = try_file "config.ru";
|
68
|
-
end
|
69
|
-
|
70
|
-
unless opt
|
71
|
-
puts "WARNING: Ruby application not found#{ filename ? " - missing both #{filename} and config.ru" : " - missing config.ru"}."
|
72
|
-
if ARGV.index('-www') && ARGV[ARGV.index('-www') + 1]
|
73
|
-
puts " Running only static file service."
|
74
|
-
opt = ::Rack::Server::Options.new.parse!([])
|
75
|
-
else
|
76
|
-
puts "For help run:"
|
77
|
-
puts " iodine -?"
|
78
|
-
return
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
Iodine.warmup(app) if ARGV.index('-warmup')
|
83
|
-
Iodine::Rack.run(app, opt)
|
84
|
-
end
|
85
|
-
|
86
|
-
extend self
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
data/lib/iodine/monkeypatch.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
module Iodine
|
2
|
-
# The Iodine::Base namespace is reserved for internal use and is NOT part of the public API.
|
3
|
-
module Base
|
4
|
-
# Iodine does NOT monkey patch automatically at this time.
|
5
|
-
#
|
6
|
-
# This may change in future releases, but that's unlikely.
|
7
|
-
module MonkeyPatch
|
8
|
-
# Iodine does NOT monkey patch Rack automatically. However, it's possible to
|
9
|
-
# moneky patch Rack::Utils using this module.
|
10
|
-
#
|
11
|
-
# Choosing to monkey patch Rack::Utils could offer significant performance gains for some applications. i.e. (on my machine):
|
12
|
-
#
|
13
|
-
# require 'iodine'
|
14
|
-
# require 'rack'
|
15
|
-
# # a String in need of decoding
|
16
|
-
# s = '%E3%83%AB%E3%83%93%E3%82%A4%E3%82%B9%E3%81%A8'
|
17
|
-
# Benchmark.bm do |bm|
|
18
|
-
# # Pre-Patch
|
19
|
-
# bm.report(" Rack.unescape") {1_000_000.times { Rack::Utils.unescape s } }
|
20
|
-
# bm.report(" Rack.rfc2822") {1_000_000.times { Rack::Utils.rfc2822(Time.now) } }
|
21
|
-
# bm.report(" Rack.rfc2109") {1_000_000.times { Rack::Utils.rfc2109(Time.now) } }
|
22
|
-
# # Perform Patch
|
23
|
-
# Iodine.patch_rack
|
24
|
-
# puts " --- Monkey Patching Rack ---"
|
25
|
-
# # Post Patch
|
26
|
-
# bm.report("Patched.unescape") {1_000_000.times { Rack::Utils.unescape s } }
|
27
|
-
# bm.report(" Patched.rfc2822") {1_000_000.times { Rack::Utils.rfc2822(Time.now) } }
|
28
|
-
# bm.report(" Patched.rfc2109") {1_000_000.times { Rack::Utils.rfc2109(Time.now) } }
|
29
|
-
# end && nil
|
30
|
-
#
|
31
|
-
# Results:
|
32
|
-
# user system total real
|
33
|
-
# Rack.unescape 8.660000 0.010000 8.670000 ( 8.687807)
|
34
|
-
# Rack.rfc2822 3.730000 0.000000 3.730000 ( 3.727732)
|
35
|
-
# Rack.rfc2109 3.020000 0.010000 3.030000 ( 3.031940)
|
36
|
-
# --- Monkey Patching Rack ---
|
37
|
-
# Patched.unescape 0.340000 0.000000 0.340000 ( 0.341506)
|
38
|
-
# Patched.rfc2822 0.740000 0.000000 0.740000 ( 0.737796)
|
39
|
-
# Patched.rfc2109 0.690000 0.010000 0.700000 ( 0.700155)
|
40
|
-
#
|
41
|
-
module RackUtils
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
\
|
data/lib/iodine/protocol.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
module Iodine
|
2
|
-
# The Protocol class is used only for documenting the Protocol API, it will not be included when requiring `iodine`.
|
3
|
-
#
|
4
|
-
# A dynamic (stateful) protocol is defined as a Ruby class instance which is in control of one single connection.
|
5
|
-
#
|
6
|
-
# It is called dynamic because it is dynamically allocated for each connection and then discarded,
|
7
|
-
# also it sounded better then calling it "the stateful protocol", even though that's what it actually is.
|
8
|
-
#
|
9
|
-
# It is (mostly) thread-safe as long as it's operations are limited to the scope
|
10
|
-
# of the object.
|
11
|
-
#
|
12
|
-
# <b>The Callbacks</b>
|
13
|
-
#
|
14
|
-
# A protocol class <b>MUST</b> contain ONE of the following callbacks:
|
15
|
-
#
|
16
|
-
# on_data:: called whened there's data available to be read, but no data was read just yet. `on_data` will not be called again untill all the existing network buffer was read (edge triggered event).
|
17
|
-
# on_message(buffer):: the default `on_data` implementation creates a 1Kb buffer and reads data while recycling the same String memory space. The buffer is forwarded to the `on_message` callback before being recycled. The buffer object will be over-written once `on_message` returns, so creating a persistent copy requires `buffer.dup`.
|
18
|
-
#
|
19
|
-
# A protocol class <b>MAY</b> contain any of the following optional callbacks:
|
20
|
-
#
|
21
|
-
# on_open:: called after a new connection was accepted and the protocol was linked with Iodine's Protocol API. Initialization should be performed here.
|
22
|
-
# ping:: called whenever timeout was reached. The default implementation will close the connection unless a protocol task ({Protocol#defer}, `on_data` or `on_message`) are busy in the background.
|
23
|
-
# on_shutdown:: called if the connection is still open while the server is shutting down. This allows the protocol to send a "going away" frame before the connection is closed and `on_close` is called.
|
24
|
-
# on_close:: called after a connection was closed, for any cleanup (if any).
|
25
|
-
#
|
26
|
-
# WARNING: for thread safety and connection management, `on_open`, `on_shutdown`, `on_close` and `ping` will all be performed within the reactor's main thread.
|
27
|
-
# Do not run long running tasks within these callbacks, or the server might block while you do.
|
28
|
-
# Use {#defer} to run protocol related tasks (this locks the connection, preventing it from running more then one task at a time and offering thread safety),
|
29
|
-
# or {#run} to run asynchronous tasks that aren't protocol related.
|
30
|
-
#
|
31
|
-
# <b>Connection timeouts</b>
|
32
|
-
#
|
33
|
-
# By setting a class variable called `@timeout` it is possible to define a default timeout for new connections. However, changing this default timeout should be performed using the {#timeout} methods.
|
34
|
-
#
|
35
|
-
# <b>The API:</b>
|
36
|
-
#
|
37
|
-
# After a new connection is accepted and a new protocol object is created, the protocol will be linked with Iodine's Protocol API.
|
38
|
-
# Only the main protocol will be able to access the API within `initialize`, so it's best to use `on_open` for any Initialization required.
|
39
|
-
#
|
40
|
-
module Protocol
|
41
|
-
end
|
42
|
-
end
|
data/lib/iodine/websocket.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
module Iodine
|
2
|
-
# This module lists the available API for WebSocket and EventSource (SSE) connections.
|
3
|
-
#
|
4
|
-
# This module is mixed in (using `extend` and `include`) with the WebSocket Callback Object (as specified by the {file:SPEC-Websocket-Draft.md proposed Rack specification}.
|
5
|
-
#
|
6
|
-
# The server performs `extend` to allow the application to be namespace agnostic (so the server can be replaced without effecting the application).
|
7
|
-
#
|
8
|
-
# The websocket API is divided into three main groups:
|
9
|
-
# * Server <=> Client relations ({Iodine::Websocket#write}, {Iodine::Websocket#close} etc')
|
10
|
-
# * Client <=> Server <=> Pub/Sub relations ({Iodine::Websocket#subscribe}, {Iodine::Websocket#publish}.
|
11
|
-
# * Task scheduling ({Iodine::Websocket.defer}, {Iodine::Websocket#defer}, {Iodine::Websocket.each}).
|
12
|
-
#
|
13
|
-
# Notice that Websocket callback objects (as specified by the {file:SPEC-Websocket-Draft.md proposed Rack specification} *MUST* provide an `on_message(data)` callback.
|
14
|
-
module Websocket
|
15
|
-
end
|
16
|
-
end
|