em-midori 0.1.11 → 0.1.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/midori.rb +1 -0
- data/lib/midori/connection.rb +4 -1
- data/lib/midori/core_ext/event_loop.rb +27 -4
- data/lib/midori/core_ext/timer.rb +10 -0
- data/lib/midori/extension/file.rb +2 -2
- data/lib/midori/extension/hiredis.rb +2 -2
- data/lib/midori/extension/net.rb +36 -0
- data/lib/midori/extension/sequel/mysql2.rb +2 -2
- data/lib/midori/extension/sequel/postgres.rb +2 -2
- data/lib/midori/runner.rb +1 -1
- data/lib/midori/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ad463d2a5c54f9995812d347d0f428752414d77
|
4
|
+
data.tar.gz: 9a9ea6eb52f59bf540e7dc37d24a6581393a439d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf12420ff582c13a143a872462284f3232472decff29a686286d931eb5fac60371182a313e0327c41281eea5a8a673913dd59eeebf560a8ecc99a4245aeaca9b
|
7
|
+
data.tar.gz: b40da8f51f4c39e5b9dd46a5944c17b0672425ffa5869a14a5880df85d0ce9bd92c19daa7433131624e4b93308ecf69d09f8c0e5afb3c0edcc3b4111957c3066
|
data/lib/midori.rb
CHANGED
@@ -10,6 +10,7 @@ require 'socket'
|
|
10
10
|
require_relative 'midori/core_ext/configurable'
|
11
11
|
require_relative 'midori/core_ext/string'
|
12
12
|
require_relative 'midori/core_ext/event_loop'
|
13
|
+
require_relative 'midori/core_ext/timer'
|
13
14
|
require_relative 'midori/core_ext/promise'
|
14
15
|
require_relative 'midori/core_ext/define_class'
|
15
16
|
require_relative 'midori/core_ext/proc'
|
data/lib/midori/connection.rb
CHANGED
@@ -20,8 +20,11 @@ class Midori::Connection
|
|
20
20
|
end
|
21
21
|
if monitor.writable?
|
22
22
|
if !@data.empty?
|
23
|
+
# :nocov:
|
24
|
+
# Leave for corner cases
|
23
25
|
monitor.io.write_nonblock(@data)
|
24
26
|
@data = ''
|
27
|
+
# :nocov:
|
25
28
|
elsif @close_flag
|
26
29
|
close_connection
|
27
30
|
end
|
@@ -34,7 +37,7 @@ class Midori::Connection
|
|
34
37
|
end
|
35
38
|
|
36
39
|
def close_connection
|
37
|
-
EventLoop.
|
40
|
+
EventLoop.deregister @socket
|
38
41
|
@socket.close
|
39
42
|
end
|
40
43
|
|
@@ -1,19 +1,42 @@
|
|
1
|
+
require 'timeout'
|
2
|
+
|
1
3
|
module EventLoop
|
2
4
|
class << self
|
3
5
|
SELECTOR = NIO::Selector.new
|
6
|
+
TIMERS = []
|
7
|
+
|
8
|
+
def add_timer(timer)
|
9
|
+
timer.start_time = Time.now.to_f + timer.time
|
10
|
+
TIMERS << timer
|
11
|
+
end
|
4
12
|
|
5
13
|
def register(io, interest=(:rw), &callback)
|
6
14
|
monitor = SELECTOR.register(io, interest)
|
7
|
-
monitor.value =
|
15
|
+
monitor.value = {
|
16
|
+
callback: callback,
|
17
|
+
}
|
18
|
+
|
8
19
|
end
|
9
20
|
|
10
|
-
def
|
21
|
+
def deregister(io)
|
11
22
|
SELECTOR.deregister(io)
|
12
23
|
end
|
13
24
|
|
14
25
|
def run_once
|
15
|
-
SELECTOR.select(
|
16
|
-
monitor.value.
|
26
|
+
SELECTOR.select(0.2) do |monitor| # Timeout for 1 secs
|
27
|
+
monitor.value[:timer].stop unless monitor.value[:timer].nil?
|
28
|
+
monitor.value[:callback].call(monitor)
|
29
|
+
end
|
30
|
+
EventLoop.timer_once
|
31
|
+
end
|
32
|
+
|
33
|
+
def timer_once
|
34
|
+
now_time = Time.now.to_f
|
35
|
+
TIMERS.delete_if do |timer|
|
36
|
+
if timer.start_time < now_time
|
37
|
+
timer.callback.call
|
38
|
+
true
|
39
|
+
end
|
17
40
|
end
|
18
41
|
end
|
19
42
|
|
@@ -8,7 +8,7 @@ class Midori::File
|
|
8
8
|
data = ''
|
9
9
|
EventLoop.register(@file, :r) do
|
10
10
|
if @file.eof?
|
11
|
-
EventLoop.
|
11
|
+
EventLoop.deregister(@file)
|
12
12
|
resolve.call(data)
|
13
13
|
else
|
14
14
|
data << @file.read_nonblock(16384)
|
@@ -23,7 +23,7 @@ class Midori::File
|
|
23
23
|
EventLoop.register(@file, :w) do
|
24
24
|
written += @file.write_nonblock(data[written..-1])
|
25
25
|
if written == data.size
|
26
|
-
EventLoop.
|
26
|
+
EventLoop.deregister(@file)
|
27
27
|
resolve.call(written)
|
28
28
|
end
|
29
29
|
end
|
@@ -17,7 +17,7 @@ module Hiredis
|
|
17
17
|
EventLoop.register(@sock, :w) do
|
18
18
|
written += @sock.write_nonblock(data[written..-1])
|
19
19
|
if written == string_size(data)
|
20
|
-
EventLoop.
|
20
|
+
EventLoop.deregister(@sock)
|
21
21
|
resolve.call
|
22
22
|
end
|
23
23
|
end
|
@@ -31,7 +31,7 @@ module Hiredis
|
|
31
31
|
@reader.feed @sock.read_nonblock(1024)
|
32
32
|
reply = @reader.gets
|
33
33
|
if reply
|
34
|
-
EventLoop.
|
34
|
+
EventLoop.deregister(@sock)
|
35
35
|
resolve.call(reply)
|
36
36
|
end
|
37
37
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'net/protocol'
|
2
|
+
|
3
|
+
class Net::BufferedIO
|
4
|
+
def wait_io(interest)
|
5
|
+
await(Promise.new do |resolve|
|
6
|
+
EventLoop.register(@io.to_io, interest) do
|
7
|
+
EventLoop.deregister(@io.to_io)
|
8
|
+
resolve.call(self)
|
9
|
+
end
|
10
|
+
end)
|
11
|
+
end
|
12
|
+
|
13
|
+
def rbuf_fill
|
14
|
+
loop do
|
15
|
+
case rv = @io.read_nonblock(BUFSIZE, exception: false)
|
16
|
+
when String
|
17
|
+
return @rbuf << rv
|
18
|
+
when :wait_readable
|
19
|
+
wait_io(:r)
|
20
|
+
# @io.to_io.wait_readable(@read_timeout) or raise Net::ReadTimeout
|
21
|
+
# continue looping
|
22
|
+
when :wait_writable
|
23
|
+
# OpenSSL::Buffering#read_nonblock may fail with IO::WaitWritable.
|
24
|
+
# http://www.openssl.org/support/faq.html#PROG10
|
25
|
+
# :nocov:
|
26
|
+
wait_io(:w)
|
27
|
+
# @io.to_io.wait_writable(@read_timeout) or raise Net::ReadTimeout
|
28
|
+
# continue looping
|
29
|
+
when nil
|
30
|
+
# callers do not care about backtrace, so avoid allocating for it
|
31
|
+
raise EOFError, 'end of file reached', []
|
32
|
+
# :nocov:
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -39,7 +39,7 @@ module Sequel
|
|
39
39
|
socket = IO::open(conn.socket)
|
40
40
|
await(Promise.new do |resolve|
|
41
41
|
EventLoop.register(socket, :w) do
|
42
|
-
EventLoop.
|
42
|
+
EventLoop.deregister(socket)
|
43
43
|
conn.query(sql,
|
44
44
|
database_timezone: timezone,
|
45
45
|
application_timezone: Sequel.application_timezone,
|
@@ -50,7 +50,7 @@ module Sequel
|
|
50
50
|
end)
|
51
51
|
await(Promise.new do |resolve|
|
52
52
|
EventLoop.register(socket, :r) do
|
53
|
-
EventLoop.
|
53
|
+
EventLoop.deregister(socket)
|
54
54
|
resolve.call(conn.async_result)
|
55
55
|
end
|
56
56
|
end)
|
@@ -14,7 +14,7 @@ class Sequel::Postgres::Adapter
|
|
14
14
|
await(Promise.new do |resolve|
|
15
15
|
EventLoop.register(socket_object, :w) do
|
16
16
|
unless is_busy
|
17
|
-
EventLoop.
|
17
|
+
EventLoop.deregister(socket_object)
|
18
18
|
send_query(sql)
|
19
19
|
resolve.call
|
20
20
|
end
|
@@ -24,7 +24,7 @@ class Sequel::Postgres::Adapter
|
|
24
24
|
await(Promise.new do |resolve|
|
25
25
|
consume_input
|
26
26
|
EventLoop.register(socket_object, :r) do
|
27
|
-
EventLoop.
|
27
|
+
EventLoop.deregister(socket_object)
|
28
28
|
resolve.call(get_result)
|
29
29
|
end
|
30
30
|
end)
|
data/lib/midori/runner.rb
CHANGED
data/lib/midori/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: em-midori
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- HeckPsi Lab
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-02-
|
11
|
+
date: 2017-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nio4r
|
@@ -74,10 +74,12 @@ files:
|
|
74
74
|
- lib/midori/core_ext/promise.rb
|
75
75
|
- lib/midori/core_ext/safe_require.rb
|
76
76
|
- lib/midori/core_ext/string.rb
|
77
|
+
- lib/midori/core_ext/timer.rb
|
77
78
|
- lib/midori/eventsource.rb
|
78
79
|
- lib/midori/exception.rb
|
79
80
|
- lib/midori/extension/file.rb
|
80
81
|
- lib/midori/extension/hiredis.rb
|
82
|
+
- lib/midori/extension/net.rb
|
81
83
|
- lib/midori/extension/sequel/mysql2.rb
|
82
84
|
- lib/midori/extension/sequel/postgres.rb
|
83
85
|
- lib/midori/middleware.rb
|