monster_engine 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/FUNDING.yml +12 -0
- data/.gitignore +13 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +25 -0
- data/LICENSE.txt +21 -0
- data/README.md +6 -0
- data/Rakefile +10 -0
- data/bin/monster_engine +19 -0
- data/ext/monster_engine/extconf.rb +13 -0
- data/ext/monster_engine/monster_engine.c +9 -0
- data/ext/monster_engine/monster_engine.h +11 -0
- data/ext/monster_engine/monster_engine_config.c +56 -0
- data/ext/monster_engine/monster_engine_config.h +7 -0
- data/ext/monster_engine/monster_engine_server.c +76 -0
- data/ext/monster_engine/monster_engine_server.h +6 -0
- data/lib/monster_engine.rb +7 -0
- data/lib/monster_engine/version.rb +3 -0
- data/monster_engine.gemspec +30 -0
- metadata +118 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a46f1b9b61fdddb909bd9bbe68647a8b9861a2eb67774825cb0c9b2e1bdd7c79
|
4
|
+
data.tar.gz: '0398cc372781fd2cadb5553261fa40cb7cdbd86ed083f40b3bc850df566e41c5'
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 586cdd19a1102e1abedef00c6944a73767df59888c3f3ecd1722016809e63a94c1517b5daf9af2dd33f12cf07a283be735475d28920f671c32faae7691bc0fd5
|
7
|
+
data.tar.gz: e2ad04aae69fe580748c25d72a0264c13c46a52cf9cb7ab1472ce9bcc23b5cabd983398e24e2e8a9a1c0721dc3c9cf1c9e79c37c9fbf7a774742eb39af35b82f
|
data/.github/FUNDING.yml
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# These are supported funding model platforms
|
2
|
+
|
3
|
+
github: [otake84] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
4
|
+
patreon: # Replace with a single Patreon username
|
5
|
+
open_collective: # Replace with a single Open Collective username
|
6
|
+
ko_fi: # Replace with a single Ko-fi username
|
7
|
+
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
8
|
+
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
9
|
+
liberapay: # Replace with a single Liberapay username
|
10
|
+
issuehunt: # Replace with a single IssueHunt username
|
11
|
+
otechie: # Replace with a single Otechie username
|
12
|
+
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
monster_engine (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
plamo (0.4.0)
|
10
|
+
rake (13.0.1)
|
11
|
+
rake-compiler (1.1.0)
|
12
|
+
rake
|
13
|
+
|
14
|
+
PLATFORMS
|
15
|
+
ruby
|
16
|
+
|
17
|
+
DEPENDENCIES
|
18
|
+
bundler (~> 2.0)
|
19
|
+
monster_engine!
|
20
|
+
plamo (~> 0.4.0)
|
21
|
+
rake (~> 13.0)
|
22
|
+
rake-compiler
|
23
|
+
|
24
|
+
BUNDLED WITH
|
25
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Shogo Otake
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
# monsterengine-ruby
|
2
|
+
monster_engine_ruby is [libmonsterengine](https://github.com/monsterengine/libmonsterengine) bindings for Ruby.
|
3
|
+
## Installation
|
4
|
+
Please install [libplamo](https://github.com/plamo/libplamo) and [libmonsterengine](https://github.com/monsterengine/libmonsterengine) before using monster_engine_ruby.
|
5
|
+
## License
|
6
|
+
MIT License
|
data/Rakefile
ADDED
data/bin/monster_engine
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require 'plamo'
|
5
|
+
require 'monster_engine'
|
6
|
+
|
7
|
+
GC.disable
|
8
|
+
|
9
|
+
plamo_middleware = Plamo::Middleware.new(nil, ->(config, request, response) {
|
10
|
+
response.body = 'Yo, MonsterEngine'
|
11
|
+
})
|
12
|
+
|
13
|
+
plamo_app = Plamo::App.new
|
14
|
+
plamo_app.push_middleware(plamo_middleware)
|
15
|
+
|
16
|
+
monster_engine_config = MonsterEngine::Config.new
|
17
|
+
monster_engine_config.bind = '0.0.0.0:8888'
|
18
|
+
|
19
|
+
MonsterEngine::Server.new(plamo_app, monster_engine_config).start
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "mkmf"
|
2
|
+
|
3
|
+
dir_config('plamo', "/usr/include", "/usr/lib")
|
4
|
+
|
5
|
+
unless find_header("libmonsterengine.h")
|
6
|
+
abort "libplamo is missing. please install libmonsterengine"
|
7
|
+
end
|
8
|
+
|
9
|
+
unless find_library("monsterengine", "monster_engine_server_start")
|
10
|
+
abort "libplamo is missing. please install libmonsterengine"
|
11
|
+
end
|
12
|
+
|
13
|
+
create_makefile("monster_engine/monster_engine")
|
@@ -0,0 +1,56 @@
|
|
1
|
+
#include "monster_engine.h"
|
2
|
+
|
3
|
+
VALUE rb_cMonsterEngineConfig;
|
4
|
+
|
5
|
+
static void deallocate(void *monster_engine_config) {
|
6
|
+
monster_engine_config_destroy(monster_engine_config);
|
7
|
+
}
|
8
|
+
|
9
|
+
const rb_data_type_t rb_monster_engine_config_type = {
|
10
|
+
"Config",
|
11
|
+
{
|
12
|
+
NULL,
|
13
|
+
deallocate,
|
14
|
+
NULL,
|
15
|
+
},
|
16
|
+
NULL,
|
17
|
+
NULL,
|
18
|
+
0,
|
19
|
+
};
|
20
|
+
|
21
|
+
static VALUE allocate(VALUE klass) {
|
22
|
+
return TypedData_Wrap_Struct(klass, &rb_monster_engine_config_type, NULL);
|
23
|
+
}
|
24
|
+
|
25
|
+
static VALUE initialize(VALUE self) {
|
26
|
+
DATA_PTR(self) = monster_engine_config_new();
|
27
|
+
rb_iv_set(self, "@workers", INT2FIX(1));
|
28
|
+
return self;
|
29
|
+
}
|
30
|
+
|
31
|
+
static VALUE get_bind(VALUE self) {
|
32
|
+
return rb_str_new2(monster_engine_config_get_bind(DATA_PTR(self)));
|
33
|
+
}
|
34
|
+
|
35
|
+
static VALUE set_bind(VALUE self, VALUE rb_bind) {
|
36
|
+
monster_engine_config_set_bind(DATA_PTR(self), StringValueCStr(rb_bind));
|
37
|
+
return Qnil;
|
38
|
+
}
|
39
|
+
|
40
|
+
static VALUE get_workers(VALUE self) {
|
41
|
+
return rb_iv_get(self, "@workers");
|
42
|
+
}
|
43
|
+
|
44
|
+
static VALUE set_workers(VALUE self, VALUE rb_workers) {
|
45
|
+
return rb_iv_set(self, "@workers", rb_workers);
|
46
|
+
}
|
47
|
+
|
48
|
+
void Init_monster_engine_config(void) {
|
49
|
+
rb_cMonsterEngineConfig = rb_define_class_under(rb_mMonsterEngine, "Config", rb_cObject);
|
50
|
+
rb_define_alloc_func(rb_cMonsterEngineConfig, allocate);
|
51
|
+
rb_define_method(rb_cMonsterEngineConfig, "initialize", initialize, 0);
|
52
|
+
rb_define_method(rb_cMonsterEngineConfig, "bind", get_bind, 0);
|
53
|
+
rb_define_method(rb_cMonsterEngineConfig, "bind=", set_bind, 1);
|
54
|
+
rb_define_method(rb_cMonsterEngineConfig, "workers", get_workers, 0);
|
55
|
+
rb_define_method(rb_cMonsterEngineConfig, "workers=", set_workers, 1);
|
56
|
+
}
|
@@ -0,0 +1,76 @@
|
|
1
|
+
#include "monster_engine.h"
|
2
|
+
#include <ruby/thread.h>
|
3
|
+
#include <sys/types.h>
|
4
|
+
#include <unistd.h>
|
5
|
+
|
6
|
+
extern const rb_data_type_t rb_plamo_app_type;
|
7
|
+
extern VALUE plamo_rb_event_thread(void*);
|
8
|
+
|
9
|
+
VALUE rb_cMonsterEngineServer;
|
10
|
+
|
11
|
+
static void deallocate(void *monster_engine_server) {
|
12
|
+
monster_engine_server_destroy(monster_engine_server);
|
13
|
+
}
|
14
|
+
|
15
|
+
const rb_data_type_t rb_monster_engine_server_type = {
|
16
|
+
"Server",
|
17
|
+
{
|
18
|
+
NULL,
|
19
|
+
deallocate,
|
20
|
+
NULL,
|
21
|
+
},
|
22
|
+
NULL,
|
23
|
+
NULL,
|
24
|
+
0,
|
25
|
+
};
|
26
|
+
|
27
|
+
static VALUE allocate(VALUE klass) {
|
28
|
+
return TypedData_Wrap_Struct(klass, &rb_monster_engine_server_type, NULL);
|
29
|
+
}
|
30
|
+
|
31
|
+
static VALUE initialize(VALUE self, VALUE rb_plamo_app, VALUE rb_monster_engine_config) {
|
32
|
+
rb_iv_set(self, "@config", rb_monster_engine_config);
|
33
|
+
PlamoApp *plamo_app;
|
34
|
+
TypedData_Get_Struct(rb_plamo_app, PlamoApp, &rb_plamo_app_type, plamo_app);
|
35
|
+
MonsterEngineConfig *monster_engine_config;
|
36
|
+
TypedData_Get_Struct(rb_monster_engine_config, MonsterEngineConfig, &rb_monster_engine_config_type, monster_engine_config);
|
37
|
+
DATA_PTR(self) = monster_engine_server_new(plamo_app, monster_engine_config);
|
38
|
+
return self;
|
39
|
+
}
|
40
|
+
|
41
|
+
typedef struct MonsterEngineRbCallbackSetting {
|
42
|
+
PlamoApp *plamo_app;
|
43
|
+
MonsterEngineConfig *monster_engine_config;
|
44
|
+
} MonsterEngineRbCallbackSetting;
|
45
|
+
|
46
|
+
static void* callback(void *monster_engine_server) {
|
47
|
+
monster_engine_server_start(monster_engine_server);
|
48
|
+
return NULL;
|
49
|
+
}
|
50
|
+
|
51
|
+
static VALUE start(VALUE self) {
|
52
|
+
VALUE rb_config = rb_iv_get(self, "@config");
|
53
|
+
const unsigned int workers = FIX2UINT(rb_iv_get(rb_config, "@workers"));
|
54
|
+
for (int i = 0; i < workers; i++) {
|
55
|
+
pid_t pid = fork();
|
56
|
+
if (pid == 0) {
|
57
|
+
rb_thread_create(plamo_rb_event_thread, NULL);
|
58
|
+
rb_thread_call_without_gvl(callback, DATA_PTR(self), RUBY_UBF_PROCESS, NULL);
|
59
|
+
break;
|
60
|
+
} else if (pid == -1) {
|
61
|
+
break;
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
65
|
+
while (true) {
|
66
|
+
sleep(1);
|
67
|
+
}
|
68
|
+
|
69
|
+
return Qnil;
|
70
|
+
}
|
71
|
+
|
72
|
+
void Init_monster_engine_server(void) {
|
73
|
+
rb_cMonsterEngineServer = rb_define_class_under(rb_mMonsterEngine, "Server", rb_cObject);
|
74
|
+
rb_define_method(rb_cMonsterEngineServer, "initialize", initialize, 2);
|
75
|
+
rb_define_method(rb_cMonsterEngineServer, "start", start, 0);
|
76
|
+
}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "monster_engine/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "monster_engine"
|
8
|
+
spec.version = MonsterEngine::VERSION
|
9
|
+
spec.authors = ["Shogo Otake"]
|
10
|
+
spec.email = ["shogo.otake@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "Ruby Bindings for libmonsterengine"
|
13
|
+
spec.homepage = "https://github.com/monsterengine/monsterengine-ruby"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# Specify which files should be added to the gem when it is released.
|
17
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
18
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
19
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
end
|
21
|
+
spec.bindir = "exe"
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
spec.extensions = ["ext/monster_engine/extconf.rb"]
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
27
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
28
|
+
spec.add_development_dependency "rake-compiler"
|
29
|
+
spec.add_development_dependency "plamo", "~> 0.4.0"
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: monster_engine
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Shogo Otake
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-01-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '13.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '13.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake-compiler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: plamo
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.4.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.4.0
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- shogo.otake@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions:
|
74
|
+
- ext/monster_engine/extconf.rb
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".github/FUNDING.yml"
|
78
|
+
- ".gitignore"
|
79
|
+
- Gemfile
|
80
|
+
- Gemfile.lock
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/monster_engine
|
85
|
+
- ext/monster_engine/extconf.rb
|
86
|
+
- ext/monster_engine/monster_engine.c
|
87
|
+
- ext/monster_engine/monster_engine.h
|
88
|
+
- ext/monster_engine/monster_engine_config.c
|
89
|
+
- ext/monster_engine/monster_engine_config.h
|
90
|
+
- ext/monster_engine/monster_engine_server.c
|
91
|
+
- ext/monster_engine/monster_engine_server.h
|
92
|
+
- lib/monster_engine.rb
|
93
|
+
- lib/monster_engine/version.rb
|
94
|
+
- monster_engine.gemspec
|
95
|
+
homepage: https://github.com/monsterengine/monsterengine-ruby
|
96
|
+
licenses:
|
97
|
+
- MIT
|
98
|
+
metadata: {}
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options: []
|
101
|
+
require_paths:
|
102
|
+
- lib
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
requirements: []
|
114
|
+
rubygems_version: 3.1.2
|
115
|
+
signing_key:
|
116
|
+
specification_version: 4
|
117
|
+
summary: Ruby Bindings for libmonsterengine
|
118
|
+
test_files: []
|