ninix-fmo 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Gemfile +10 -0
- data/LICENSE.txt +21 -0
- data/README.md +22 -0
- data/Rakefile +8 -0
- data/ext/ninix-fmo/extconf.rb +16 -0
- data/ext/ninix-fmo/ninix-fmo.c +385 -0
- data/lib/ninix-fmo/version.rb +3 -0
- data/lib/ninix-fmo.rb +13 -0
- data/ninix-fmo.gemspec +33 -0
- metadata +94 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: d31940060a50f18939b42bb02ab12eecc0b07b39add612b41c5c7e49666654cb
|
|
4
|
+
data.tar.gz: 1a32218e7acd2a464718d3a98703ff890f7d3b0371a539a100808ee6cd73aba8
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 8dc0f3375a8eea977a39f65be5d17019c2f99a00fd69c8dd4b34d6724447d01e40bf2c3216fdfba7c7f4d55e65ea4b27dc95ec6b11c32b8aeebdc1a80ddfccf0
|
|
7
|
+
data.tar.gz: b24c0de63171f6c554125e2325e02a9f5265c45179474ba6aa57aa0c0e8503c8204a38f864d1f331356968b7b50a6df70a29fdcb4ac67a9b2d4a72b8b5c248e6
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Tatakinov
|
|
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,22 @@
|
|
|
1
|
+
# NinixFMO
|
|
2
|
+
|
|
3
|
+
A gem for using FileMappingObject in ninix-kagari.
|
|
4
|
+
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
apt install build-essential rake rake-compiler ruby-dev
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## How to Install
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
git clone https://github.com/Tatakinov/ninix-fmo.git
|
|
15
|
+
cd ninix-fmo
|
|
16
|
+
rake install
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## License
|
|
20
|
+
|
|
21
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
22
|
+
|
data/Rakefile
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require 'mkmf'
|
|
2
|
+
|
|
3
|
+
func = []
|
|
4
|
+
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
|
|
5
|
+
func = ['CreateMutex', 'OpenMutex', 'CreateFileMapping', 'OpenFileMapping',
|
|
6
|
+
'WaitForSingleObject', 'MapViewOfFile', 'UnmapViewOfFile',
|
|
7
|
+
'CloseHandle']
|
|
8
|
+
else
|
|
9
|
+
func = ['strndup', 'shm_open', 'ftruncate', 'mmap', 'sem_init', 'sem_wait', 'sem_post',
|
|
10
|
+
'munmap', 'shm_unlink', 'close']
|
|
11
|
+
end
|
|
12
|
+
for f in func
|
|
13
|
+
abort 'missing ' + f unless have_func f
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
create_makefile 'ninix-fmo/ninix_fmo'
|
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
#include <ruby.h>
|
|
2
|
+
#include <stdint.h>
|
|
3
|
+
#include <stdlib.h>
|
|
4
|
+
#include <string.h>
|
|
5
|
+
|
|
6
|
+
#ifdef WIN32
|
|
7
|
+
|
|
8
|
+
#include <windows.h>
|
|
9
|
+
|
|
10
|
+
#else
|
|
11
|
+
|
|
12
|
+
#include <errno.h>
|
|
13
|
+
#include <fcntl.h>
|
|
14
|
+
#include <semaphore.h>
|
|
15
|
+
#include <sys/mman.h>
|
|
16
|
+
#include <sys/stat.h>
|
|
17
|
+
#include <unistd.h>
|
|
18
|
+
|
|
19
|
+
#endif // WIN32
|
|
20
|
+
|
|
21
|
+
static const int OPENED = 1;
|
|
22
|
+
static const int CLOSED = 0;
|
|
23
|
+
static const int ERR = -1;
|
|
24
|
+
|
|
25
|
+
static const int F_RDONLY = 0x01;
|
|
26
|
+
static const int F_RDWR = 0x02;
|
|
27
|
+
static const int F_CREAT = 0x04;
|
|
28
|
+
static const int F_EXCL = 0x08;
|
|
29
|
+
static const int F_TRUNC = 0x10;
|
|
30
|
+
|
|
31
|
+
struct shm_t {
|
|
32
|
+
uint32_t size;
|
|
33
|
+
#ifdef WIN32
|
|
34
|
+
char buf[MAX_PATH];
|
|
35
|
+
#else
|
|
36
|
+
sem_t sem;
|
|
37
|
+
char buf[PATH_MAX];
|
|
38
|
+
#endif // WIN32
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
struct ninix_fmo {
|
|
42
|
+
int status;
|
|
43
|
+
struct shm_t *memory;
|
|
44
|
+
#ifdef WIN32
|
|
45
|
+
HANDLE mutex;
|
|
46
|
+
HANDLE fmo;
|
|
47
|
+
#else
|
|
48
|
+
int is_owner;
|
|
49
|
+
int fd;
|
|
50
|
+
char *name;
|
|
51
|
+
#endif // WIN32
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
#ifdef WIN32
|
|
55
|
+
static char *strndup_(char *s, size_t n) {
|
|
56
|
+
char *p = malloc(sizeof(char) * (n + 1));
|
|
57
|
+
if (p == NULL) {
|
|
58
|
+
return NULL;
|
|
59
|
+
}
|
|
60
|
+
memcpy(p, s, n);
|
|
61
|
+
p[n] = '\0';
|
|
62
|
+
return p;
|
|
63
|
+
}
|
|
64
|
+
#endif // WIN32
|
|
65
|
+
|
|
66
|
+
static void ninix_fmo_free(void *ptr) {
|
|
67
|
+
struct ninix_fmo *p = ptr;
|
|
68
|
+
if (p->status > CLOSED) {
|
|
69
|
+
p->status = CLOSED;
|
|
70
|
+
#ifdef WIN32
|
|
71
|
+
UnmapViewOfFile(p->memory);
|
|
72
|
+
CloseHandle(p->fmo);
|
|
73
|
+
CloseHandle(p->mutex);
|
|
74
|
+
#else
|
|
75
|
+
if (p->is_owner) {
|
|
76
|
+
sem_destroy(&p->memory->sem);
|
|
77
|
+
munmap(p->memory, sizeof(struct shm_t));
|
|
78
|
+
shm_unlink(p->name);
|
|
79
|
+
}
|
|
80
|
+
free(p->name);
|
|
81
|
+
#endif // WIN32
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
static VALUE ninix_fmo_alloc(VALUE klass) {
|
|
86
|
+
VALUE obj;
|
|
87
|
+
struct ninix_fmo *p;
|
|
88
|
+
|
|
89
|
+
obj = Data_Make_Struct(klass, struct ninix_fmo, NULL, ninix_fmo_free, p);
|
|
90
|
+
|
|
91
|
+
p->status = CLOSED;
|
|
92
|
+
#ifdef WIN32
|
|
93
|
+
#else
|
|
94
|
+
p->is_owner = 0;
|
|
95
|
+
#endif
|
|
96
|
+
|
|
97
|
+
return obj;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
static VALUE ninix_fmo_init(VALUE self, VALUE name, VALUE flag) {
|
|
101
|
+
struct ninix_fmo *p;
|
|
102
|
+
Data_Get_Struct(self, struct ninix_fmo, p);
|
|
103
|
+
Check_Type(name, T_STRING);
|
|
104
|
+
Check_Type(flag, T_FIXNUM);
|
|
105
|
+
int i = NUM2INT(flag);
|
|
106
|
+
#ifdef WIN32
|
|
107
|
+
DWORD create_flag = 0;
|
|
108
|
+
DWORD open_flag = 0;
|
|
109
|
+
BOOL is_owner = FALSE;
|
|
110
|
+
if (i & F_RDONLY) {
|
|
111
|
+
create_flag |= PAGE_READONLY;
|
|
112
|
+
open_flag |= FILE_MAP_READ;
|
|
113
|
+
}
|
|
114
|
+
if (i & F_RDWR) {
|
|
115
|
+
create_flag |= PAGE_READWRITE;
|
|
116
|
+
open_flag |= FILE_MAP_ALL_ACCESS;
|
|
117
|
+
}
|
|
118
|
+
if (i & F_CREAT) {
|
|
119
|
+
is_owner = TRUE;
|
|
120
|
+
}
|
|
121
|
+
int len = RSTRING_LENINT(name);
|
|
122
|
+
if (len + 6 >= MAX_PATH) {
|
|
123
|
+
goto error_too_long;
|
|
124
|
+
}
|
|
125
|
+
char *n = strndup_(RSTRING_PTR(name), len);
|
|
126
|
+
if (n == NULL) {
|
|
127
|
+
goto error_strndup;
|
|
128
|
+
}
|
|
129
|
+
char *n_for_mutex = (char *) malloc(sizeof(char) * (len + 6 + 1));
|
|
130
|
+
if (n_for_mutex == NULL) {
|
|
131
|
+
goto error_malloc;
|
|
132
|
+
}
|
|
133
|
+
memcpy(n_for_mutex, n, len);
|
|
134
|
+
memcpy(&n_for_mutex[len], "_mutex", 6);
|
|
135
|
+
n_for_mutex[len + 6] = '\0';
|
|
136
|
+
if (is_owner) {
|
|
137
|
+
p->fmo = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, create_flag, 0, sizeof(struct shm_t), n);
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
p->fmo = OpenFileMapping(open_flag, FALSE, n);
|
|
141
|
+
}
|
|
142
|
+
if (p->fmo == NULL) {
|
|
143
|
+
goto error_create_file_mapping;
|
|
144
|
+
}
|
|
145
|
+
p->memory = MapViewOfFile(p->fmo, open_flag, 0, 0, 0);
|
|
146
|
+
if (p->memory == NULL) {
|
|
147
|
+
goto error_map_view_of_file;
|
|
148
|
+
}
|
|
149
|
+
if (is_owner) {
|
|
150
|
+
p->memory->size = 0;
|
|
151
|
+
p->mutex = CreateMutex(NULL, FALSE, n_for_mutex);
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
p->mutex = OpenMutex(SYNCHRONIZE, FALSE, n_for_mutex);
|
|
155
|
+
}
|
|
156
|
+
if (p->mutex == NULL) {
|
|
157
|
+
goto error_create_mutex;
|
|
158
|
+
}
|
|
159
|
+
free(n_for_mutex);
|
|
160
|
+
free(n);
|
|
161
|
+
p->status = OPENED;
|
|
162
|
+
return self;
|
|
163
|
+
if (0) {
|
|
164
|
+
error_create_mutex:
|
|
165
|
+
rb_raise(rb_eSystemCallError, "failed to Create/OpenMutex");
|
|
166
|
+
}
|
|
167
|
+
UnmapViewOfFile(p->memory);
|
|
168
|
+
if (0) {
|
|
169
|
+
error_map_view_of_file:
|
|
170
|
+
rb_raise(rb_eSystemCallError, "failed to map_view_of_file");
|
|
171
|
+
}
|
|
172
|
+
CloseHandle(p->fmo);
|
|
173
|
+
if (0) {
|
|
174
|
+
error_create_file_mapping:
|
|
175
|
+
rb_raise(rb_eSystemCallError, "failed to Create/OpenFileMapping");
|
|
176
|
+
}
|
|
177
|
+
free(n_for_mutex);
|
|
178
|
+
if (0) {
|
|
179
|
+
error_malloc:
|
|
180
|
+
rb_raise(rb_eSystemCallError, "failed to malloc");
|
|
181
|
+
}
|
|
182
|
+
free(n);
|
|
183
|
+
if (0) {
|
|
184
|
+
error_strndup:
|
|
185
|
+
rb_raise(rb_eSystemCallError, "failed to strndup");
|
|
186
|
+
}
|
|
187
|
+
if (0) {
|
|
188
|
+
error_too_long:
|
|
189
|
+
rb_raise(rb_eArgError, "name is too long");
|
|
190
|
+
}
|
|
191
|
+
p->status = ERR;
|
|
192
|
+
return self;
|
|
193
|
+
#else
|
|
194
|
+
int f = 0;
|
|
195
|
+
if (i & F_RDONLY) {
|
|
196
|
+
f |= O_RDONLY;
|
|
197
|
+
}
|
|
198
|
+
if (i & F_RDWR) {
|
|
199
|
+
f |= O_RDWR;
|
|
200
|
+
}
|
|
201
|
+
if (i & F_CREAT) {
|
|
202
|
+
f |= O_CREAT;
|
|
203
|
+
p->is_owner = 1;
|
|
204
|
+
}
|
|
205
|
+
if (i & F_EXCL) {
|
|
206
|
+
f |= O_EXCL;
|
|
207
|
+
}
|
|
208
|
+
if (i & F_TRUNC) {
|
|
209
|
+
f |= O_TRUNC;
|
|
210
|
+
}
|
|
211
|
+
int len = RSTRING_LENINT(name);
|
|
212
|
+
if (len >= NAME_MAX) {
|
|
213
|
+
goto error_too_long;
|
|
214
|
+
}
|
|
215
|
+
p->name = strndup(RSTRING_PTR(name), len);
|
|
216
|
+
if (p->name == NULL) {
|
|
217
|
+
goto error_strndup;
|
|
218
|
+
}
|
|
219
|
+
p->fd = shm_open(p->name, f, S_IRUSR | S_IWUSR);
|
|
220
|
+
if (p->fd == -1) {
|
|
221
|
+
goto error_shm_open;
|
|
222
|
+
}
|
|
223
|
+
if (ftruncate(p->fd, sizeof(struct shm_t)) == -1) {
|
|
224
|
+
goto error_ftruncate;
|
|
225
|
+
}
|
|
226
|
+
p->memory = mmap(NULL, sizeof(struct shm_t), PROT_READ | PROT_WRITE, MAP_SHARED, p->fd, 0);
|
|
227
|
+
if (p->memory == MAP_FAILED) {
|
|
228
|
+
goto error_mmap;
|
|
229
|
+
}
|
|
230
|
+
close(p->fd);
|
|
231
|
+
if (p->is_owner) {
|
|
232
|
+
p->memory->size = 0;
|
|
233
|
+
if (sem_init(&p->memory->sem, 1, 1) == -1) {
|
|
234
|
+
goto error_sem_init;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
p->status = OPENED;
|
|
238
|
+
return self;
|
|
239
|
+
if (0) {
|
|
240
|
+
error_sem_init:
|
|
241
|
+
rb_raise(rb_eSystemCallError, "%s: %s", "failed to init semaphore", strerror(errno));
|
|
242
|
+
}
|
|
243
|
+
munmap(p->memory, sizeof(struct shm_t));
|
|
244
|
+
if (0) {
|
|
245
|
+
error_mmap:
|
|
246
|
+
rb_raise(rb_eSystemCallError, "%s: %s", "failed to mmap", strerror(errno));
|
|
247
|
+
}
|
|
248
|
+
if (0) {
|
|
249
|
+
error_ftruncate:
|
|
250
|
+
rb_raise(rb_eSystemCallError, "%s: %s", "failed to truncate", strerror(errno));
|
|
251
|
+
}
|
|
252
|
+
if (p->is_owner) {
|
|
253
|
+
shm_unlink(p->name);
|
|
254
|
+
}
|
|
255
|
+
if (0) {
|
|
256
|
+
error_shm_open:
|
|
257
|
+
rb_raise(rb_eSystemCallError, "%s: %s", "failed to shm_open", strerror(errno));
|
|
258
|
+
}
|
|
259
|
+
free(p->name);
|
|
260
|
+
if (0) {
|
|
261
|
+
error_strndup:
|
|
262
|
+
rb_raise(rb_eSystemCallError, "%s: %s", "failed to strndup", strerror(errno));
|
|
263
|
+
}
|
|
264
|
+
if (0) {
|
|
265
|
+
error_too_long:
|
|
266
|
+
rb_raise(rb_eArgError, "name is too long");
|
|
267
|
+
}
|
|
268
|
+
p->status = ERR;
|
|
269
|
+
return self;
|
|
270
|
+
#endif // WIN32
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
static VALUE ninix_fmo_read(VALUE self) {
|
|
274
|
+
struct ninix_fmo *p;
|
|
275
|
+
Data_Get_Struct(self, struct ninix_fmo, p);
|
|
276
|
+
if (p->status <= CLOSED) {
|
|
277
|
+
return Qfalse;
|
|
278
|
+
}
|
|
279
|
+
#ifdef WIN32
|
|
280
|
+
if (WaitForSingleObject(p->mutex, INFINITE) != WAIT_OBJECT_0) {
|
|
281
|
+
goto error_mutex;
|
|
282
|
+
}
|
|
283
|
+
VALUE ret = rb_str_new(p->memory->buf, p->memory->size);
|
|
284
|
+
ReleaseMutex(p->mutex);
|
|
285
|
+
return ret;
|
|
286
|
+
error_mutex:
|
|
287
|
+
CloseHandle(p->mutex);
|
|
288
|
+
UnmapViewOfFile(p->memory);
|
|
289
|
+
CloseHandle(p->fmo);
|
|
290
|
+
p->status = ERR;
|
|
291
|
+
rb_raise(rb_eSystemCallError, "failed to wait/release mutex");
|
|
292
|
+
return Qfalse;
|
|
293
|
+
#else
|
|
294
|
+
if (sem_wait(&p->memory->sem) == -1) {
|
|
295
|
+
goto error_sem;
|
|
296
|
+
}
|
|
297
|
+
VALUE ret = rb_str_new(p->memory->buf, p->memory->size);
|
|
298
|
+
if (sem_post(&p->memory->sem) == -1) {
|
|
299
|
+
goto error_sem;
|
|
300
|
+
}
|
|
301
|
+
return ret;
|
|
302
|
+
error_sem:
|
|
303
|
+
if (p->is_owner) {
|
|
304
|
+
sem_destroy(&p->memory->sem);
|
|
305
|
+
munmap(p->memory, sizeof(struct shm_t));
|
|
306
|
+
shm_unlink(p->name);
|
|
307
|
+
}
|
|
308
|
+
p->status = ERR;
|
|
309
|
+
rb_raise(rb_eSystemCallError, "%s: %s", "failed to wait/post semaphore", strerror(errno));
|
|
310
|
+
return Qfalse;
|
|
311
|
+
#endif // WIN32
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
static VALUE ninix_fmo_write(VALUE self, VALUE data) {
|
|
315
|
+
struct ninix_fmo *p;
|
|
316
|
+
Check_Type(data, T_STRING);
|
|
317
|
+
Data_Get_Struct(self, struct ninix_fmo, p);
|
|
318
|
+
if (p->status <= CLOSED) {
|
|
319
|
+
return Qfalse;
|
|
320
|
+
}
|
|
321
|
+
char *d = RSTRING_PTR(data);
|
|
322
|
+
#ifdef WIN32
|
|
323
|
+
if (RSTRING_LEN(data) >= MAX_PATH) {
|
|
324
|
+
rb_raise(rb_eArgError, "data is too long");
|
|
325
|
+
return Qfalse;
|
|
326
|
+
}
|
|
327
|
+
if (WaitForSingleObject(p->mutex, INFINITE) != WAIT_OBJECT_0) {
|
|
328
|
+
goto error_mutex;
|
|
329
|
+
}
|
|
330
|
+
p->memory->size = RSTRING_LEN(data);
|
|
331
|
+
memcpy(p->memory->buf, d, p->memory->size);
|
|
332
|
+
p->memory->buf[p->memory->size] = '\0';
|
|
333
|
+
if (ReleaseMutex(p->mutex) == FALSE) {
|
|
334
|
+
goto error_mutex;
|
|
335
|
+
}
|
|
336
|
+
return Qtrue;
|
|
337
|
+
error_mutex:
|
|
338
|
+
CloseHandle(p->mutex);
|
|
339
|
+
UnmapViewOfFile(p->memory);
|
|
340
|
+
CloseHandle(p->fmo);
|
|
341
|
+
p->status = ERR;
|
|
342
|
+
rb_raise(rb_eSystemCallError, "failed to wait/release mutex");
|
|
343
|
+
return Qfalse;
|
|
344
|
+
#else
|
|
345
|
+
if (RSTRING_LEN(data) >= PATH_MAX) {
|
|
346
|
+
rb_raise(rb_eArgError, "data is too long");
|
|
347
|
+
return Qfalse;
|
|
348
|
+
}
|
|
349
|
+
if (sem_wait(&p->memory->sem) == -1) {
|
|
350
|
+
goto error_sem;
|
|
351
|
+
}
|
|
352
|
+
p->memory->size = RSTRING_LEN(data);
|
|
353
|
+
memcpy(p->memory->buf, d, p->memory->size);
|
|
354
|
+
p->memory->buf[p->memory->size] = '\0';
|
|
355
|
+
if (sem_post(&p->memory->sem) == -1) {
|
|
356
|
+
goto error_sem;
|
|
357
|
+
}
|
|
358
|
+
return Qtrue;
|
|
359
|
+
error_sem:
|
|
360
|
+
sem_destroy(&p->memory->sem);
|
|
361
|
+
munmap(p->memory, sizeof(struct shm_t));
|
|
362
|
+
shm_unlink(p->name);
|
|
363
|
+
p->status = ERR;
|
|
364
|
+
rb_raise(rb_eSystemCallError, "%s: %s", "failed to wait/post semaphore", strerror(errno));
|
|
365
|
+
return Qfalse;
|
|
366
|
+
#endif // WIN32
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
static VALUE ninix_fmo_close(VALUE self) {
|
|
370
|
+
struct ninix_fmo *p;
|
|
371
|
+
Data_Get_Struct(self, struct ninix_fmo, p);
|
|
372
|
+
ninix_fmo_free(p);
|
|
373
|
+
return Qtrue;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
void Init_ninix_fmo() {
|
|
377
|
+
VALUE mNinixFMO = rb_define_module("NinixFMO");
|
|
378
|
+
VALUE cNinixFMO = rb_define_class_under(mNinixFMO, "NinixFMO", rb_cObject);
|
|
379
|
+
|
|
380
|
+
rb_define_alloc_func(cNinixFMO, ninix_fmo_alloc);
|
|
381
|
+
rb_define_method(cNinixFMO, "initialize", ninix_fmo_init, 2);
|
|
382
|
+
rb_define_method(cNinixFMO, "read", ninix_fmo_read, 0);
|
|
383
|
+
rb_define_method(cNinixFMO, "write", ninix_fmo_write, 1);
|
|
384
|
+
rb_define_method(cNinixFMO, "close", ninix_fmo_close, 0);
|
|
385
|
+
}
|
data/lib/ninix-fmo.rb
ADDED
data/ninix-fmo.gemspec
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
Gem::Specification.new do |spec|
|
|
4
|
+
spec.name = "ninix-fmo"
|
|
5
|
+
spec.version = "1.0.3"
|
|
6
|
+
spec.authors = ["Tatakinov"]
|
|
7
|
+
spec.email = ["tatakinov@gmail.com"]
|
|
8
|
+
|
|
9
|
+
spec.summary = "A gem for using FileMappingObject in ninix-kagari."
|
|
10
|
+
spec.homepage = "https://tatakinov.github.io/"
|
|
11
|
+
spec.license = "MIT"
|
|
12
|
+
spec.required_ruby_version = ">= 3.1.0"
|
|
13
|
+
|
|
14
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
15
|
+
spec.metadata["source_code_uri"] = "https://github.com/Tatakinov/ninix-fmo"
|
|
16
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
|
17
|
+
|
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
20
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
21
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
|
22
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features|utils)/|\.(?:git|travis|circleci)|appveyor|debian)})
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
spec.bindir = "exe"
|
|
26
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
27
|
+
spec.require_paths = ["lib"]
|
|
28
|
+
spec.extensions = %w{ext/ninix-fmo/extconf.rb}
|
|
29
|
+
|
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
|
31
|
+
spec.add_development_dependency "rake"
|
|
32
|
+
spec.add_development_dependency "rake-compiler"
|
|
33
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: ninix-fmo
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.3
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Tatakinov
|
|
8
|
+
bindir: exe
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: bundler
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '1.5'
|
|
19
|
+
type: :development
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - "~>"
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '1.5'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: rake
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
type: :development
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '0'
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: rake-compiler
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '0'
|
|
47
|
+
type: :development
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '0'
|
|
54
|
+
email:
|
|
55
|
+
- tatakinov@gmail.com
|
|
56
|
+
executables: []
|
|
57
|
+
extensions:
|
|
58
|
+
- ext/ninix-fmo/extconf.rb
|
|
59
|
+
extra_rdoc_files: []
|
|
60
|
+
files:
|
|
61
|
+
- Gemfile
|
|
62
|
+
- LICENSE.txt
|
|
63
|
+
- README.md
|
|
64
|
+
- Rakefile
|
|
65
|
+
- ext/ninix-fmo/extconf.rb
|
|
66
|
+
- ext/ninix-fmo/ninix-fmo.c
|
|
67
|
+
- lib/ninix-fmo.rb
|
|
68
|
+
- lib/ninix-fmo/version.rb
|
|
69
|
+
- ninix-fmo.gemspec
|
|
70
|
+
homepage: https://tatakinov.github.io/
|
|
71
|
+
licenses:
|
|
72
|
+
- MIT
|
|
73
|
+
metadata:
|
|
74
|
+
homepage_uri: https://tatakinov.github.io/
|
|
75
|
+
source_code_uri: https://github.com/Tatakinov/ninix-fmo
|
|
76
|
+
allowed_push_host: https://rubygems.org
|
|
77
|
+
rdoc_options: []
|
|
78
|
+
require_paths:
|
|
79
|
+
- lib
|
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
81
|
+
requirements:
|
|
82
|
+
- - ">="
|
|
83
|
+
- !ruby/object:Gem::Version
|
|
84
|
+
version: 3.1.0
|
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - ">="
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0'
|
|
90
|
+
requirements: []
|
|
91
|
+
rubygems_version: 3.6.7
|
|
92
|
+
specification_version: 4
|
|
93
|
+
summary: A gem for using FileMappingObject in ninix-kagari.
|
|
94
|
+
test_files: []
|