noderb 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,6 +9,7 @@
9
9
  //#include <noderb_defer.h>
10
10
  #include <noderb_fs.h>
11
11
 
12
+ #include <signal.h>
12
13
  // Core NodeRb module
13
14
  VALUE nodeRb;
14
15
  // Pointer for saving native data
@@ -24,7 +25,14 @@ VALUE nodeRb_get_nodeRb_pointer(){
24
25
  return nodeRbPointer;
25
26
  }
26
27
 
28
+ void siginthandler(int param)
29
+ {
30
+ rb_funcall(nodeRb, rb_intern("kill"), 0, 0);
31
+ }
32
+
27
33
  void Init_noderb_extension() {
34
+ // Exits
35
+ signal(SIGINT, siginthandler);
28
36
  // Define module
29
37
  nodeRb = rb_define_module("NodeRb");
30
38
  // Define native pointer
@@ -33,11 +41,11 @@ void Init_noderb_extension() {
33
41
  VALUE nodeRbConnection = rb_define_module_under(nodeRb, "Connection");
34
42
  VALUE nodeRbProcess = rb_define_module_under(nodeRb, "Process");
35
43
  // Define connection methods
36
- rb_define_method(nodeRbConnection, "write_data", nodeRb_tcp_send_data, 1);
37
- rb_define_method(nodeRbConnection, "close_connection", nodeRb_tcp_close_connection, 0);
44
+ rb_define_method(nodeRbConnection, "connection_write", nodeRb_tcp_send_data, 1);
45
+ rb_define_method(nodeRbConnection, "connection_close", nodeRb_tcp_close_connection, 0);
38
46
  // Define process methods
39
- rb_define_method(nodeRbProcess, "write_data", nodeRb_process_write, 1);
40
- rb_define_method(nodeRbProcess, "kill_process", nodeRb_process_kill, 1);
47
+ rb_define_method(nodeRbProcess, "process_write", nodeRb_process_write, 1);
48
+ rb_define_method(nodeRbProcess, "process_kill", nodeRb_process_kill, 1);
41
49
  // Define utility methods
42
50
  rb_define_singleton_method(nodeRb, "next_tick_native", nodeRb_nextTick, 0);
43
51
  rb_define_singleton_method(nodeRb, "start_proxy", nodeRb_startProxy, 2);
@@ -33,4 +33,5 @@ VALUE nodeRb_dns_resolve(VALUE self, VALUE host, VALUE callback){
33
33
  handle->data = data;
34
34
  // Resolve
35
35
  uv_getaddrinfo(uv_default_loop(), handle, nodeRb_dns_resolved, rb_string_value_cstr(&host), NULL, NULL);
36
+ return self;
36
37
  }
@@ -118,6 +118,7 @@ VALUE nodeRb_fs_operation(VALUE self, VALUE roperation, VALUE path, VALUE params
118
118
  uv_fs_chown(uv_default_loop(), handle, rb_string_value_cstr(&path), (int) rb_num2long(rb_ary_entry(params, 0)), (int) rb_num2long(rb_ary_entry(params, 1)), nodeRb_fs_operation_callback);
119
119
  break;
120
120
  }
121
+ return self;
121
122
  }
122
123
 
123
124
  void nodeRb_fs_file_operation_callback(uv_fs_t* handle){
@@ -125,32 +126,32 @@ void nodeRb_fs_file_operation_callback(uv_fs_t* handle){
125
126
  nodeRb_file_handle* data = (nodeRb_file_handle*) handle->data;
126
127
  VALUE target = data->target;
127
128
  if(handle->result == -1){
128
- rb_funcall(target, rb_intern("on_error"), 0, 0);
129
+ rb_funcall(target, rb_intern("on_file_error"), 0, 0);
129
130
  }else{
130
131
  switch(handle->fs_type) {
131
132
  case UV_FS_SENDFILE:
132
- rb_funcall(target, rb_intern("on_sendfile"), 0, 0);
133
+ rb_funcall(target, rb_intern("on_file_sendfile"), 0, 0);
133
134
  break;
134
135
  case UV_FS_FTRUNCATE:
135
- rb_funcall(target, rb_intern("on_truncate"), 0, 0);
136
+ rb_funcall(target, rb_intern("on_file_truncate"), 0, 0);
136
137
  break;
137
138
  case UV_FS_FUTIME:
138
- rb_funcall(target, rb_intern("on_utime"), 0, 0);
139
+ rb_funcall(target, rb_intern("on_file_utime"), 0, 0);
139
140
  break;
140
141
  case UV_FS_FCHMOD:
141
- rb_funcall(target, rb_intern("on_chmod"), 0, 0);
142
+ rb_funcall(target, rb_intern("on_file_chmod"), 0, 0);
142
143
  break;
143
144
  case UV_FS_FSYNC:
144
- rb_funcall(target, rb_intern("on_sync"), 0, 0);
145
+ rb_funcall(target, rb_intern("on_file_sync"), 0, 0);
145
146
  break;
146
147
  case UV_FS_FDATASYNC:
147
- rb_funcall(target, rb_intern("on_datasync"), 0, 0);
148
+ rb_funcall(target, rb_intern("on_file_datasync"), 0, 0);
148
149
  break;
149
150
  case UV_FS_FCHOWN:
150
- rb_funcall(target, rb_intern("on_chown"), 0, 0);
151
+ rb_funcall(target, rb_intern("on_file_chown"), 0, 0);
151
152
  break;
152
153
  case UV_FS_WRITE:
153
- rb_funcall(target, rb_intern("on_write"), 0, 0);
154
+ rb_funcall(target, rb_intern("on_file_write"), 0, 0);
154
155
  break;
155
156
  case UV_FS_FSTAT:
156
157
  {
@@ -173,26 +174,26 @@ void nodeRb_fs_file_operation_callback(uv_fs_t* handle){
173
174
  rb_iv_set(values, "@modified", LONG2NUM(stats->st_mtime));
174
175
  rb_iv_set(values, "@changed", LONG2NUM(stats->st_ctime));
175
176
 
176
- rb_funcall(target, rb_intern("on_stat"), 1, values);
177
+ rb_funcall(target, rb_intern("on_file_stat"), 1, values);
177
178
  }
178
179
  break;
179
180
  case UV_FS_OPEN:
180
181
  {
181
182
  uv_file fd = (uv_file) handle->result;
182
183
  rb_iv_set(target, "@_handle", INT2NUM(fd)); //INT2NUM(fd)
183
- rb_funcall(target, rb_intern("on_open"), 0, 0);
184
+ rb_funcall(target, rb_intern("on_file_open"), 0, 0);
184
185
  }
185
186
  break;
186
187
  case UV_FS_READ:
187
188
  {
188
189
  int size = (int) handle->result;
189
190
  char* buf = data->buffer;
190
- rb_funcall(target, rb_intern("on_read"), 1, rb_str_new(buf, size));
191
+ rb_funcall(target, rb_intern("on_file_read"), 1, rb_str_new(buf, size));
191
192
  free(buf);
192
193
  }
193
194
  break;
194
195
  case UV_FS_CLOSE:
195
- rb_funcall(target, rb_intern("on_close"), 0, 0);
196
+ rb_funcall(target, rb_intern("on_file_close"), 0, 0);
196
197
  nodeRb_unregister_instance(target);
197
198
  rb_iv_set(target, "@_handle", Qnil);
198
199
  break;
@@ -274,4 +275,5 @@ VALUE nodeRb_fs_file_operation(VALUE self, VALUE roperation, VALUE params){
274
275
  uv_fs_close(uv_default_loop(), handle, fd, nodeRb_fs_file_operation_callback);
275
276
  break;
276
277
  }
278
+ return self;
277
279
  }
@@ -35,18 +35,20 @@ VALUE nodeRb_process_write(VALUE self, VALUE data) {
35
35
  nodeRb_process_handle* process_handle = (nodeRb_process_handle*) handle->data;
36
36
  // Write data to stream
37
37
  nodeRb_write((uv_stream_t*) process_handle->stdi, buffer, sizeof(buffer));
38
+ return self;
38
39
  }
39
40
 
40
41
  VALUE nodeRb_process_kill(VALUE self, VALUE signal) {
41
42
  uv_process_t *handle;
42
43
  Data_Get_Struct(rb_iv_get(self, "@_handle"), uv_process_t, handle);
43
44
  uv_process_kill(handle, (int) rb_num2int(signal));
45
+ return self;
44
46
  }
45
47
 
46
48
  void nodeRb_process_exit(uv_process_t* handle, int status, int signal) {
47
49
  nodeRb_process_handle* process_handle = (nodeRb_process_handle*) handle->data;
48
50
  VALUE clazz = nodeRb_get_class_from_id(process_handle->target);
49
- rb_funcall(clazz, rb_intern("on_exit"), 2, rb_int2inum(status), rb_int2inum(signal));
51
+ rb_funcall(clazz, rb_intern("on_process_close"), 2, rb_int2inum(status), rb_int2inum(signal));
50
52
  }
51
53
 
52
54
  VALUE nodeRb_startProcess(VALUE self, VALUE executable, VALUE arguments, VALUE environment, VALUE directory, VALUE clazz) {
@@ -99,7 +101,7 @@ VALUE nodeRb_startProcess(VALUE self, VALUE executable, VALUE arguments, VALUE e
99
101
  options.stdout_stream = stdo;
100
102
  nodeRb_process_read_handle* stdout_handle = malloc(sizeof(nodeRb_process_read_handle));
101
103
  stdout_handle->target = process_handle->target;
102
- stdout_handle->target_callback = (char*) "on_stdout";
104
+ stdout_handle->target_callback = (char*) "on_process_stdout";
103
105
  stdo->data = stdout_handle;
104
106
  process_handle->stdo = stdo;
105
107
  // stderr
@@ -108,7 +110,7 @@ VALUE nodeRb_startProcess(VALUE self, VALUE executable, VALUE arguments, VALUE e
108
110
  options.stderr_stream = stde;
109
111
  nodeRb_process_read_handle* stderr_handle = malloc(sizeof(nodeRb_process_read_handle));
110
112
  stderr_handle->target = process_handle->target;
111
- stderr_handle->target_callback = (char*) "on_stderr";
113
+ stderr_handle->target_callback = (char*) "on_process_stderr";
112
114
  stde->data = stderr_handle;
113
115
  process_handle->stde = stde;
114
116
  // libuv handle
@@ -122,5 +124,6 @@ VALUE nodeRb_startProcess(VALUE self, VALUE executable, VALUE arguments, VALUE e
122
124
  uv_read_start((uv_stream_t*) stdo, nodeRb_read_alloc, nodeRb_read);
123
125
  uv_read_start((uv_stream_t*) stde, nodeRb_read_alloc, nodeRb_read);
124
126
  // call back ruby
125
- rb_funcall(clazz, rb_intern("on_start"), 0);
127
+ rb_funcall(clazz, rb_intern("on_process_open"), 0);
128
+ return self;
126
129
  };
@@ -17,7 +17,7 @@ void nodeRb_tcp_on_close(uv_handle_t* client) {
17
17
  nodeRb_client *client_data = client->data;
18
18
  VALUE object = nodeRb_get_class_from_id(client_data->target);
19
19
  // Call callback for connection close
20
- rb_funcall(object, rb_intern("on_close"), 0, 0);
20
+ rb_funcall(object, rb_intern("on_connection_close"), 0, 0);
21
21
  // Allow GC of handler instance
22
22
  nodeRb_unregister_instance(object);
23
23
  rb_iv_set(object, "@_handle", Qnil);
@@ -42,6 +42,7 @@ VALUE nodeRb_tcp_close_connection(VALUE self) {
42
42
  Data_Get_Struct(rhandler, uv_stream_t, handle);
43
43
  // Request shutdown of stream
44
44
  uv_shutdown(req, handle, nodeRb_tcp_on_shutdown);
45
+ return self;
45
46
  }
46
47
 
47
48
  VALUE nodeRb_tcp_send_data(VALUE self, VALUE data) {
@@ -50,6 +51,7 @@ VALUE nodeRb_tcp_send_data(VALUE self, VALUE data) {
50
51
  Data_Get_Struct(rb_iv_get(self, "@_handle"), uv_stream_t, handle);
51
52
  // Request write to stream
52
53
  nodeRb_write(handle, rb_string_value_ptr(&data), RSTRING_LEN(data));
54
+ return self;
53
55
  }
54
56
 
55
57
  /*
@@ -61,7 +63,7 @@ void nodeRb_tcp_on_client_connect(uv_connect_t* client, int status) {
61
63
  VALUE obj = nodeRb_get_class_from_id(client_data->target);
62
64
  rb_iv_set(obj, "@_handle", Data_Wrap_Struct(nodeRb_get_nodeRb_pointer(), 0, NULL, client->handle));
63
65
  rb_iv_set(obj, "@_proxy_target", Data_Wrap_Struct(nodeRb_get_nodeRb_pointer(), 0, NULL, client->handle));
64
- rb_funcall(obj, rb_intern("on_connect"), 0, 0);
66
+ rb_funcall(obj, rb_intern("on_connection_open"), 0, 0);
65
67
  uv_read_start((uv_stream_t*) client->handle, nodeRb_read_alloc, nodeRb_read);
66
68
  }
67
69
 
@@ -75,11 +77,12 @@ VALUE nodeRb_tcp_startClient(VALUE self, VALUE address, VALUE port, VALUE clazz)
75
77
  // Save client data
76
78
  nodeRb_client *client_data = malloc(sizeof (nodeRb_client));
77
79
  client_data->target = rb_num2long(rb_obj_id(clazz));
78
- client_data->target_callback = (char*) "on_data";
80
+ client_data->target_callback = (char*) "on_connection_read";
79
81
  handle->data = client_data;
80
82
  // Open socket
81
83
  int r = uv_tcp_connect(connect, handle, socket, nodeRb_tcp_on_client_connect);
82
84
  if (nodeRb_handle_error(r)) return Qnil;
85
+ return self;
83
86
  };
84
87
 
85
88
  /*
@@ -105,10 +108,10 @@ void nodeRb_tcp_on_server_connect(uv_stream_t* server, int status) {
105
108
  rb_iv_set(obj, "@_proxy_target", Data_Wrap_Struct(nodeRb_get_nodeRb_pointer(), 0, NULL, client));
106
109
  // Get object id of handler instance
107
110
  client_data->target = rb_num2long(rb_obj_id(obj));
108
- client_data->target_callback = (char*) "on_data";
111
+ client_data->target_callback = (char*) "on_connection_read";
109
112
  client->data = client_data;
110
113
  // Call callback
111
- rb_funcall(obj, rb_intern("on_connect"), 0, 0);
114
+ rb_funcall(obj, rb_intern("on_connection_open"), 0, 0);
112
115
  // Listen for incoming data
113
116
  uv_read_start(client, nodeRb_read_alloc, nodeRb_read);
114
117
  }
@@ -128,4 +131,5 @@ VALUE nodeRb_tcp_startServer(VALUE self, VALUE address, VALUE port, VALUE clazz)
128
131
  // Save information for server
129
132
  VALUE name = rb_class_name(clazz);
130
133
  server->data = rb_string_value_cstr(&name);
134
+ return self;
131
135
  };
@@ -35,6 +35,7 @@ VALUE nodeRb_timers_stop(VALUE self){
35
35
  uv_timer_stop(handle);
36
36
  // Let the GC work
37
37
  nodeRb_unregister_instance(self);
38
+ return self;
38
39
  }
39
40
 
40
41
  VALUE nodeRb_timers_once(VALUE self, VALUE timeout, VALUE repeat, VALUE handler){
@@ -55,4 +56,5 @@ VALUE nodeRb_timers_once(VALUE self, VALUE timeout, VALUE repeat, VALUE handler)
55
56
  rb_iv_set(handler, "@_handle", Data_Wrap_Struct(nodeRb_get_nodeRb_pointer(), 0, NULL, handle));
56
57
  // Schedule
57
58
  uv_timer_start(handle, nodeRb_timers_callback, rb_num2long(timeout), rb_num2long(repeat));
59
+ return self;
58
60
  }
@@ -74,6 +74,7 @@ VALUE nodeRb_startProxy(VALUE self, VALUE source, VALUE target){
74
74
  // Enable proxy
75
75
  data->proxy_enabled = 1;
76
76
  data->proxy_target = target_handle;
77
+ return self;
77
78
  }
78
79
 
79
80
  VALUE nodeRb_stopProxy(VALUE self, VALUE source){
@@ -84,6 +85,7 @@ VALUE nodeRb_stopProxy(VALUE self, VALUE source){
84
85
  nodeRb_basic_handle* data = (nodeRb_basic_handle*) source_handle->data;
85
86
  // Disable proxy
86
87
  data->proxy_enabled = 0;
88
+ return self;
87
89
  }
88
90
 
89
91
  /*
@@ -109,6 +111,7 @@ VALUE nodeRb_nextTick(VALUE self) {
109
111
  nodeRbNextTickStatus = 1;
110
112
  uv_idle_start(handle, nodeRb_next_tick);
111
113
  }
114
+ return self;
112
115
  }
113
116
 
114
117
  /*
@@ -118,21 +121,25 @@ VALUE nodeRb_nextTick(VALUE self) {
118
121
  // Register object to be GC safe
119
122
  VALUE nodeRb_register_instance(VALUE instance) {
120
123
  rb_ary_push(rb_iv_get(nodeRb_get_nodeRb_module(), "@instances"), instance);
124
+ return instance;
121
125
  }
122
126
 
123
127
  // Ruby wrapper for previous function
124
128
  VALUE nodeRb_registerInstance(VALUE self, VALUE instance) {
125
129
  nodeRb_register_instance(instance);
130
+ return self;
126
131
  }
127
132
 
128
133
  // Unregister object to be GC safe
129
134
  VALUE nodeRb_unregister_instance(VALUE instance) {
130
135
  rb_ary_delete(rb_iv_get(nodeRb_get_nodeRb_module(), "@instances"), instance);
136
+ return instance;
131
137
  }
132
138
 
133
139
  // Ruby wrapper for previous function
134
140
  VALUE nodeRb_unregisterInstance(VALUE self, VALUE instance) {
135
141
  nodeRb_unregister_instance(instance);
142
+ return self;
136
143
  }
137
144
 
138
145
  // Transforms Ruby Object.object_id back into the Object
@@ -158,4 +165,5 @@ VALUE nodeRb_start(VALUE self) {
158
165
  rb_yield(Qnil);
159
166
  }
160
167
  uv_run(uv_default_loop());
168
+ return self;
161
169
  };
data/lib/noderb.rb CHANGED
@@ -17,4 +17,6 @@ require "noderb/file"
17
17
  require "noderb/fs"
18
18
  # Helpers
19
19
  require "noderb/connection"
20
- require "noderb/process"
20
+ require "noderb/process"
21
+ # Tools
22
+ require "noderb/tools"
@@ -1,13 +1,13 @@
1
1
  module NodeRb
2
2
  module Connection
3
3
 
4
- def on_connect
4
+ def on_connection_open
5
5
  end
6
6
 
7
- def on_data data
7
+ def on_connection_read(data)
8
8
  end
9
9
 
10
- def on_close
10
+ def on_connection_close
11
11
  end
12
12
 
13
13
  end
data/lib/noderb/file.rb CHANGED
@@ -1,119 +1,119 @@
1
1
  module NodeRb
2
2
 
3
- module File
3
+ module File
4
4
 
5
- # Operations
5
+ # Operations
6
6
 
7
- def open file, flags = "r", mode = 600
8
- flags = case flags
9
- when "r"
10
- 1
11
- when "w"
12
- 2
13
- else
14
- 0
15
- end
16
- operation_native(0, [file, flags, mode])
17
- end
7
+ def file_open(file, flags = "r", mode = 600)
8
+ flags = case flags
9
+ when "r"
10
+ 1
11
+ when "w"
12
+ 2
13
+ else
14
+ 0
15
+ end
16
+ operation_native(0, [file, flags, mode])
17
+ end
18
18
 
19
- def read size = 1024, offset = 0
20
- operation_native(1, [size, offset])
21
- end
19
+ def file_read(size = 1024, offset = 0)
20
+ operation_native(1, [size, offset])
21
+ end
22
22
 
23
- def write data
24
- operation_native(2, data)
25
- end
23
+ def file_write(data)
24
+ operation_native(2, data)
25
+ end
26
26
 
27
- def stat
28
- operation_native(3, nil)
29
- end
27
+ def file_stat
28
+ operation_native(3, nil)
29
+ end
30
30
 
31
- def sync
32
- operation_native(4, nil)
33
- end
31
+ def file_sync
32
+ operation_native(4, nil)
33
+ end
34
34
 
35
- def datasync
36
- operation_native(5, nil)
37
- end
35
+ def file_datasync
36
+ operation_native(5, nil)
37
+ end
38
38
 
39
- def truncate offset = 0
40
- operation_native(6, offset)
41
- end
39
+ def file_truncate(offset = 0)
40
+ operation_native(6, offset)
41
+ end
42
42
 
43
- def sendfile output, offset = 0, length = 1024
44
- operation_native(7, [output, offset, length])
45
- end
43
+ def file_sendfile(output, offset = 0, length = 1024)
44
+ operation_native(7, [output, offset, length])
45
+ end
46
46
 
47
- def utime atime, mtime
48
- operation_native(8, [atime, mtime])
49
- end
47
+ def file_utime(atime, mtime)
48
+ operation_native(8, [atime, mtime])
49
+ end
50
50
 
51
- def chmod mode
52
- operation_native(9, mode)
53
- end
51
+ def file_chmod(mode)
52
+ operation_native(9, mode)
53
+ end
54
54
 
55
- def chown uid, gid
56
- operation_native(10, [uid, gid])
57
- end
55
+ def file_chown(uid, gid)
56
+ operation_native(10, [uid, gid])
57
+ end
58
58
 
59
- def close
60
- operation_native(11, nil)
61
- end
59
+ def file_close
60
+ operation_native(11, nil)
61
+ end
62
62
 
63
- # Callbacks
63
+ # Callbacks
64
64
 
65
- def on_open
65
+ def on_file_open
66
66
 
67
- end
67
+ end
68
68
 
69
- def on_read data
69
+ def on_file_read(data)
70
70
 
71
- end
71
+ end
72
72
 
73
- def on_write
73
+ def on_file_write
74
74
 
75
- end
75
+ end
76
76
 
77
- def on_stat
78
-
79
- end
77
+ def on_file_stat
80
78
 
81
- def on_sync
82
-
83
- end
79
+ end
84
80
 
85
- def on_datasync
86
-
87
- end
81
+ def on_file_sync
88
82
 
89
- def on_truncate
90
-
91
- end
83
+ end
92
84
 
93
- def on_sendfile
94
-
95
- end
85
+ def on_file_datasync
96
86
 
97
- def on_utime
87
+ end
98
88
 
99
- end
89
+ def on_file_truncate
100
90
 
101
- def on_chmod
102
-
103
- end
91
+ end
104
92
 
105
- def on_chown
106
-
107
- end
93
+ def on_file_sendfile
108
94
 
109
- def on_close
95
+ end
110
96
 
111
- end
97
+ def on_file_utime
112
98
 
113
- def on_error
114
-
115
- end
99
+ end
116
100
 
117
- end
101
+ def on_file_chmod
102
+
103
+ end
104
+
105
+ def on_file_chown
106
+
107
+ end
108
+
109
+ def on_file_close
110
+
111
+ end
112
+
113
+ def on_file_error
114
+
115
+ end
116
+
117
+ end
118
118
 
119
119
  end
data/lib/noderb/fs.rb CHANGED
@@ -1,72 +1,72 @@
1
1
  module NodeRb
2
2
 
3
- class FileSystem
3
+ class FileSystem
4
4
 
5
- class << self
5
+ class << self
6
6
 
7
- def unlink path, &block
8
- fs_native(0, path, nil, block)
9
- end
7
+ def unlink path, &block
8
+ fs_native(0, path, nil, block)
9
+ end
10
10
 
11
- def mkdir path, mode, &block
12
- fs_native(1, path, mode, block)
13
- end
11
+ def mkdir path, mode, &block
12
+ fs_native(1, path, mode, block)
13
+ end
14
14
 
15
- def rmdir path, &block
16
- fs_native(2, path, nil, block)
17
- end
15
+ def rmdir path, &block
16
+ fs_native(2, path, nil, block)
17
+ end
18
18
 
19
- def readdir path, flags = 2, &block
20
- parser = proc do |data|
21
- data ? block.call(data.split("\0")) : block.call(data)
22
- end
23
- fs_native(3, path, flags, parser)
24
- end
19
+ def readdir path, flags = 2, &block
20
+ parser = proc do |data|
21
+ data ? block.call(data.split("\0")) : block.call(data)
22
+ end
23
+ fs_native(3, path, flags, parser)
24
+ end
25
25
 
26
- def stat path, &block
27
- fs_native(4, path, nil, block)
28
- end
26
+ def stat path, &block
27
+ fs_native(4, path, nil, block)
28
+ end
29
29
 
30
- def rename path, new_path, &block
31
- fs_native(5, path, new_path, block)
32
- end
30
+ def rename path, new_path, &block
31
+ fs_native(5, path, new_path, block)
32
+ end
33
33
 
34
- def chmod path, mode, &block
35
- fs_native(6, path, mode, block)
36
- end
34
+ def chmod path, mode, &block
35
+ fs_native(6, path, mode, block)
36
+ end
37
37
 
38
- def utime path, atime, mtime, &block
39
- fs_native(7, path, [atime, mtime], block)
40
- end
38
+ def utime path, atime, mtime, &block
39
+ fs_native(7, path, [atime, mtime], block)
40
+ end
41
41
 
42
- def lstat path, &block
43
- fs_native(8, path, nil, block)
44
- end
42
+ def lstat path, &block
43
+ fs_native(8, path, nil, block)
44
+ end
45
45
 
46
- def link path, new_path, &block
47
- fs_native(9, path, new_path, block)
48
- end
46
+ def link path, new_path, &block
47
+ fs_native(9, path, new_path, block)
48
+ end
49
49
 
50
- def symlink path, new_path, flags, &block
51
- fs_native(10, path, [new_path, flags], block)
52
- end
50
+ def symlink path, new_path, flags, &block
51
+ fs_native(10, path, [new_path, flags], block)
52
+ end
53
53
 
54
- def readlink path, &block
55
- # ToDo: libuv not implemented yet
56
- block.call(nil)
57
- #fs_native(11, path, nil, block)
58
- end
54
+ def readlink path, &block
55
+ # ToDo: libuv not implemented yet
56
+ block.call(nil)
57
+ #fs_native(11, path, nil, block)
58
+ end
59
59
 
60
- def chown path, uid, gid, &block
61
- fs_native(12, path, [uid, gid], block)
62
- end
60
+ def chown path, uid, gid, &block
61
+ fs_native(12, path, [uid, gid], block)
62
+ end
63
63
 
64
- end
64
+ end
65
65
 
66
- end
66
+ end
67
67
 
68
- class Stat
69
-
70
- end
68
+ class Stat
69
+
70
+ end
71
71
 
72
72
  end
@@ -1,18 +1,24 @@
1
1
  module NodeRb
2
2
 
3
3
  class << self
4
-
5
- def next_tick &block
6
- ( @next_tick ||= [] ) << block
4
+
5
+ def next_tick params = nil, &block
6
+ next_tick_schedule(block, params)
7
+ end
8
+
9
+ def next_tick_schedule block, params
10
+ @next_tick ||= []
11
+ @next_tick << [block, params]
7
12
  NodeRb.send(:next_tick_native)
8
13
  end
9
-
14
+
10
15
  def next_tick_execute
11
16
  blocks, @next_tick = @next_tick, []
12
17
  blocks.each do |block|
13
- block.call
18
+ block, params = block
19
+ params ? block.call(params) : block.call
14
20
  end
15
21
  end
16
-
22
+
17
23
  end
18
24
  end
@@ -1,16 +1,16 @@
1
1
  module NodeRb
2
2
  module Process
3
3
 
4
- def on_start pid
4
+ def on_process_open
5
5
  end
6
6
 
7
- def on_stdout data
7
+ def on_process_stdout data
8
8
  end
9
9
 
10
- def on_stderr data
10
+ def on_process_stderr data
11
11
  end
12
12
 
13
- def on_exit status, signal
13
+ def on_process_close status, signal
14
14
  end
15
15
 
16
16
  end
data/lib/noderb/timers.rb CHANGED
@@ -16,7 +16,7 @@ module NodeRb
16
16
  module Timer
17
17
 
18
18
  def call
19
-
19
+
20
20
  end
21
21
 
22
22
  end
@@ -0,0 +1,10 @@
1
+ module NodeRb
2
+
3
+ def self.kill
4
+ NodeRb.next_tick do
5
+ puts "Exiting"
6
+ Kernel.exit(0)
7
+ end
8
+ end
9
+
10
+ end
@@ -1,3 +1,3 @@
1
1
  module NodeRb
2
- VERSION = "0.0.11" unless const_defined?(:VERSION)
3
- end
2
+ VERSION = "0.0.12" unless const_defined?(:VERSION)
3
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: noderb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-30 00:00:00.000000000Z
12
+ date: 2011-10-04 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description: Port of the NodeJs library to Ruby, featuring asynchronous IO operations
15
15
  of all kinds.
@@ -29,6 +29,7 @@ files:
29
29
  - lib/noderb/process.rb
30
30
  - lib/noderb/tcp.rb
31
31
  - lib/noderb/timers.rb
32
+ - lib/noderb/tools.rb
32
33
  - lib/noderb/version.rb
33
34
  - lib/noderb.rb
34
35
  - ext/noderb_extension/extconf.rb