rbuv 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +5 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +0 -1
- data/README.md +6 -1
- data/Rakefile +42 -0
- data/deps/libuv/.gitignore +34 -0
- data/deps/libuv/.mailmap +16 -0
- data/deps/libuv/AUTHORS +81 -0
- data/deps/libuv/ChangeLog +45 -0
- data/deps/libuv/LICENSE +41 -0
- data/deps/libuv/Makefile +53 -0
- data/deps/libuv/README.md +118 -0
- data/deps/libuv/build.mk +164 -0
- data/deps/libuv/checksparse.sh +230 -0
- data/deps/libuv/common.gypi +197 -0
- data/deps/libuv/config-mingw.mk +48 -0
- data/deps/libuv/config-unix.mk +167 -0
- data/deps/libuv/gyp_uv +98 -0
- data/deps/libuv/include/uv-private/ngx-queue.h +129 -0
- data/deps/libuv/include/uv-private/stdint-msvc2008.h +247 -0
- data/deps/libuv/include/uv-private/tree.h +768 -0
- data/deps/libuv/include/uv-private/uv-bsd.h +34 -0
- data/deps/libuv/include/uv-private/uv-darwin.h +61 -0
- data/deps/libuv/include/uv-private/uv-linux.h +34 -0
- data/deps/libuv/include/uv-private/uv-sunos.h +44 -0
- data/deps/libuv/include/uv-private/uv-unix.h +332 -0
- data/deps/libuv/include/uv-private/uv-win.h +585 -0
- data/deps/libuv/include/uv.h +1987 -0
- data/deps/libuv/src/fs-poll.c +248 -0
- data/deps/libuv/src/inet.c +298 -0
- data/deps/libuv/src/unix/aix.c +393 -0
- data/deps/libuv/src/unix/async.c +281 -0
- data/deps/libuv/src/unix/core.c +714 -0
- data/deps/libuv/src/unix/cygwin.c +93 -0
- data/deps/libuv/src/unix/darwin-proctitle.m +78 -0
- data/deps/libuv/src/unix/darwin.c +431 -0
- data/deps/libuv/src/unix/dl.c +83 -0
- data/deps/libuv/src/unix/error.c +109 -0
- data/deps/libuv/src/unix/freebsd.c +343 -0
- data/deps/libuv/src/unix/fs.c +869 -0
- data/deps/libuv/src/unix/fsevents.c +299 -0
- data/deps/libuv/src/unix/getaddrinfo.c +159 -0
- data/deps/libuv/src/unix/internal.h +259 -0
- data/deps/libuv/src/unix/kqueue.c +347 -0
- data/deps/libuv/src/unix/linux-core.c +724 -0
- data/deps/libuv/src/unix/linux-inotify.c +236 -0
- data/deps/libuv/src/unix/linux-syscalls.c +388 -0
- data/deps/libuv/src/unix/linux-syscalls.h +150 -0
- data/deps/libuv/src/unix/loop-watcher.c +64 -0
- data/deps/libuv/src/unix/loop.c +114 -0
- data/deps/libuv/src/unix/netbsd.c +353 -0
- data/deps/libuv/src/unix/openbsd.c +304 -0
- data/deps/libuv/src/unix/pipe.c +261 -0
- data/deps/libuv/src/unix/poll.c +108 -0
- data/deps/libuv/src/unix/process.c +501 -0
- data/deps/libuv/src/unix/proctitle.c +103 -0
- data/deps/libuv/src/unix/signal.c +455 -0
- data/deps/libuv/src/unix/stream.c +1380 -0
- data/deps/libuv/src/unix/sunos.c +647 -0
- data/deps/libuv/src/unix/tcp.c +357 -0
- data/deps/libuv/src/unix/thread.c +431 -0
- data/deps/libuv/src/unix/threadpool.c +286 -0
- data/deps/libuv/src/unix/timer.c +153 -0
- data/deps/libuv/src/unix/tty.c +179 -0
- data/deps/libuv/src/unix/udp.c +715 -0
- data/deps/libuv/src/uv-common.c +431 -0
- data/deps/libuv/src/uv-common.h +204 -0
- data/deps/libuv/src/version.c +60 -0
- data/deps/libuv/src/win/async.c +99 -0
- data/deps/libuv/src/win/atomicops-inl.h +56 -0
- data/deps/libuv/src/win/core.c +310 -0
- data/deps/libuv/src/win/dl.c +86 -0
- data/deps/libuv/src/win/error.c +164 -0
- data/deps/libuv/src/win/fs-event.c +506 -0
- data/deps/libuv/src/win/fs.c +1951 -0
- data/deps/libuv/src/win/getaddrinfo.c +365 -0
- data/deps/libuv/src/win/handle-inl.h +164 -0
- data/deps/libuv/src/win/handle.c +153 -0
- data/deps/libuv/src/win/internal.h +346 -0
- data/deps/libuv/src/win/loop-watcher.c +124 -0
- data/deps/libuv/src/win/pipe.c +1656 -0
- data/deps/libuv/src/win/poll.c +615 -0
- data/deps/libuv/src/win/process-stdio.c +503 -0
- data/deps/libuv/src/win/process.c +1048 -0
- data/deps/libuv/src/win/req-inl.h +224 -0
- data/deps/libuv/src/win/req.c +25 -0
- data/deps/libuv/src/win/signal.c +354 -0
- data/deps/libuv/src/win/stream-inl.h +67 -0
- data/deps/libuv/src/win/stream.c +198 -0
- data/deps/libuv/src/win/tcp.c +1422 -0
- data/deps/libuv/src/win/thread.c +666 -0
- data/deps/libuv/src/win/threadpool.c +82 -0
- data/deps/libuv/src/win/timer.c +230 -0
- data/deps/libuv/src/win/tty.c +1857 -0
- data/deps/libuv/src/win/udp.c +744 -0
- data/deps/libuv/src/win/util.c +946 -0
- data/deps/libuv/src/win/winapi.c +152 -0
- data/deps/libuv/src/win/winapi.h +4476 -0
- data/deps/libuv/src/win/winsock.c +560 -0
- data/deps/libuv/src/win/winsock.h +171 -0
- data/deps/libuv/test/benchmark-async-pummel.c +119 -0
- data/deps/libuv/test/benchmark-async.c +139 -0
- data/deps/libuv/test/benchmark-fs-stat.c +136 -0
- data/deps/libuv/test/benchmark-getaddrinfo.c +91 -0
- data/deps/libuv/test/benchmark-list.h +163 -0
- data/deps/libuv/test/benchmark-loop-count.c +90 -0
- data/deps/libuv/test/benchmark-million-async.c +112 -0
- data/deps/libuv/test/benchmark-million-timers.c +77 -0
- data/deps/libuv/test/benchmark-multi-accept.c +432 -0
- data/deps/libuv/test/benchmark-ping-pongs.c +212 -0
- data/deps/libuv/test/benchmark-pound.c +325 -0
- data/deps/libuv/test/benchmark-pump.c +459 -0
- data/deps/libuv/test/benchmark-sizes.c +45 -0
- data/deps/libuv/test/benchmark-spawn.c +163 -0
- data/deps/libuv/test/benchmark-tcp-write-batch.c +141 -0
- data/deps/libuv/test/benchmark-thread.c +64 -0
- data/deps/libuv/test/benchmark-udp-pummel.c +238 -0
- data/deps/libuv/test/blackhole-server.c +118 -0
- data/deps/libuv/test/dns-server.c +329 -0
- data/deps/libuv/test/echo-server.c +384 -0
- data/deps/libuv/test/fixtures/empty_file +0 -0
- data/deps/libuv/test/fixtures/load_error.node +1 -0
- data/deps/libuv/test/run-benchmarks.c +64 -0
- data/deps/libuv/test/run-tests.c +159 -0
- data/deps/libuv/test/runner-unix.c +328 -0
- data/deps/libuv/test/runner-unix.h +36 -0
- data/deps/libuv/test/runner-win.c +318 -0
- data/deps/libuv/test/runner-win.h +43 -0
- data/deps/libuv/test/runner.c +394 -0
- data/deps/libuv/test/runner.h +165 -0
- data/deps/libuv/test/task.h +122 -0
- data/deps/libuv/test/test-active.c +83 -0
- data/deps/libuv/test/test-async.c +136 -0
- data/deps/libuv/test/test-barrier.c +98 -0
- data/deps/libuv/test/test-callback-order.c +77 -0
- data/deps/libuv/test/test-callback-stack.c +204 -0
- data/deps/libuv/test/test-condvar.c +173 -0
- data/deps/libuv/test/test-connection-fail.c +150 -0
- data/deps/libuv/test/test-cwd-and-chdir.c +64 -0
- data/deps/libuv/test/test-delayed-accept.c +189 -0
- data/deps/libuv/test/test-dlerror.c +58 -0
- data/deps/libuv/test/test-embed.c +136 -0
- data/deps/libuv/test/test-error.c +59 -0
- data/deps/libuv/test/test-fail-always.c +29 -0
- data/deps/libuv/test/test-fs-event.c +504 -0
- data/deps/libuv/test/test-fs-poll.c +148 -0
- data/deps/libuv/test/test-fs.c +1899 -0
- data/deps/libuv/test/test-get-currentexe.c +63 -0
- data/deps/libuv/test/test-get-loadavg.c +36 -0
- data/deps/libuv/test/test-get-memory.c +38 -0
- data/deps/libuv/test/test-getaddrinfo.c +120 -0
- data/deps/libuv/test/test-getsockname.c +344 -0
- data/deps/libuv/test/test-hrtime.c +54 -0
- data/deps/libuv/test/test-idle.c +82 -0
- data/deps/libuv/test/test-ipc-send-recv.c +218 -0
- data/deps/libuv/test/test-ipc.c +625 -0
- data/deps/libuv/test/test-list.h +492 -0
- data/deps/libuv/test/test-loop-handles.c +337 -0
- data/deps/libuv/test/test-loop-stop.c +73 -0
- data/deps/libuv/test/test-multiple-listen.c +103 -0
- data/deps/libuv/test/test-mutexes.c +63 -0
- data/deps/libuv/test/test-pass-always.c +28 -0
- data/deps/libuv/test/test-ping-pong.c +250 -0
- data/deps/libuv/test/test-pipe-bind-error.c +144 -0
- data/deps/libuv/test/test-pipe-connect-error.c +98 -0
- data/deps/libuv/test/test-platform-output.c +87 -0
- data/deps/libuv/test/test-poll-close.c +73 -0
- data/deps/libuv/test/test-poll.c +575 -0
- data/deps/libuv/test/test-process-title.c +49 -0
- data/deps/libuv/test/test-ref.c +415 -0
- data/deps/libuv/test/test-run-nowait.c +46 -0
- data/deps/libuv/test/test-run-once.c +49 -0
- data/deps/libuv/test/test-semaphore.c +111 -0
- data/deps/libuv/test/test-shutdown-close.c +105 -0
- data/deps/libuv/test/test-shutdown-eof.c +184 -0
- data/deps/libuv/test/test-signal-multiple-loops.c +270 -0
- data/deps/libuv/test/test-signal.c +152 -0
- data/deps/libuv/test/test-spawn.c +938 -0
- data/deps/libuv/test/test-stdio-over-pipes.c +250 -0
- data/deps/libuv/test/test-tcp-bind-error.c +198 -0
- data/deps/libuv/test/test-tcp-bind6-error.c +159 -0
- data/deps/libuv/test/test-tcp-close-while-connecting.c +81 -0
- data/deps/libuv/test/test-tcp-close.c +130 -0
- data/deps/libuv/test/test-tcp-connect-error-after-write.c +96 -0
- data/deps/libuv/test/test-tcp-connect-error.c +71 -0
- data/deps/libuv/test/test-tcp-connect-timeout.c +86 -0
- data/deps/libuv/test/test-tcp-connect6-error.c +69 -0
- data/deps/libuv/test/test-tcp-flags.c +52 -0
- data/deps/libuv/test/test-tcp-open.c +175 -0
- data/deps/libuv/test/test-tcp-read-stop.c +73 -0
- data/deps/libuv/test/test-tcp-shutdown-after-write.c +132 -0
- data/deps/libuv/test/test-tcp-unexpected-read.c +114 -0
- data/deps/libuv/test/test-tcp-write-to-half-open-connection.c +136 -0
- data/deps/libuv/test/test-tcp-writealot.c +171 -0
- data/deps/libuv/test/test-thread.c +183 -0
- data/deps/libuv/test/test-threadpool-cancel.c +311 -0
- data/deps/libuv/test/test-threadpool.c +77 -0
- data/deps/libuv/test/test-timer-again.c +142 -0
- data/deps/libuv/test/test-timer.c +266 -0
- data/deps/libuv/test/test-tty.c +111 -0
- data/deps/libuv/test/test-udp-dgram-too-big.c +87 -0
- data/deps/libuv/test/test-udp-ipv6.c +158 -0
- data/deps/libuv/test/test-udp-multicast-join.c +140 -0
- data/deps/libuv/test/test-udp-multicast-ttl.c +87 -0
- data/deps/libuv/test/test-udp-open.c +154 -0
- data/deps/libuv/test/test-udp-options.c +87 -0
- data/deps/libuv/test/test-udp-send-and-recv.c +210 -0
- data/deps/libuv/test/test-util.c +97 -0
- data/deps/libuv/test/test-walk-handles.c +78 -0
- data/deps/libuv/uv.gyp +431 -0
- data/deps/libuv/vcbuild.bat +128 -0
- data/ext/rbuv/debug.h +27 -0
- data/ext/rbuv/error.c +7 -0
- data/ext/rbuv/error.h +10 -0
- data/ext/rbuv/extconf.rb +35 -0
- data/ext/rbuv/handle.c +40 -0
- data/ext/rbuv/handle.h +14 -0
- data/ext/rbuv/libuv.mk +12 -0
- data/ext/rbuv/loop.c +50 -0
- data/ext/rbuv/loop.h +13 -0
- data/ext/rbuv/rbuv.c +15 -0
- data/ext/rbuv/rbuv.h +27 -0
- data/ext/rbuv/timer.c +133 -0
- data/ext/rbuv/timer.h +13 -0
- data/lib/rbuv/timer.rb +7 -0
- data/lib/rbuv/version.rb +1 -1
- data/lib/rbuv.rb +24 -2
- data/rbuv.gemspec +5 -1
- data/spec/spec_helper.rb +22 -0
- data/spec/timer_spec.rb +144 -0
- metadata +278 -9
@@ -0,0 +1,128 @@
|
|
1
|
+
@echo off
|
2
|
+
|
3
|
+
cd %~dp0
|
4
|
+
|
5
|
+
if /i "%1"=="help" goto help
|
6
|
+
if /i "%1"=="--help" goto help
|
7
|
+
if /i "%1"=="-help" goto help
|
8
|
+
if /i "%1"=="/help" goto help
|
9
|
+
if /i "%1"=="?" goto help
|
10
|
+
if /i "%1"=="-?" goto help
|
11
|
+
if /i "%1"=="--?" goto help
|
12
|
+
if /i "%1"=="/?" goto help
|
13
|
+
|
14
|
+
@rem Process arguments.
|
15
|
+
set config=
|
16
|
+
set target=Build
|
17
|
+
set noprojgen=
|
18
|
+
set nobuild=
|
19
|
+
set run=
|
20
|
+
set target_arch=ia32
|
21
|
+
set vs_toolset=x86
|
22
|
+
set platform=WIN32
|
23
|
+
set library=static_library
|
24
|
+
|
25
|
+
:next-arg
|
26
|
+
if "%1"=="" goto args-done
|
27
|
+
if /i "%1"=="debug" set config=Debug&goto arg-ok
|
28
|
+
if /i "%1"=="release" set config=Release&goto arg-ok
|
29
|
+
if /i "%1"=="test" set run=run-tests.exe&goto arg-ok
|
30
|
+
if /i "%1"=="bench" set run=run-benchmarks.exe&goto arg-ok
|
31
|
+
if /i "%1"=="clean" set target=Clean&goto arg-ok
|
32
|
+
if /i "%1"=="noprojgen" set noprojgen=1&goto arg-ok
|
33
|
+
if /i "%1"=="nobuild" set nobuild=1&goto arg-ok
|
34
|
+
if /i "%1"=="x86" set target_arch=ia32&set platform=WIN32&set vs_toolset=x86&goto arg-ok
|
35
|
+
if /i "%1"=="ia32" set target_arch=ia32&set platform=WIN32&set vs_toolset=x86&goto arg-ok
|
36
|
+
if /i "%1"=="x64" set target_arch=x64&set platform=amd64&set vs_toolset=x64&goto arg-ok
|
37
|
+
if /i "%1"=="shared" set library=shared_library&goto arg-ok
|
38
|
+
if /i "%1"=="static" set library=static_library&goto arg-ok
|
39
|
+
:arg-ok
|
40
|
+
shift
|
41
|
+
goto next-arg
|
42
|
+
:args-done
|
43
|
+
|
44
|
+
@rem Look for Visual Studio 2010
|
45
|
+
if not defined VS100COMNTOOLS goto vc-set-2008
|
46
|
+
if not exist "%VS100COMNTOOLS%\..\..\vc\vcvarsall.bat" goto vc-set-2008
|
47
|
+
call "%VS100COMNTOOLS%\..\..\vc\vcvarsall.bat" %vs_toolset%
|
48
|
+
set GYP_MSVS_VERSION=2010
|
49
|
+
goto select-target
|
50
|
+
|
51
|
+
:vc-set-2008
|
52
|
+
@rem Look for Visual Studio 2008
|
53
|
+
if not defined VS90COMNTOOLS goto vc-set-notfound
|
54
|
+
if not exist "%VS90COMNTOOLS%\..\..\vc\vcvarsall.bat" goto vc-set-notfound
|
55
|
+
call "%VS90COMNTOOLS%\..\..\vc\vcvarsall.bat" %vs_toolset%
|
56
|
+
set GYP_MSVS_VERSION=2008
|
57
|
+
goto select-target
|
58
|
+
|
59
|
+
:vc-set-notfound
|
60
|
+
echo Warning: Visual Studio not found
|
61
|
+
|
62
|
+
:select-target
|
63
|
+
if not "%config%"=="" goto project-gen
|
64
|
+
if "%run%"=="run-tests.exe" set config=Debug& goto project-gen
|
65
|
+
if "%run%"=="run-benchmarks.exe" set config=Release& goto project-gen
|
66
|
+
set config=Debug
|
67
|
+
|
68
|
+
:project-gen
|
69
|
+
@rem Skip project generation if requested.
|
70
|
+
if defined noprojgen goto msbuild
|
71
|
+
|
72
|
+
@rem Generate the VS project.
|
73
|
+
if exist build\gyp goto have_gyp
|
74
|
+
echo git clone https://git.chromium.org/external/gyp.git build/gyp
|
75
|
+
git clone https://git.chromium.org/external/gyp.git build/gyp
|
76
|
+
if errorlevel 1 goto gyp_install_failed
|
77
|
+
goto have_gyp
|
78
|
+
|
79
|
+
:gyp_install_failed
|
80
|
+
echo Failed to download gyp. Make sure you have git installed, or
|
81
|
+
echo manually install gyp into %~dp0build\gyp.
|
82
|
+
exit /b 1
|
83
|
+
|
84
|
+
:have_gyp
|
85
|
+
if not defined PYTHON set PYTHON="python"
|
86
|
+
%PYTHON% gyp_uv -Dtarget_arch=%target_arch% -Dlibrary=%library%
|
87
|
+
if errorlevel 1 goto create-msvs-files-failed
|
88
|
+
if not exist uv.sln goto create-msvs-files-failed
|
89
|
+
echo Project files generated.
|
90
|
+
|
91
|
+
:msbuild
|
92
|
+
@rem Skip project generation if requested.
|
93
|
+
if defined nobuild goto run
|
94
|
+
|
95
|
+
@rem Check if VS build env is available
|
96
|
+
if not defined VCINSTALLDIR goto msbuild-not-found
|
97
|
+
goto msbuild-found
|
98
|
+
|
99
|
+
:msbuild-not-found
|
100
|
+
echo Build skipped. To build, this file needs to run from VS cmd prompt.
|
101
|
+
goto run
|
102
|
+
|
103
|
+
@rem Build the sln with msbuild.
|
104
|
+
:msbuild-found
|
105
|
+
msbuild uv.sln /t:%target% /p:Configuration=%config% /p:Platform="%platform%" /clp:NoSummary;NoItemAndPropertyList;Verbosity=minimal /nologo
|
106
|
+
if errorlevel 1 exit /b 1
|
107
|
+
|
108
|
+
:run
|
109
|
+
@rem Run tests if requested.
|
110
|
+
if "%run%"=="" goto exit
|
111
|
+
if not exist %config%\%run% goto exit
|
112
|
+
echo running '%config%\%run%'
|
113
|
+
%config%\%run%
|
114
|
+
goto exit
|
115
|
+
|
116
|
+
:create-msvs-files-failed
|
117
|
+
echo Failed to create vc project files.
|
118
|
+
exit /b 1
|
119
|
+
|
120
|
+
:help
|
121
|
+
echo vcbuild.bat [debug/release] [test/bench] [clean] [noprojgen] [nobuild] [x86/x64] [static/shared]
|
122
|
+
echo Examples:
|
123
|
+
echo vcbuild.bat : builds debug build
|
124
|
+
echo vcbuild.bat test : builds debug build and runs tests
|
125
|
+
echo vcbuild.bat release bench: builds release build and runs benchmarks
|
126
|
+
goto exit
|
127
|
+
|
128
|
+
:exit
|
data/ext/rbuv/debug.h
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#ifndef RBUV_DEBUG_H_
|
2
|
+
#define RBUV_DEBUG_H_
|
3
|
+
|
4
|
+
# ifndef RBUV_DEBUG
|
5
|
+
|
6
|
+
# define RBUV_DEBUG_LOG(...)
|
7
|
+
# define RBUV_DEBUG_LOG_DETAIL(...)
|
8
|
+
|
9
|
+
# else
|
10
|
+
|
11
|
+
# include <stdio.h>
|
12
|
+
|
13
|
+
# define RBUV_DEBUG_LOG(...) do {\
|
14
|
+
fprintf(stderr, "[rbuv] [%s] ", __func__);\
|
15
|
+
fprintf(stderr, __VA_ARGS__);\
|
16
|
+
fprintf(stderr, "\n");\
|
17
|
+
} while (0)
|
18
|
+
|
19
|
+
# if RBUV_DEBUG > 1
|
20
|
+
# define RBUV_DEBUG_LOG_DETAIL(...) RBUV_DEBUG_LOG(__VA_ARGS__)
|
21
|
+
# else
|
22
|
+
# define RBUV_DEBUG_LOG_DETAIL(...)
|
23
|
+
# endif
|
24
|
+
|
25
|
+
# endif
|
26
|
+
|
27
|
+
#endif /* RBUV_DEBUG_H_ */
|
data/ext/rbuv/error.c
ADDED
data/ext/rbuv/error.h
ADDED
data/ext/rbuv/extconf.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'mkmf'
|
2
|
+
require 'rbconfig'
|
3
|
+
|
4
|
+
case RbConfig::CONFIG["host_os"]
|
5
|
+
when /darwin/
|
6
|
+
have_framework("CoreFoundation")
|
7
|
+
have_framework("CoreServices") if RUBY_ENGINE =~ /rbx/
|
8
|
+
end
|
9
|
+
|
10
|
+
dir_config('uv')
|
11
|
+
libuv_ok = have_library('uv', 'uv_run', ['uv.h'])
|
12
|
+
|
13
|
+
##
|
14
|
+
# Adds -DRBUV_DEBUG for compilation
|
15
|
+
# To turn it on, use: --with-debug or --enable-debug
|
16
|
+
#
|
17
|
+
|
18
|
+
if debug_arg = with_config("debug") || enable_config("debug")
|
19
|
+
debug_def = "-DRBUV_DEBUG"
|
20
|
+
$defs.push(debug_arg.is_a?(String) ? "#{debug_def}=#{debug_arg}" : debug_def) unless $defs.include?(/\A#{debug_arg}/)
|
21
|
+
end
|
22
|
+
|
23
|
+
case RUBY_ENGINE
|
24
|
+
when /rbx/
|
25
|
+
$defs.push("-DRBUV_RBX") unless $defs.include? "-DRBUV_RBX"
|
26
|
+
end
|
27
|
+
|
28
|
+
create_header
|
29
|
+
create_makefile('rbuv/rbuv')
|
30
|
+
|
31
|
+
unless libuv_ok
|
32
|
+
File.open('Makefile', 'a') do |mf|
|
33
|
+
mf.puts('include ${srcdir}/libuv.mk')
|
34
|
+
end
|
35
|
+
end
|
data/ext/rbuv/handle.c
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
#include "handle.h"
|
2
|
+
|
3
|
+
struct rbuv_handle_s {
|
4
|
+
uv_handle_t *uv_handle;
|
5
|
+
};
|
6
|
+
|
7
|
+
VALUE cRbuvHandle;
|
8
|
+
|
9
|
+
/* Methods */
|
10
|
+
static VALUE rbuv_handle_is_active(VALUE self);
|
11
|
+
|
12
|
+
/* Private methods */
|
13
|
+
static void _uv_handle_on_close(uv_handle_t *uv_handle);
|
14
|
+
|
15
|
+
void Init_rbuv_handle() {
|
16
|
+
cRbuvHandle = rb_define_class_under(mRbuv, "Handle", rb_cObject);
|
17
|
+
rb_undef_alloc_func(cRbuvHandle);
|
18
|
+
|
19
|
+
rb_define_method(cRbuvHandle, "active?", rbuv_handle_is_active, 0);
|
20
|
+
}
|
21
|
+
|
22
|
+
VALUE rbuv_handle_is_active(VALUE self) {
|
23
|
+
rbuv_handle_t *rbuv_handle;
|
24
|
+
|
25
|
+
Data_Get_Struct(self, rbuv_handle_t, rbuv_handle);
|
26
|
+
|
27
|
+
return uv_is_active(rbuv_handle->uv_handle) ? Qtrue : Qfalse;
|
28
|
+
}
|
29
|
+
|
30
|
+
void rbuv_handle_close(rbuv_handle_t *rbuv_handle) {
|
31
|
+
assert(rbuv_handle);
|
32
|
+
assert(rbuv_handle->uv_handle);
|
33
|
+
uv_close(rbuv_handle->uv_handle, _uv_handle_on_close);
|
34
|
+
}
|
35
|
+
|
36
|
+
void _uv_handle_on_close(uv_handle_t *uv_handle) {
|
37
|
+
RBUV_DEBUG_LOG_DETAIL("uv_handle: %p, handle: %ld",
|
38
|
+
uv_handle, (VALUE)uv_handle->data);
|
39
|
+
free(uv_handle);
|
40
|
+
}
|
data/ext/rbuv/handle.h
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#ifndef RBUV_HANDLE_H_
|
2
|
+
#define RBUV_HANDLE_H_
|
3
|
+
|
4
|
+
#include "rbuv.h"
|
5
|
+
|
6
|
+
typedef struct rbuv_handle_s rbuv_handle_t;
|
7
|
+
|
8
|
+
extern VALUE cRbuvHandle;
|
9
|
+
|
10
|
+
void Init_rbuv_handle();
|
11
|
+
|
12
|
+
void rbuv_handle_close(rbuv_handle_t *rbuv_handle);
|
13
|
+
|
14
|
+
#endif /* RBUV_HANDLE_H_ */
|
data/ext/rbuv/libuv.mk
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
DEPS_DIR := $(srcdir)/../../deps
|
2
|
+
LIBUV_DIR := $(DEPS_DIR)/libuv
|
3
|
+
|
4
|
+
INCFLAGS += -I"$(LIBUV_DIR)/include"
|
5
|
+
|
6
|
+
LIBUV_A = "$(LIBUV_DIR)/libuv.a"
|
7
|
+
|
8
|
+
$(OBJS): $(LIBUV_A)
|
9
|
+
|
10
|
+
OBJS += $(LIBUV_A)
|
11
|
+
$(LIBUV_A): $(LIBUV_DIR)
|
12
|
+
CFLAGS="-fPIC" $(MAKE) -C "$(LIBUV_DIR)"
|
data/ext/rbuv/loop.c
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
#include "loop.h"
|
2
|
+
|
3
|
+
struct rbuv_handle_s {
|
4
|
+
uv_handle_t *uv_handle;
|
5
|
+
};
|
6
|
+
|
7
|
+
VALUE cRbuvLoop;
|
8
|
+
|
9
|
+
/* Methods */
|
10
|
+
static VALUE rbuv_loop_s_run(VALUE klass);
|
11
|
+
static VALUE rbuv_loop_s_stop(VALUE klass);
|
12
|
+
static VALUE rbuv_loop_s_run_once(VALUE klass);
|
13
|
+
static VALUE rbuv_loop_s_run_nowait(VALUE klass);
|
14
|
+
|
15
|
+
/* Private methods */
|
16
|
+
static void _rbuv_loop_run(uv_run_mode mode);
|
17
|
+
|
18
|
+
void Init_rbuv_loop() {
|
19
|
+
cRbuvLoop = rb_define_class_under(mRbuv, "Loop", cRbuvHandle);
|
20
|
+
rb_undef_alloc_func(cRbuvLoop);
|
21
|
+
|
22
|
+
rb_define_singleton_method(cRbuvLoop, "run", rbuv_loop_s_run, 0);
|
23
|
+
rb_define_singleton_method(cRbuvLoop, "stop", rbuv_loop_s_stop, 0);
|
24
|
+
rb_define_singleton_method(cRbuvLoop, "run_once", rbuv_loop_s_run_once, 0);
|
25
|
+
rb_define_singleton_method(cRbuvLoop, "run_nowait", rbuv_loop_s_run_nowait, 0);
|
26
|
+
}
|
27
|
+
|
28
|
+
VALUE rbuv_loop_s_run(VALUE klass) {
|
29
|
+
_rbuv_loop_run(UV_RUN_DEFAULT);
|
30
|
+
return Qnil;
|
31
|
+
}
|
32
|
+
|
33
|
+
VALUE rbuv_loop_s_stop(VALUE klass) {
|
34
|
+
uv_stop(uv_default_loop());
|
35
|
+
return Qnil;
|
36
|
+
}
|
37
|
+
|
38
|
+
VALUE rbuv_loop_s_run_once(VALUE klass) {
|
39
|
+
_rbuv_loop_run(UV_RUN_ONCE);
|
40
|
+
return Qnil;
|
41
|
+
}
|
42
|
+
|
43
|
+
VALUE rbuv_loop_s_run_nowait(VALUE klass) {
|
44
|
+
_rbuv_loop_run(UV_RUN_NOWAIT);
|
45
|
+
return Qnil;
|
46
|
+
}
|
47
|
+
|
48
|
+
void _rbuv_loop_run(uv_run_mode mode) {
|
49
|
+
uv_run(uv_default_loop(), mode);
|
50
|
+
}
|
data/ext/rbuv/loop.h
ADDED
data/ext/rbuv/rbuv.c
ADDED
data/ext/rbuv/rbuv.h
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#ifndef RBUV_H_
|
2
|
+
#define RBUV_H_
|
3
|
+
|
4
|
+
#include <assert.h>
|
5
|
+
|
6
|
+
#include <ruby.h>
|
7
|
+
#include <uv.h>
|
8
|
+
|
9
|
+
#include "debug.h"
|
10
|
+
|
11
|
+
#include "error.h"
|
12
|
+
#include "handle.h"
|
13
|
+
#include "loop.h"
|
14
|
+
#include "timer.h"
|
15
|
+
|
16
|
+
extern ID id_call;
|
17
|
+
|
18
|
+
extern VALUE mRbuv;
|
19
|
+
|
20
|
+
#define RBUV_CHECK_UV_RETURN(uv_ret) do { \
|
21
|
+
if (uv_ret) { \
|
22
|
+
uv_err_t err = uv_last_error(uv_default_loop()); \
|
23
|
+
rb_raise(eRbuvError, "%s", uv_strerror(err)); \
|
24
|
+
} \
|
25
|
+
} while(0)
|
26
|
+
|
27
|
+
#endif /* RBUV_H_ */
|
data/ext/rbuv/timer.c
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
#include "timer.h"
|
2
|
+
|
3
|
+
VALUE cRbuvTimer;
|
4
|
+
|
5
|
+
struct rbuv_timer_s {
|
6
|
+
uv_timer_t *uv_handle;
|
7
|
+
VALUE cb;
|
8
|
+
};
|
9
|
+
|
10
|
+
/* Allocator/deallocator */
|
11
|
+
static VALUE rbuv_timer_alloc(VALUE klass);
|
12
|
+
static void rbuv_timer_mark(rbuv_timer_t *rbuv_timer);
|
13
|
+
static void rbuv_timer_free(rbuv_timer_t *rbuv_timer);
|
14
|
+
|
15
|
+
/* Methods */
|
16
|
+
static VALUE rbuv_timer_start(VALUE self, VALUE timeout, VALUE repeat);
|
17
|
+
static VALUE rbuv_timer_stop(VALUE self);
|
18
|
+
static VALUE rbuv_timer_repeat_get(VALUE self);
|
19
|
+
static VALUE rbuv_timer_repeat_set(VALUE self, VALUE repeat);
|
20
|
+
|
21
|
+
/* Private methods */
|
22
|
+
static void _uv_timer_on_timeout(uv_timer_t *uv_timer, int status);
|
23
|
+
|
24
|
+
void Init_rbuv_timer() {
|
25
|
+
cRbuvTimer = rb_define_class_under(mRbuv, "Timer", cRbuvHandle);
|
26
|
+
rb_define_alloc_func(cRbuvTimer, rbuv_timer_alloc);
|
27
|
+
|
28
|
+
rb_define_method(cRbuvTimer, "start", rbuv_timer_start, 2);
|
29
|
+
rb_define_method(cRbuvTimer, "stop", rbuv_timer_stop, 0);
|
30
|
+
rb_define_method(cRbuvTimer, "repeat", rbuv_timer_repeat_get, 0);
|
31
|
+
rb_define_method(cRbuvTimer, "repeat=", rbuv_timer_repeat_set, 1);
|
32
|
+
}
|
33
|
+
|
34
|
+
VALUE rbuv_timer_alloc(VALUE klass) {
|
35
|
+
rbuv_timer_t *rbuv_timer;
|
36
|
+
VALUE timer;
|
37
|
+
|
38
|
+
rbuv_timer = malloc(sizeof(*rbuv_timer));
|
39
|
+
rbuv_timer->uv_handle = malloc(sizeof(*rbuv_timer->uv_handle));
|
40
|
+
uv_timer_init(uv_default_loop(), rbuv_timer->uv_handle);
|
41
|
+
rbuv_timer->cb = Qnil;
|
42
|
+
|
43
|
+
timer = Data_Wrap_Struct(klass, rbuv_timer_mark, rbuv_timer_free, rbuv_timer);
|
44
|
+
rbuv_timer->uv_handle->data = (void *)timer;
|
45
|
+
|
46
|
+
return timer;
|
47
|
+
}
|
48
|
+
|
49
|
+
void rbuv_timer_mark(rbuv_timer_t *rbuv_timer) {
|
50
|
+
assert(rbuv_timer);
|
51
|
+
rb_gc_mark(rbuv_timer->cb);
|
52
|
+
}
|
53
|
+
|
54
|
+
void rbuv_timer_free(rbuv_timer_t *rbuv_timer) {
|
55
|
+
assert(rbuv_timer);
|
56
|
+
rbuv_handle_close((rbuv_handle_t *)rbuv_timer);
|
57
|
+
free(rbuv_timer);
|
58
|
+
}
|
59
|
+
|
60
|
+
/**
|
61
|
+
* start the timer.
|
62
|
+
* @param timeout the timeout in millisecond.
|
63
|
+
* @param repeat the repeat interval in millisecond.
|
64
|
+
* @return self
|
65
|
+
*/
|
66
|
+
VALUE rbuv_timer_start(VALUE self, VALUE timeout, VALUE repeat) {
|
67
|
+
VALUE block;
|
68
|
+
uint64_t uv_timeout;
|
69
|
+
uint64_t uv_repeat;
|
70
|
+
rbuv_timer_t *rbuv_timer;
|
71
|
+
|
72
|
+
rb_need_block();
|
73
|
+
block = rb_block_proc();
|
74
|
+
uv_timeout = NUM2ULL(timeout);
|
75
|
+
uv_repeat = NUM2ULL(repeat);
|
76
|
+
|
77
|
+
Data_Get_Struct(self, rbuv_timer_t, rbuv_timer);
|
78
|
+
rbuv_timer->cb = block;
|
79
|
+
|
80
|
+
RBUV_DEBUG_LOG_DETAIL("rbuv_timer: %p, uv_handle: %p, _uv_timer_on_timeout: %p, timer: %ld",
|
81
|
+
rbuv_timer, rbuv_timer->uv_handle, _uv_timer_on_timeout, self);
|
82
|
+
uv_timer_start(rbuv_timer->uv_handle, _uv_timer_on_timeout,
|
83
|
+
uv_timeout, uv_repeat);
|
84
|
+
|
85
|
+
return self;
|
86
|
+
}
|
87
|
+
|
88
|
+
/**
|
89
|
+
* stop the timer.
|
90
|
+
* @return self
|
91
|
+
*/
|
92
|
+
VALUE rbuv_timer_stop(VALUE self) {
|
93
|
+
rbuv_timer_t *rbuv_timer;
|
94
|
+
|
95
|
+
Data_Get_Struct(self, rbuv_timer_t, rbuv_timer);
|
96
|
+
|
97
|
+
uv_timer_stop(rbuv_timer->uv_handle);
|
98
|
+
|
99
|
+
return self;
|
100
|
+
}
|
101
|
+
|
102
|
+
VALUE rbuv_timer_repeat_get(VALUE self) {
|
103
|
+
rbuv_timer_t *rbuv_timer;
|
104
|
+
VALUE repeat;
|
105
|
+
|
106
|
+
Data_Get_Struct(self, rbuv_timer_t, rbuv_timer);
|
107
|
+
repeat = ULL2NUM(uv_timer_get_repeat(rbuv_timer->uv_handle));
|
108
|
+
|
109
|
+
return repeat;
|
110
|
+
}
|
111
|
+
|
112
|
+
VALUE rbuv_timer_repeat_set(VALUE self, VALUE repeat) {
|
113
|
+
rbuv_timer_t *rbuv_timer;
|
114
|
+
uint64_t uv_repeat;
|
115
|
+
|
116
|
+
uv_repeat = NUM2ULL(repeat);
|
117
|
+
|
118
|
+
Data_Get_Struct(self, rbuv_timer_t, rbuv_timer);
|
119
|
+
|
120
|
+
uv_timer_set_repeat(rbuv_timer->uv_handle, uv_repeat);
|
121
|
+
|
122
|
+
return repeat;
|
123
|
+
}
|
124
|
+
|
125
|
+
void _uv_timer_on_timeout(uv_timer_t *uv_timer, int status) {
|
126
|
+
VALUE timer;
|
127
|
+
rbuv_timer_t *rbuv_timer;
|
128
|
+
|
129
|
+
timer = (VALUE)uv_timer->data;
|
130
|
+
Data_Get_Struct(timer, struct rbuv_timer_s, rbuv_timer);
|
131
|
+
|
132
|
+
rb_funcall(rbuv_timer->cb, id_call, 1, timer);
|
133
|
+
}
|
data/ext/rbuv/timer.h
ADDED
data/lib/rbuv/timer.rb
ADDED
data/lib/rbuv/version.rb
CHANGED
data/lib/rbuv.rb
CHANGED
@@ -1,5 +1,27 @@
|
|
1
|
-
require
|
1
|
+
require 'rbuv/rbuv'
|
2
|
+
require 'rbuv/version'
|
3
|
+
require 'rbuv/timer'
|
2
4
|
|
3
5
|
module Rbuv
|
4
|
-
|
6
|
+
def self.run_loop
|
7
|
+
Loop.run
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.stop_loop
|
11
|
+
Loop.stop
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.run
|
15
|
+
Timer.start 0, 0 do
|
16
|
+
yield
|
17
|
+
end
|
18
|
+
self.run_loop
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.run_block
|
22
|
+
Timer.start 0, 0 do
|
23
|
+
yield
|
24
|
+
end
|
25
|
+
Loop.run_once
|
26
|
+
end
|
5
27
|
end
|
data/rbuv.gemspec
CHANGED
@@ -14,10 +14,14 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.extensions = ['ext/rbuv/extconf.rb']
|
17
18
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
20
|
spec.require_paths = ["lib"]
|
20
21
|
|
21
|
-
spec.add_development_dependency "bundler"
|
22
|
+
spec.add_development_dependency "bundler"
|
22
23
|
spec.add_development_dependency "rake"
|
24
|
+
spec.add_development_dependency "rake-compiler"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
spec.add_development_dependency "coveralls"
|
23
27
|
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'coveralls'
|
2
|
+
Coveralls.wear!
|
3
|
+
|
4
|
+
require 'rbuv'
|
5
|
+
|
6
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
7
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
8
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
9
|
+
# loaded once.
|
10
|
+
#
|
11
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
12
|
+
RSpec.configure do |config|
|
13
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
14
|
+
config.run_all_when_everything_filtered = true
|
15
|
+
config.filter_run :focus
|
16
|
+
|
17
|
+
# Run specs in random order to surface order dependencies. If you find an
|
18
|
+
# order dependency and want to debug it, you can fix the order by providing
|
19
|
+
# the seed, which is printed after each run.
|
20
|
+
# --seed 1234
|
21
|
+
config.order = 'random'
|
22
|
+
end
|