foolio 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +21 -0
- data/examples/timer.rb +20 -0
- data/ext/foolio/extconf.rb +34 -0
- data/ext/foolio/foolio_ext.c +921 -0
- data/ext/foolio/gen.rb +50 -0
- data/ext/foolio/make_table.rb +12 -0
- data/ext/foolio/templ +243 -0
- data/ext/libuv/.gitignore +33 -0
- data/ext/libuv/.mailmap +13 -0
- data/ext/libuv/.travis.yml +9 -0
- data/ext/libuv/AUTHORS +61 -0
- data/ext/libuv/LICENSE +44 -0
- data/ext/libuv/Makefile +71 -0
- data/ext/libuv/README.md +90 -0
- data/ext/libuv/common.gypi +178 -0
- data/ext/libuv/gyp_uv +73 -0
- data/ext/libuv/include/uv-private/eio.h +403 -0
- data/ext/libuv/include/uv-private/ev.h +838 -0
- data/ext/libuv/include/uv-private/ngx-queue.h +108 -0
- data/ext/libuv/include/uv-private/tree.h +768 -0
- data/ext/libuv/include/uv-private/uv-unix.h +324 -0
- data/ext/libuv/include/uv-private/uv-win.h +517 -0
- data/ext/libuv/include/uv.h +1838 -0
- data/ext/libuv/src/fs-poll.c +235 -0
- data/ext/libuv/src/inet.c +293 -0
- data/ext/libuv/src/unix/async.c +148 -0
- data/ext/libuv/src/unix/core.c +696 -0
- data/ext/libuv/src/unix/cygwin.c +83 -0
- data/ext/libuv/src/unix/darwin.c +342 -0
- data/ext/libuv/src/unix/dl.c +83 -0
- data/ext/libuv/src/unix/eio/Changes +63 -0
- data/ext/libuv/src/unix/eio/LICENSE +36 -0
- data/ext/libuv/src/unix/eio/Makefile.am +15 -0
- data/ext/libuv/src/unix/eio/aclocal.m4 +8957 -0
- data/ext/libuv/src/unix/eio/autogen.sh +3 -0
- data/ext/libuv/src/unix/eio/config.h.in +86 -0
- data/ext/libuv/src/unix/eio/config_cygwin.h +80 -0
- data/ext/libuv/src/unix/eio/config_darwin.h +141 -0
- data/ext/libuv/src/unix/eio/config_freebsd.h +81 -0
- data/ext/libuv/src/unix/eio/config_linux.h +94 -0
- data/ext/libuv/src/unix/eio/config_netbsd.h +81 -0
- data/ext/libuv/src/unix/eio/config_openbsd.h +137 -0
- data/ext/libuv/src/unix/eio/config_sunos.h +84 -0
- data/ext/libuv/src/unix/eio/configure.ac +22 -0
- data/ext/libuv/src/unix/eio/demo.c +194 -0
- data/ext/libuv/src/unix/eio/ecb.h +370 -0
- data/ext/libuv/src/unix/eio/eio.3 +3428 -0
- data/ext/libuv/src/unix/eio/eio.c +2593 -0
- data/ext/libuv/src/unix/eio/eio.pod +969 -0
- data/ext/libuv/src/unix/eio/libeio.m4 +195 -0
- data/ext/libuv/src/unix/eio/xthread.h +164 -0
- data/ext/libuv/src/unix/error.c +105 -0
- data/ext/libuv/src/unix/ev/Changes +388 -0
- data/ext/libuv/src/unix/ev/LICENSE +36 -0
- data/ext/libuv/src/unix/ev/Makefile.am +18 -0
- data/ext/libuv/src/unix/ev/Makefile.in +771 -0
- data/ext/libuv/src/unix/ev/README +58 -0
- data/ext/libuv/src/unix/ev/aclocal.m4 +8957 -0
- data/ext/libuv/src/unix/ev/autogen.sh +6 -0
- data/ext/libuv/src/unix/ev/config.guess +1526 -0
- data/ext/libuv/src/unix/ev/config.h.in +125 -0
- data/ext/libuv/src/unix/ev/config.sub +1658 -0
- data/ext/libuv/src/unix/ev/config_cygwin.h +123 -0
- data/ext/libuv/src/unix/ev/config_darwin.h +122 -0
- data/ext/libuv/src/unix/ev/config_freebsd.h +120 -0
- data/ext/libuv/src/unix/ev/config_linux.h +141 -0
- data/ext/libuv/src/unix/ev/config_netbsd.h +120 -0
- data/ext/libuv/src/unix/ev/config_openbsd.h +126 -0
- data/ext/libuv/src/unix/ev/config_sunos.h +122 -0
- data/ext/libuv/src/unix/ev/configure +13037 -0
- data/ext/libuv/src/unix/ev/configure.ac +18 -0
- data/ext/libuv/src/unix/ev/depcomp +630 -0
- data/ext/libuv/src/unix/ev/ev++.h +816 -0
- data/ext/libuv/src/unix/ev/ev.3 +5311 -0
- data/ext/libuv/src/unix/ev/ev.c +3925 -0
- data/ext/libuv/src/unix/ev/ev.pod +5243 -0
- data/ext/libuv/src/unix/ev/ev_epoll.c +266 -0
- data/ext/libuv/src/unix/ev/ev_kqueue.c +235 -0
- data/ext/libuv/src/unix/ev/ev_poll.c +148 -0
- data/ext/libuv/src/unix/ev/ev_port.c +179 -0
- data/ext/libuv/src/unix/ev/ev_select.c +310 -0
- data/ext/libuv/src/unix/ev/ev_vars.h +203 -0
- data/ext/libuv/src/unix/ev/ev_win32.c +153 -0
- data/ext/libuv/src/unix/ev/ev_wrap.h +196 -0
- data/ext/libuv/src/unix/ev/event.c +402 -0
- data/ext/libuv/src/unix/ev/event.h +170 -0
- data/ext/libuv/src/unix/ev/install-sh +294 -0
- data/ext/libuv/src/unix/ev/libev.m4 +39 -0
- data/ext/libuv/src/unix/ev/ltmain.sh +8413 -0
- data/ext/libuv/src/unix/ev/missing +336 -0
- data/ext/libuv/src/unix/ev/mkinstalldirs +111 -0
- data/ext/libuv/src/unix/freebsd.c +326 -0
- data/ext/libuv/src/unix/fs.c +739 -0
- data/ext/libuv/src/unix/internal.h +188 -0
- data/ext/libuv/src/unix/kqueue.c +120 -0
- data/ext/libuv/src/unix/linux/inotify.c +239 -0
- data/ext/libuv/src/unix/linux/linux-core.c +557 -0
- data/ext/libuv/src/unix/linux/syscalls.c +388 -0
- data/ext/libuv/src/unix/linux/syscalls.h +124 -0
- data/ext/libuv/src/unix/loop-watcher.c +62 -0
- data/ext/libuv/src/unix/loop.c +94 -0
- data/ext/libuv/src/unix/netbsd.c +108 -0
- data/ext/libuv/src/unix/openbsd.c +295 -0
- data/ext/libuv/src/unix/pipe.c +259 -0
- data/ext/libuv/src/unix/poll.c +114 -0
- data/ext/libuv/src/unix/process.c +495 -0
- data/ext/libuv/src/unix/signal.c +269 -0
- data/ext/libuv/src/unix/stream.c +990 -0
- data/ext/libuv/src/unix/sunos.c +481 -0
- data/ext/libuv/src/unix/tcp.c +393 -0
- data/ext/libuv/src/unix/thread.c +251 -0
- data/ext/libuv/src/unix/timer.c +136 -0
- data/ext/libuv/src/unix/tty.c +145 -0
- data/ext/libuv/src/unix/udp.c +659 -0
- data/ext/libuv/src/unix/uv-eio.c +107 -0
- data/ext/libuv/src/unix/uv-eio.h +13 -0
- data/ext/libuv/src/uv-common.c +380 -0
- data/ext/libuv/src/uv-common.h +170 -0
- data/ext/libuv/src/win/async.c +100 -0
- data/ext/libuv/src/win/atomicops-inl.h +56 -0
- data/ext/libuv/src/win/core.c +278 -0
- data/ext/libuv/src/win/dl.c +86 -0
- data/ext/libuv/src/win/error.c +155 -0
- data/ext/libuv/src/win/fs-event.c +510 -0
- data/ext/libuv/src/win/fs.c +1948 -0
- data/ext/libuv/src/win/getaddrinfo.c +365 -0
- data/ext/libuv/src/win/handle-inl.h +149 -0
- data/ext/libuv/src/win/handle.c +154 -0
- data/ext/libuv/src/win/internal.h +343 -0
- data/ext/libuv/src/win/loop-watcher.c +122 -0
- data/ext/libuv/src/win/pipe.c +1672 -0
- data/ext/libuv/src/win/poll.c +616 -0
- data/ext/libuv/src/win/process-stdio.c +500 -0
- data/ext/libuv/src/win/process.c +1013 -0
- data/ext/libuv/src/win/req-inl.h +220 -0
- data/ext/libuv/src/win/req.c +25 -0
- data/ext/libuv/src/win/signal.c +57 -0
- data/ext/libuv/src/win/stream-inl.h +67 -0
- data/ext/libuv/src/win/stream.c +167 -0
- data/ext/libuv/src/win/tcp.c +1394 -0
- data/ext/libuv/src/win/thread.c +372 -0
- data/ext/libuv/src/win/threadpool.c +74 -0
- data/ext/libuv/src/win/timer.c +224 -0
- data/ext/libuv/src/win/tty.c +1799 -0
- data/ext/libuv/src/win/udp.c +716 -0
- data/ext/libuv/src/win/util.c +864 -0
- data/ext/libuv/src/win/winapi.c +132 -0
- data/ext/libuv/src/win/winapi.h +4452 -0
- data/ext/libuv/src/win/winsock.c +557 -0
- data/ext/libuv/src/win/winsock.h +171 -0
- data/ext/libuv/test/benchmark-async-pummel.c +97 -0
- data/ext/libuv/test/benchmark-async.c +137 -0
- data/ext/libuv/test/benchmark-fs-stat.c +135 -0
- data/ext/libuv/test/benchmark-getaddrinfo.c +94 -0
- data/ext/libuv/test/benchmark-list.h +127 -0
- data/ext/libuv/test/benchmark-loop-count.c +88 -0
- data/ext/libuv/test/benchmark-million-timers.c +65 -0
- data/ext/libuv/test/benchmark-ping-pongs.c +213 -0
- data/ext/libuv/test/benchmark-pound.c +324 -0
- data/ext/libuv/test/benchmark-pump.c +462 -0
- data/ext/libuv/test/benchmark-sizes.c +44 -0
- data/ext/libuv/test/benchmark-spawn.c +162 -0
- data/ext/libuv/test/benchmark-tcp-write-batch.c +140 -0
- data/ext/libuv/test/benchmark-thread.c +64 -0
- data/ext/libuv/test/benchmark-udp-packet-storm.c +247 -0
- data/ext/libuv/test/blackhole-server.c +118 -0
- data/ext/libuv/test/dns-server.c +321 -0
- data/ext/libuv/test/echo-server.c +378 -0
- data/ext/libuv/test/fixtures/empty_file +0 -0
- data/ext/libuv/test/fixtures/load_error.node +1 -0
- data/ext/libuv/test/run-benchmarks.c +64 -0
- data/ext/libuv/test/run-tests.c +138 -0
- data/ext/libuv/test/runner-unix.c +295 -0
- data/ext/libuv/test/runner-unix.h +36 -0
- data/ext/libuv/test/runner-win.c +285 -0
- data/ext/libuv/test/runner-win.h +42 -0
- data/ext/libuv/test/runner.c +355 -0
- data/ext/libuv/test/runner.h +159 -0
- data/ext/libuv/test/task.h +112 -0
- data/ext/libuv/test/test-async.c +118 -0
- data/ext/libuv/test/test-callback-order.c +76 -0
- data/ext/libuv/test/test-callback-stack.c +203 -0
- data/ext/libuv/test/test-connection-fail.c +148 -0
- data/ext/libuv/test/test-cwd-and-chdir.c +64 -0
- data/ext/libuv/test/test-delayed-accept.c +188 -0
- data/ext/libuv/test/test-dlerror.c +58 -0
- data/ext/libuv/test/test-error.c +59 -0
- data/ext/libuv/test/test-fail-always.c +29 -0
- data/ext/libuv/test/test-fs-event.c +474 -0
- data/ext/libuv/test/test-fs-poll.c +146 -0
- data/ext/libuv/test/test-fs.c +1843 -0
- data/ext/libuv/test/test-get-currentexe.c +63 -0
- data/ext/libuv/test/test-get-loadavg.c +36 -0
- data/ext/libuv/test/test-get-memory.c +38 -0
- data/ext/libuv/test/test-getaddrinfo.c +122 -0
- data/ext/libuv/test/test-getsockname.c +342 -0
- data/ext/libuv/test/test-hrtime.c +54 -0
- data/ext/libuv/test/test-idle.c +81 -0
- data/ext/libuv/test/test-ipc-send-recv.c +209 -0
- data/ext/libuv/test/test-ipc.c +620 -0
- data/ext/libuv/test/test-list.h +427 -0
- data/ext/libuv/test/test-loop-handles.c +336 -0
- data/ext/libuv/test/test-multiple-listen.c +102 -0
- data/ext/libuv/test/test-mutexes.c +63 -0
- data/ext/libuv/test/test-pass-always.c +28 -0
- data/ext/libuv/test/test-ping-pong.c +253 -0
- data/ext/libuv/test/test-pipe-bind-error.c +140 -0
- data/ext/libuv/test/test-pipe-connect-error.c +96 -0
- data/ext/libuv/test/test-platform-output.c +87 -0
- data/ext/libuv/test/test-poll-close.c +72 -0
- data/ext/libuv/test/test-poll.c +573 -0
- data/ext/libuv/test/test-process-title.c +49 -0
- data/ext/libuv/test/test-ref.c +338 -0
- data/ext/libuv/test/test-run-once.c +48 -0
- data/ext/libuv/test/test-semaphore.c +111 -0
- data/ext/libuv/test/test-shutdown-close.c +103 -0
- data/ext/libuv/test/test-shutdown-eof.c +183 -0
- data/ext/libuv/test/test-signal.c +162 -0
- data/ext/libuv/test/test-spawn.c +863 -0
- data/ext/libuv/test/test-stdio-over-pipes.c +246 -0
- data/ext/libuv/test/test-tcp-bind-error.c +191 -0
- data/ext/libuv/test/test-tcp-bind6-error.c +154 -0
- data/ext/libuv/test/test-tcp-close-while-connecting.c +80 -0
- data/ext/libuv/test/test-tcp-close.c +129 -0
- data/ext/libuv/test/test-tcp-connect-error-after-write.c +95 -0
- data/ext/libuv/test/test-tcp-connect-error.c +70 -0
- data/ext/libuv/test/test-tcp-connect-timeout.c +85 -0
- data/ext/libuv/test/test-tcp-connect6-error.c +68 -0
- data/ext/libuv/test/test-tcp-flags.c +51 -0
- data/ext/libuv/test/test-tcp-shutdown-after-write.c +131 -0
- data/ext/libuv/test/test-tcp-unexpected-read.c +113 -0
- data/ext/libuv/test/test-tcp-write-error.c +168 -0
- data/ext/libuv/test/test-tcp-write-to-half-open-connection.c +135 -0
- data/ext/libuv/test/test-tcp-writealot.c +170 -0
- data/ext/libuv/test/test-thread.c +183 -0
- data/ext/libuv/test/test-threadpool.c +57 -0
- data/ext/libuv/test/test-timer-again.c +141 -0
- data/ext/libuv/test/test-timer.c +152 -0
- data/ext/libuv/test/test-tty.c +110 -0
- data/ext/libuv/test/test-udp-dgram-too-big.c +86 -0
- data/ext/libuv/test/test-udp-ipv6.c +156 -0
- data/ext/libuv/test/test-udp-multicast-join.c +139 -0
- data/ext/libuv/test/test-udp-multicast-ttl.c +86 -0
- data/ext/libuv/test/test-udp-options.c +86 -0
- data/ext/libuv/test/test-udp-send-and-recv.c +208 -0
- data/ext/libuv/test/test-util.c +97 -0
- data/ext/libuv/test/test-walk-handles.c +77 -0
- data/ext/libuv/uv.gyp +375 -0
- data/ext/libuv/vcbuild.bat +105 -0
- data/foolio.gemspec +18 -0
- data/lib/foolio.rb +9 -0
- data/lib/foolio/handle.rb +27 -0
- data/lib/foolio/listener.rb +26 -0
- data/lib/foolio/loop.rb +79 -0
- data/lib/foolio/stream.rb +109 -0
- data/lib/foolio/version.rb +3 -0
- metadata +309 -0
data/foolio.gemspec
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/foolio/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["mzp"]
|
6
|
+
gem.email = ["mzpppp@gmail.com"]
|
7
|
+
gem.description = "Wow"
|
8
|
+
gem.summary = "Wow"
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.extensions = ['ext/foolio/extconf.rb']
|
13
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
14
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
15
|
+
gem.name = "foolio"
|
16
|
+
gem.require_paths = ["lib", "ext"]
|
17
|
+
gem.version = Foolio::VERSION
|
18
|
+
end
|
data/lib/foolio.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- mode:ruby; coding:utf-8 -*-
|
2
|
+
|
3
|
+
module Foolio
|
4
|
+
class Handle
|
5
|
+
def initialize(loop, handle)
|
6
|
+
@loop = loop
|
7
|
+
@handle = handle
|
8
|
+
end
|
9
|
+
|
10
|
+
def callback(&block)
|
11
|
+
@loop.callback &block
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class Idle < Foolio::Handle
|
16
|
+
def start(&block)
|
17
|
+
Foolio::UV.idle_start(@handle, callback(&block))
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class Timer < Foolio::Handle
|
22
|
+
def start(interval, &block)
|
23
|
+
sec = (interval * 1000).to_i
|
24
|
+
Foolio::UV.timer_start(@handle, callback(&block), sec, sec)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- mode:ruby; coding:utf-8 -*-
|
2
|
+
|
3
|
+
module Foolio
|
4
|
+
module Listener
|
5
|
+
def callback(&f)
|
6
|
+
const_name = "Callback_#{f.object_id}"
|
7
|
+
unless self.class.const_defined?(const_name)
|
8
|
+
callbacks << const_name
|
9
|
+
self.class.const_set(const_name, f)
|
10
|
+
end
|
11
|
+
self.class.const_get(const_name)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
def callbacks
|
16
|
+
@callbacks ||= Set.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def clear_callbacks
|
20
|
+
callbacks.each do |name|
|
21
|
+
self.class.send(:remove_const, name)
|
22
|
+
end
|
23
|
+
callbacks.clear
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/foolio/loop.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
# -*- mode:ruby; coding:utf-8 -*-
|
2
|
+
|
3
|
+
module Foolio
|
4
|
+
class Loop
|
5
|
+
include Foolio::Listener
|
6
|
+
attr_reader :loop
|
7
|
+
class << self
|
8
|
+
def default
|
9
|
+
self.new Foolio::UV.default_loop
|
10
|
+
end
|
11
|
+
|
12
|
+
def create
|
13
|
+
self.new Foolio::UV.loop_new
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(loop)
|
18
|
+
@loop = loop
|
19
|
+
|
20
|
+
timer.start(1) do
|
21
|
+
if @stop
|
22
|
+
Foolio::UV.close_all(@loop, callback{
|
23
|
+
clear_callbacks
|
24
|
+
})
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def idle
|
30
|
+
Foolio::Idle.new(self, Foolio::UV.idle_init(@loop))
|
31
|
+
end
|
32
|
+
|
33
|
+
def timer
|
34
|
+
Foolio::Timer.new(self, Foolio::UV.timer_init(@loop))
|
35
|
+
end
|
36
|
+
|
37
|
+
def tcp(ip, port)
|
38
|
+
handle = Foolio::UV.tcp_init(@loop)
|
39
|
+
@socket = Foolio::UV.ip4_addr(ip, port)
|
40
|
+
Foolio::UV.tcp_bind(handle, @socket)
|
41
|
+
Foolio::TCP.new self, handle
|
42
|
+
end
|
43
|
+
|
44
|
+
def udp
|
45
|
+
handle = Foolio::UV.udp_init(@loop)
|
46
|
+
Foolio::UDP.new self, handle
|
47
|
+
end
|
48
|
+
|
49
|
+
def unix(path, ipc = 0)
|
50
|
+
handle = Foolio::UV.pipe_init(@loop, ipc)
|
51
|
+
Foolio::UV.pipe_bind(handle, path)
|
52
|
+
Foolio::Pipe.new self, handle
|
53
|
+
end
|
54
|
+
|
55
|
+
def file_stat(path, &block)
|
56
|
+
cb = callback{|event, _|
|
57
|
+
block[path, event]
|
58
|
+
}
|
59
|
+
Foolio::UV.fs_event_init(@loop, path, cb, 0)
|
60
|
+
end
|
61
|
+
|
62
|
+
def run
|
63
|
+
Foolio::UV.run @loop
|
64
|
+
end
|
65
|
+
|
66
|
+
def alive?
|
67
|
+
not @stop
|
68
|
+
end
|
69
|
+
|
70
|
+
def stop
|
71
|
+
@stop = true
|
72
|
+
end
|
73
|
+
|
74
|
+
def force_stop
|
75
|
+
@stop = true
|
76
|
+
Foolio::UV.loop_delete @loop
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# -*- mode:ruby; coding:utf-8 -*-
|
2
|
+
|
3
|
+
module Foolio
|
4
|
+
class Handler
|
5
|
+
include Foolio::Listener
|
6
|
+
|
7
|
+
def initialize(handle)
|
8
|
+
@handle = handle
|
9
|
+
end
|
10
|
+
|
11
|
+
def write(data)
|
12
|
+
Foolio::UV.write(nil, @handle, data, callback{|status|
|
13
|
+
on_write_complete(status)})
|
14
|
+
end
|
15
|
+
|
16
|
+
def close
|
17
|
+
$log.info "close #{@handle}"
|
18
|
+
Foolio::UV.close(@handle, callback{
|
19
|
+
clear_callbacks
|
20
|
+
})
|
21
|
+
end
|
22
|
+
|
23
|
+
def on_write_complete(err); end
|
24
|
+
def on_connect; end
|
25
|
+
def on_close; end
|
26
|
+
|
27
|
+
def on_recv(data)
|
28
|
+
if data then
|
29
|
+
on_read(data)
|
30
|
+
else
|
31
|
+
close
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def start
|
36
|
+
Foolio::UV.read_start(@handle, callback(&method(:on_recv)))
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class BlockHandler < Foolio::Handler
|
41
|
+
def initialize(io, block)
|
42
|
+
super(io)
|
43
|
+
@block = block
|
44
|
+
end
|
45
|
+
|
46
|
+
def on_connect; end
|
47
|
+
def on_close; end
|
48
|
+
|
49
|
+
def on_read(data)
|
50
|
+
@block.call data
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class Stream < Foolio::Handle
|
55
|
+
def listen_handler(backlog, klass, *args)
|
56
|
+
@klass = klass
|
57
|
+
@args = args
|
58
|
+
Foolio::UV.listen(@handle, backlog, callback(&method(:on_connect)))
|
59
|
+
self
|
60
|
+
end
|
61
|
+
|
62
|
+
def on_connect(status)
|
63
|
+
client = init
|
64
|
+
Foolio::UV.accept(@handle, client)
|
65
|
+
$log.info "accept #{client}"
|
66
|
+
handle = @klass.new(client, *@args)
|
67
|
+
handle.on_connect
|
68
|
+
handle.start
|
69
|
+
end
|
70
|
+
|
71
|
+
def listen(backlog=5, &block)
|
72
|
+
listen_handler(backlog, BlockHandler, block)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
class TCP < Stream
|
77
|
+
def init
|
78
|
+
Foolio::UV.tcp_init(@loop.loop)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
class Pipe < Stream
|
83
|
+
def init
|
84
|
+
Foolio::UV.pipe_init(@loop.loop, 0)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
class UDP < Foolio::Handle
|
89
|
+
def bind(ip,port)
|
90
|
+
@socket = Foolio::UV.ip4_addr(ip, port)
|
91
|
+
Foolio::UV.udp_bind(@handle, @socket, 0)
|
92
|
+
self
|
93
|
+
end
|
94
|
+
|
95
|
+
def start(&block)
|
96
|
+
on_recv = callback do|data, addr, flags|
|
97
|
+
ip = Foolio::UV.ip_name addr
|
98
|
+
port = Foolio::UV.port addr
|
99
|
+
block.call(ip, port, data) if ip
|
100
|
+
end
|
101
|
+
Foolio::UV.udp_recv_start(@handle, on_recv)
|
102
|
+
end
|
103
|
+
|
104
|
+
def send(ip, port, data)
|
105
|
+
on_send = proc {|_|}
|
106
|
+
Foolio::UV.udp_send(nil, @handle, data, Foolio::UV.ip4_addr(ip, port), on_send)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
metadata
ADDED
@@ -0,0 +1,309 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: foolio
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- mzp
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-10 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Wow
|
15
|
+
email:
|
16
|
+
- mzpppp@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions:
|
19
|
+
- ext/foolio/extconf.rb
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- .gitignore
|
23
|
+
- Gemfile
|
24
|
+
- LICENSE
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- examples/timer.rb
|
28
|
+
- ext/foolio/extconf.rb
|
29
|
+
- ext/foolio/foolio_ext.c
|
30
|
+
- ext/foolio/gen.rb
|
31
|
+
- ext/foolio/make_table.rb
|
32
|
+
- ext/foolio/templ
|
33
|
+
- ext/libuv/.gitignore
|
34
|
+
- ext/libuv/.mailmap
|
35
|
+
- ext/libuv/.travis.yml
|
36
|
+
- ext/libuv/AUTHORS
|
37
|
+
- ext/libuv/LICENSE
|
38
|
+
- ext/libuv/Makefile
|
39
|
+
- ext/libuv/README.md
|
40
|
+
- ext/libuv/common.gypi
|
41
|
+
- ext/libuv/config-mingw.mk
|
42
|
+
- ext/libuv/config-unix.mk
|
43
|
+
- ext/libuv/gyp_uv
|
44
|
+
- ext/libuv/include/uv-private/eio.h
|
45
|
+
- ext/libuv/include/uv-private/ev.h
|
46
|
+
- ext/libuv/include/uv-private/ngx-queue.h
|
47
|
+
- ext/libuv/include/uv-private/tree.h
|
48
|
+
- ext/libuv/include/uv-private/uv-unix.h
|
49
|
+
- ext/libuv/include/uv-private/uv-win.h
|
50
|
+
- ext/libuv/include/uv.h
|
51
|
+
- ext/libuv/src/fs-poll.c
|
52
|
+
- ext/libuv/src/inet.c
|
53
|
+
- ext/libuv/src/unix/async.c
|
54
|
+
- ext/libuv/src/unix/core.c
|
55
|
+
- ext/libuv/src/unix/cygwin.c
|
56
|
+
- ext/libuv/src/unix/darwin.c
|
57
|
+
- ext/libuv/src/unix/dl.c
|
58
|
+
- ext/libuv/src/unix/eio/Changes
|
59
|
+
- ext/libuv/src/unix/eio/LICENSE
|
60
|
+
- ext/libuv/src/unix/eio/Makefile.am
|
61
|
+
- ext/libuv/src/unix/eio/aclocal.m4
|
62
|
+
- ext/libuv/src/unix/eio/autogen.sh
|
63
|
+
- ext/libuv/src/unix/eio/config.h.in
|
64
|
+
- ext/libuv/src/unix/eio/config_cygwin.h
|
65
|
+
- ext/libuv/src/unix/eio/config_darwin.h
|
66
|
+
- ext/libuv/src/unix/eio/config_freebsd.h
|
67
|
+
- ext/libuv/src/unix/eio/config_linux.h
|
68
|
+
- ext/libuv/src/unix/eio/config_netbsd.h
|
69
|
+
- ext/libuv/src/unix/eio/config_openbsd.h
|
70
|
+
- ext/libuv/src/unix/eio/config_sunos.h
|
71
|
+
- ext/libuv/src/unix/eio/configure.ac
|
72
|
+
- ext/libuv/src/unix/eio/demo.c
|
73
|
+
- ext/libuv/src/unix/eio/ecb.h
|
74
|
+
- ext/libuv/src/unix/eio/eio.3
|
75
|
+
- ext/libuv/src/unix/eio/eio.c
|
76
|
+
- ext/libuv/src/unix/eio/eio.pod
|
77
|
+
- ext/libuv/src/unix/eio/libeio.m4
|
78
|
+
- ext/libuv/src/unix/eio/xthread.h
|
79
|
+
- ext/libuv/src/unix/error.c
|
80
|
+
- ext/libuv/src/unix/ev/Changes
|
81
|
+
- ext/libuv/src/unix/ev/LICENSE
|
82
|
+
- ext/libuv/src/unix/ev/Makefile.am
|
83
|
+
- ext/libuv/src/unix/ev/Makefile.in
|
84
|
+
- ext/libuv/src/unix/ev/README
|
85
|
+
- ext/libuv/src/unix/ev/aclocal.m4
|
86
|
+
- ext/libuv/src/unix/ev/autogen.sh
|
87
|
+
- ext/libuv/src/unix/ev/config.guess
|
88
|
+
- ext/libuv/src/unix/ev/config.h.in
|
89
|
+
- ext/libuv/src/unix/ev/config.sub
|
90
|
+
- ext/libuv/src/unix/ev/config_cygwin.h
|
91
|
+
- ext/libuv/src/unix/ev/config_darwin.h
|
92
|
+
- ext/libuv/src/unix/ev/config_freebsd.h
|
93
|
+
- ext/libuv/src/unix/ev/config_linux.h
|
94
|
+
- ext/libuv/src/unix/ev/config_netbsd.h
|
95
|
+
- ext/libuv/src/unix/ev/config_openbsd.h
|
96
|
+
- ext/libuv/src/unix/ev/config_sunos.h
|
97
|
+
- ext/libuv/src/unix/ev/configure
|
98
|
+
- ext/libuv/src/unix/ev/configure.ac
|
99
|
+
- ext/libuv/src/unix/ev/depcomp
|
100
|
+
- ext/libuv/src/unix/ev/ev++.h
|
101
|
+
- ext/libuv/src/unix/ev/ev.3
|
102
|
+
- ext/libuv/src/unix/ev/ev.c
|
103
|
+
- ext/libuv/src/unix/ev/ev.pod
|
104
|
+
- ext/libuv/src/unix/ev/ev_epoll.c
|
105
|
+
- ext/libuv/src/unix/ev/ev_kqueue.c
|
106
|
+
- ext/libuv/src/unix/ev/ev_poll.c
|
107
|
+
- ext/libuv/src/unix/ev/ev_port.c
|
108
|
+
- ext/libuv/src/unix/ev/ev_select.c
|
109
|
+
- ext/libuv/src/unix/ev/ev_vars.h
|
110
|
+
- ext/libuv/src/unix/ev/ev_win32.c
|
111
|
+
- ext/libuv/src/unix/ev/ev_wrap.h
|
112
|
+
- ext/libuv/src/unix/ev/event.c
|
113
|
+
- ext/libuv/src/unix/ev/event.h
|
114
|
+
- ext/libuv/src/unix/ev/install-sh
|
115
|
+
- ext/libuv/src/unix/ev/libev.m4
|
116
|
+
- ext/libuv/src/unix/ev/ltmain.sh
|
117
|
+
- ext/libuv/src/unix/ev/missing
|
118
|
+
- ext/libuv/src/unix/ev/mkinstalldirs
|
119
|
+
- ext/libuv/src/unix/freebsd.c
|
120
|
+
- ext/libuv/src/unix/fs.c
|
121
|
+
- ext/libuv/src/unix/internal.h
|
122
|
+
- ext/libuv/src/unix/kqueue.c
|
123
|
+
- ext/libuv/src/unix/linux/inotify.c
|
124
|
+
- ext/libuv/src/unix/linux/linux-core.c
|
125
|
+
- ext/libuv/src/unix/linux/syscalls.c
|
126
|
+
- ext/libuv/src/unix/linux/syscalls.h
|
127
|
+
- ext/libuv/src/unix/loop-watcher.c
|
128
|
+
- ext/libuv/src/unix/loop.c
|
129
|
+
- ext/libuv/src/unix/netbsd.c
|
130
|
+
- ext/libuv/src/unix/openbsd.c
|
131
|
+
- ext/libuv/src/unix/pipe.c
|
132
|
+
- ext/libuv/src/unix/poll.c
|
133
|
+
- ext/libuv/src/unix/process.c
|
134
|
+
- ext/libuv/src/unix/signal.c
|
135
|
+
- ext/libuv/src/unix/stream.c
|
136
|
+
- ext/libuv/src/unix/sunos.c
|
137
|
+
- ext/libuv/src/unix/tcp.c
|
138
|
+
- ext/libuv/src/unix/thread.c
|
139
|
+
- ext/libuv/src/unix/timer.c
|
140
|
+
- ext/libuv/src/unix/tty.c
|
141
|
+
- ext/libuv/src/unix/udp.c
|
142
|
+
- ext/libuv/src/unix/uv-eio.c
|
143
|
+
- ext/libuv/src/unix/uv-eio.h
|
144
|
+
- ext/libuv/src/uv-common.c
|
145
|
+
- ext/libuv/src/uv-common.h
|
146
|
+
- ext/libuv/src/win/async.c
|
147
|
+
- ext/libuv/src/win/atomicops-inl.h
|
148
|
+
- ext/libuv/src/win/core.c
|
149
|
+
- ext/libuv/src/win/dl.c
|
150
|
+
- ext/libuv/src/win/error.c
|
151
|
+
- ext/libuv/src/win/fs-event.c
|
152
|
+
- ext/libuv/src/win/fs.c
|
153
|
+
- ext/libuv/src/win/getaddrinfo.c
|
154
|
+
- ext/libuv/src/win/handle-inl.h
|
155
|
+
- ext/libuv/src/win/handle.c
|
156
|
+
- ext/libuv/src/win/internal.h
|
157
|
+
- ext/libuv/src/win/loop-watcher.c
|
158
|
+
- ext/libuv/src/win/pipe.c
|
159
|
+
- ext/libuv/src/win/poll.c
|
160
|
+
- ext/libuv/src/win/process-stdio.c
|
161
|
+
- ext/libuv/src/win/process.c
|
162
|
+
- ext/libuv/src/win/req-inl.h
|
163
|
+
- ext/libuv/src/win/req.c
|
164
|
+
- ext/libuv/src/win/signal.c
|
165
|
+
- ext/libuv/src/win/stream-inl.h
|
166
|
+
- ext/libuv/src/win/stream.c
|
167
|
+
- ext/libuv/src/win/tcp.c
|
168
|
+
- ext/libuv/src/win/thread.c
|
169
|
+
- ext/libuv/src/win/threadpool.c
|
170
|
+
- ext/libuv/src/win/timer.c
|
171
|
+
- ext/libuv/src/win/tty.c
|
172
|
+
- ext/libuv/src/win/udp.c
|
173
|
+
- ext/libuv/src/win/util.c
|
174
|
+
- ext/libuv/src/win/winapi.c
|
175
|
+
- ext/libuv/src/win/winapi.h
|
176
|
+
- ext/libuv/src/win/winsock.c
|
177
|
+
- ext/libuv/src/win/winsock.h
|
178
|
+
- ext/libuv/test/benchmark-async-pummel.c
|
179
|
+
- ext/libuv/test/benchmark-async.c
|
180
|
+
- ext/libuv/test/benchmark-fs-stat.c
|
181
|
+
- ext/libuv/test/benchmark-getaddrinfo.c
|
182
|
+
- ext/libuv/test/benchmark-list.h
|
183
|
+
- ext/libuv/test/benchmark-loop-count.c
|
184
|
+
- ext/libuv/test/benchmark-million-timers.c
|
185
|
+
- ext/libuv/test/benchmark-ping-pongs.c
|
186
|
+
- ext/libuv/test/benchmark-pound.c
|
187
|
+
- ext/libuv/test/benchmark-pump.c
|
188
|
+
- ext/libuv/test/benchmark-sizes.c
|
189
|
+
- ext/libuv/test/benchmark-spawn.c
|
190
|
+
- ext/libuv/test/benchmark-tcp-write-batch.c
|
191
|
+
- ext/libuv/test/benchmark-thread.c
|
192
|
+
- ext/libuv/test/benchmark-udp-packet-storm.c
|
193
|
+
- ext/libuv/test/blackhole-server.c
|
194
|
+
- ext/libuv/test/dns-server.c
|
195
|
+
- ext/libuv/test/echo-server.c
|
196
|
+
- ext/libuv/test/fixtures/empty_file
|
197
|
+
- ext/libuv/test/fixtures/load_error.node
|
198
|
+
- ext/libuv/test/run-benchmarks.c
|
199
|
+
- ext/libuv/test/run-tests.c
|
200
|
+
- ext/libuv/test/runner-unix.c
|
201
|
+
- ext/libuv/test/runner-unix.h
|
202
|
+
- ext/libuv/test/runner-win.c
|
203
|
+
- ext/libuv/test/runner-win.h
|
204
|
+
- ext/libuv/test/runner.c
|
205
|
+
- ext/libuv/test/runner.h
|
206
|
+
- ext/libuv/test/task.h
|
207
|
+
- ext/libuv/test/test-async.c
|
208
|
+
- ext/libuv/test/test-callback-order.c
|
209
|
+
- ext/libuv/test/test-callback-stack.c
|
210
|
+
- ext/libuv/test/test-connection-fail.c
|
211
|
+
- ext/libuv/test/test-cwd-and-chdir.c
|
212
|
+
- ext/libuv/test/test-delayed-accept.c
|
213
|
+
- ext/libuv/test/test-dlerror.c
|
214
|
+
- ext/libuv/test/test-error.c
|
215
|
+
- ext/libuv/test/test-fail-always.c
|
216
|
+
- ext/libuv/test/test-fs-event.c
|
217
|
+
- ext/libuv/test/test-fs-poll.c
|
218
|
+
- ext/libuv/test/test-fs.c
|
219
|
+
- ext/libuv/test/test-get-currentexe.c
|
220
|
+
- ext/libuv/test/test-get-loadavg.c
|
221
|
+
- ext/libuv/test/test-get-memory.c
|
222
|
+
- ext/libuv/test/test-getaddrinfo.c
|
223
|
+
- ext/libuv/test/test-getsockname.c
|
224
|
+
- ext/libuv/test/test-hrtime.c
|
225
|
+
- ext/libuv/test/test-idle.c
|
226
|
+
- ext/libuv/test/test-ipc-send-recv.c
|
227
|
+
- ext/libuv/test/test-ipc.c
|
228
|
+
- ext/libuv/test/test-list.h
|
229
|
+
- ext/libuv/test/test-loop-handles.c
|
230
|
+
- ext/libuv/test/test-multiple-listen.c
|
231
|
+
- ext/libuv/test/test-mutexes.c
|
232
|
+
- ext/libuv/test/test-pass-always.c
|
233
|
+
- ext/libuv/test/test-ping-pong.c
|
234
|
+
- ext/libuv/test/test-pipe-bind-error.c
|
235
|
+
- ext/libuv/test/test-pipe-connect-error.c
|
236
|
+
- ext/libuv/test/test-platform-output.c
|
237
|
+
- ext/libuv/test/test-poll-close.c
|
238
|
+
- ext/libuv/test/test-poll.c
|
239
|
+
- ext/libuv/test/test-process-title.c
|
240
|
+
- ext/libuv/test/test-ref.c
|
241
|
+
- ext/libuv/test/test-run-once.c
|
242
|
+
- ext/libuv/test/test-semaphore.c
|
243
|
+
- ext/libuv/test/test-shutdown-close.c
|
244
|
+
- ext/libuv/test/test-shutdown-eof.c
|
245
|
+
- ext/libuv/test/test-signal.c
|
246
|
+
- ext/libuv/test/test-spawn.c
|
247
|
+
- ext/libuv/test/test-stdio-over-pipes.c
|
248
|
+
- ext/libuv/test/test-tcp-bind-error.c
|
249
|
+
- ext/libuv/test/test-tcp-bind6-error.c
|
250
|
+
- ext/libuv/test/test-tcp-close-while-connecting.c
|
251
|
+
- ext/libuv/test/test-tcp-close.c
|
252
|
+
- ext/libuv/test/test-tcp-connect-error-after-write.c
|
253
|
+
- ext/libuv/test/test-tcp-connect-error.c
|
254
|
+
- ext/libuv/test/test-tcp-connect-timeout.c
|
255
|
+
- ext/libuv/test/test-tcp-connect6-error.c
|
256
|
+
- ext/libuv/test/test-tcp-flags.c
|
257
|
+
- ext/libuv/test/test-tcp-shutdown-after-write.c
|
258
|
+
- ext/libuv/test/test-tcp-unexpected-read.c
|
259
|
+
- ext/libuv/test/test-tcp-write-error.c
|
260
|
+
- ext/libuv/test/test-tcp-write-to-half-open-connection.c
|
261
|
+
- ext/libuv/test/test-tcp-writealot.c
|
262
|
+
- ext/libuv/test/test-thread.c
|
263
|
+
- ext/libuv/test/test-threadpool.c
|
264
|
+
- ext/libuv/test/test-timer-again.c
|
265
|
+
- ext/libuv/test/test-timer.c
|
266
|
+
- ext/libuv/test/test-tty.c
|
267
|
+
- ext/libuv/test/test-udp-dgram-too-big.c
|
268
|
+
- ext/libuv/test/test-udp-ipv6.c
|
269
|
+
- ext/libuv/test/test-udp-multicast-join.c
|
270
|
+
- ext/libuv/test/test-udp-multicast-ttl.c
|
271
|
+
- ext/libuv/test/test-udp-options.c
|
272
|
+
- ext/libuv/test/test-udp-send-and-recv.c
|
273
|
+
- ext/libuv/test/test-util.c
|
274
|
+
- ext/libuv/test/test-walk-handles.c
|
275
|
+
- ext/libuv/uv.gyp
|
276
|
+
- ext/libuv/vcbuild.bat
|
277
|
+
- foolio.gemspec
|
278
|
+
- lib/foolio.rb
|
279
|
+
- lib/foolio/handle.rb
|
280
|
+
- lib/foolio/listener.rb
|
281
|
+
- lib/foolio/loop.rb
|
282
|
+
- lib/foolio/stream.rb
|
283
|
+
- lib/foolio/version.rb
|
284
|
+
homepage: ''
|
285
|
+
licenses: []
|
286
|
+
post_install_message:
|
287
|
+
rdoc_options: []
|
288
|
+
require_paths:
|
289
|
+
- lib
|
290
|
+
- ext
|
291
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
292
|
+
none: false
|
293
|
+
requirements:
|
294
|
+
- - ! '>='
|
295
|
+
- !ruby/object:Gem::Version
|
296
|
+
version: '0'
|
297
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
298
|
+
none: false
|
299
|
+
requirements:
|
300
|
+
- - ! '>='
|
301
|
+
- !ruby/object:Gem::Version
|
302
|
+
version: '0'
|
303
|
+
requirements: []
|
304
|
+
rubyforge_project:
|
305
|
+
rubygems_version: 1.8.24
|
306
|
+
signing_key:
|
307
|
+
specification_version: 3
|
308
|
+
summary: Wow
|
309
|
+
test_files: []
|