Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 17 commits
  • 18 files changed
  • 0 comments
  • 1 contributor
18  .gitignore
... ...
@@ -1,13 +1,5 @@
1  
-# Compiled Object files
2  
-*.slo
3  
-*.lo
4  
-*.o
5  
-
6  
-# Compiled Dynamic libraries
7  
-*.so
8  
-*.exe
9  
-
10  
-# Compiled Static libraries
11  
-*.lai
12  
-*.la
13  
-*.a
  1
+gem_*
  2
+gem-*
  3
+mrb-*.a
  4
+src/*.o
  5
+.local.vimrc
6  Makefile
@@ -2,12 +2,10 @@ GEM := mruby-uv
2 2
 
3 3
 include $(MAKEFILE_4_GEM)
4 4
 
5  
-CFLAGS += -I$(MRUBY_ROOT)/include
6  
-MRUBY_CFLAGS += -I$(MRUBY_ROOT)/include
7 5
 ifeq ($(OS),Windows_NT)
8  
-MRUBY_LIBS += -luv -lws2_32 -liphlpapi -lpsapi
  6
+MRUBY_LIBS = -luv -lws2_32 -liphlpapi -lpsapi
9 7
 else
10  
-MRUBY_LIBS += -luv -lrt -lm
  8
+MRUBY_LIBS = -luv -lrt -lm
11 9
 endif
12 10
 
13 11
 GEM_C_FILES := $(wildcard $(SRC_DIR)/*.c)
2  example/async.rb
... ...
@@ -1,3 +1,5 @@
  1
+#!mruby
  2
+
1 3
 t = UV::Timer.new()
2 4
 
3 5
 a = UV::Async.new {|x|
4  example/fs.rb
@@ -2,10 +2,10 @@
2 2
 
3 3
 UV::FS::mkdir("foo-bar") do
4 4
   f = UV::FS::open("foo-bar/foo.txt", UV::FS::O_CREAT|UV::FS::O_WRONLY, UV::FS::S_IWRITE | UV::FS::S_IREAD)
5  
-  f.write("fooo") do
  5
+  f.write("helloworld") do
6 6
     f.close() do
7 7
       f = UV::FS::open("foo-bar/foo.txt", UV::FS::O_RDONLY, UV::FS::S_IREAD) do
8  
-        puts f.read(3)
  8
+        puts f.read(5)
9 9
         puts f.read()
10 10
         f.close() do
11 11
           UV::FS::unlink("foo-bar/foo.txt") do
2  example/idle.rb
... ...
@@ -1,3 +1,5 @@
  1
+#!mruby
  2
+
1 3
 i = UV::Idle.new()
2 4
 i.start {|x|
3 5
   puts "idle"
2  example/loop.rb
... ...
@@ -1,3 +1,5 @@
  1
+#!mruby
  2
+
1 3
 l = UV::Loop.new()
2 4
 t = UV::Timer.new(l)
3 5
 i = 3
4  example/pipe-client-win.rb
... ...
@@ -1,4 +1,6 @@
1  
-c = UV::Pipe.new()
  1
+#!mruby
  2
+
  3
+c = UV::Pipe.new(0)
2 4
 c.connect('\\\\.\\pipe\\mruby-uv') {|x|
3 5
   if x == 0
4 6
     c.read_start {|b|
4  example/pipe-client.rb
... ...
@@ -1,4 +1,6 @@
1  
-c = UV::Pipe.new()
  1
+#!mruby
  2
+
  3
+c = UV::Pipe.new(1)
2 4
 c.connect('/tmp/mrub-yuv') {|x|
3 5
   if x == 0
4 6
     c.read_start {|b|
4  example/pipe-server-win.rb
... ...
@@ -1,4 +1,6 @@
1  
-s = UV::Pipe.new()
  1
+#!mruby
  2
+
  3
+s = UV::Pipe.new(0)
2 4
 s.bind('\\\\.\\pipe\\mruby-uv')
3 5
 s.listen(1) {|x|
4 6
   return if x != 0
4  example/pipe-server.rb
... ...
@@ -1,4 +1,6 @@
1  
-s = UV::Pipe.new()
  1
+#!mruby
  2
+
  3
+s = UV::Pipe.new(1)
2 4
 s.bind('/tmp/mruby-uv')
3 5
 s.listen(5) {|x|
4 6
   return if x != 0
28  example/process.rb
... ...
@@ -0,0 +1,28 @@
  1
+#!mruby
  2
+
  3
+if UV::IS_WINDOWS == true
  4
+  ps = UV::Process.new({
  5
+    'file' => 'cmd',
  6
+    'args' => ['/c', 'dir /S ..']
  7
+  })
  8
+else
  9
+  ps = UV::Process.new({
  10
+    'file' => 'find',
  11
+    'args' => ['../..']
  12
+  })
  13
+end
  14
+ps.stdout_pipe = UV::Pipe.new(0)
  15
+
  16
+ps.spawn do |sig|
  17
+  puts "exit #{sig}"
  18
+end
  19
+ps.stdout_pipe.read_start do |b|
  20
+  puts b
  21
+end
  22
+
  23
+t = UV::Timer.new
  24
+t.start(1000, 0) do |x|
  25
+  ps.kill(UV::Signal::SIGINT)
  26
+end
  27
+
  28
+UV::run()
2  example/tcp-client.rb
... ...
@@ -1,3 +1,5 @@
  1
+#!mruby
  2
+
1 3
 c = UV::TCP.new()
2 4
 c.connect(UV.ip4_addr('127.0.0.1', 8888)) {|x|
3 5
   if x == 0
2  example/tcp-server.rb
... ...
@@ -1,3 +1,5 @@
  1
+#!mruby
  2
+
1 3
 s = UV::TCP.new()
2 4
 s.bind(UV::ip4_addr('127.0.0.1', 8888))
3 5
 s.listen(5) {|x|
2  example/timer.rb
... ...
@@ -1,3 +1,5 @@
  1
+#!mruby
  2
+
1 3
 t = UV::Timer.new()
2 4
 c = 3
3 5
 t.start(1000, 1000) {|x|
6  example/tty.rb
... ...
@@ -0,0 +1,6 @@
  1
+#!mruby
  2
+
  3
+tty = UV::TTY.new(1, 1)
  4
+tty.set_mode(0)
  5
+tty.reset_mode
  6
+p tty.get_winsize
2  example/udp-reader.rb
... ...
@@ -1,3 +1,5 @@
  1
+#!mruby
  2
+
1 3
 r = UV::UDP.new()
2 4
 r.bind(UV::ip4_addr('127.0.0.1', 8888))
3 5
 r.recv_start {|data, addr, flags|
2  example/udp-sender.rb
... ...
@@ -1,3 +1,5 @@
  1
+#!mruby
  2
+
1 3
 c = UV::UDP.new()
2 4
 c.send("helloworld", UV::ip4_addr('127.0.0.1', 8888)) {|x|
3 5
   c.close()
509  src/mrb_uv.c
... ...
@@ -1,3 +1,4 @@
  1
+#define _GNU_SOURCE
1 2
 #include <errno.h>
2 3
 #include <memory.h>
3 4
 #include <mruby.h>
@@ -11,6 +12,8 @@
11 12
 #include <uv.h>
12 13
 #include <stdio.h>
13 14
 #include <fcntl.h>
  15
+#include <limits.h>
  16
+#include <unistd.h>
14 17
 
15 18
 #if 1
16 19
 #define ARENA_SAVE \
@@ -49,6 +52,8 @@ typedef struct {
49 52
     uv_signal_t signal;
50 53
     uv_file fs;
51 54
     uv_fs_poll_t fs_poll;
  55
+    uv_tty_t tty;
  56
+    uv_process_t process;
52 57
   } any;
53 58
   mrb_value instance;
54 59
   uv_loop_t* loop;
@@ -70,10 +75,14 @@ static void
70 75
 uv_context_free(mrb_state *mrb, void *p)
71 76
 {
72 77
   mrb_uv_context* context = (mrb_uv_context*) p;
73  
-  OBJECT_REMOVE(mrb, context->instance, "context");
74  
-  context->instance = mrb_nil_value();
75  
-  context->mrb = NULL;
76  
-  context->loop = NULL;
  78
+  if (context) {
  79
+    OBJECT_REMOVE(mrb, context->instance, "read_cb");
  80
+    OBJECT_REMOVE(mrb, context->instance, "write_cb");
  81
+    OBJECT_REMOVE(mrb, context->instance, "context");
  82
+    context->instance = mrb_nil_value();
  83
+    context->mrb = NULL;
  84
+    context->loop = NULL;
  85
+  }
77 86
   free(p);
78 87
 }
79 88
 
@@ -81,7 +90,7 @@ static const struct mrb_data_type uv_context_type = {
81 90
   "uv_context", uv_context_free,
82 91
 };
83 92
 
84  
-static mrb_value uv_gc_hash;
  93
+static mrb_value uv_gc_table;
85 94
 static struct RClass *_class_uv;
86 95
 static struct RClass *_class_uv_loop;
87 96
 static struct RClass *_class_uv_timer;
@@ -91,12 +100,15 @@ static struct RClass *_class_uv_tcp;
91 100
 static struct RClass *_class_uv_udp;
92 101
 static struct RClass *_class_uv_pipe;
93 102
 static struct RClass *_class_uv_ip4addr;
  103
+static struct RClass *_class_uv_ip6addr;
94 104
 static struct RClass *_class_uv_addrinfo;
95 105
 static struct RClass *_class_uv_prepare;
96 106
 static struct RClass *_class_uv_mutex;
97 107
 static struct RClass *_class_uv_fs;
98 108
 static struct RClass *_class_uv_fs_poll;
99 109
 static struct RClass *_class_uv_signal;
  110
+static struct RClass *_class_uv_tty;
  111
+static struct RClass *_class_uv_process;
100 112
 
101 113
 /*********************************************************
102 114
  * main
@@ -105,18 +117,17 @@ static mrb_value
105 117
 mrb_uv_gc(mrb_state *mrb, mrb_value self)
106 118
 {
107 119
   ARENA_SAVE;
108  
-  mrb_value keys;
109  
-  keys = mrb_hash_keys(mrb, uv_gc_hash);
110  
-  int i, l = RARRAY_LEN(keys);
  120
+  int i, l = RARRAY_LEN(uv_gc_table);
111 121
   for (i = 0; i < l; i++) {
112  
-    mrb_value key = mrb_ary_entry(keys, i);
113  
-    mrb_value obj = mrb_hash_get(mrb, uv_gc_hash, key);
  122
+    mrb_value obj = mrb_ary_entry(uv_gc_table, i);
114 123
     mrb_value ctx  = mrb_iv_get(mrb, obj, mrb_intern(mrb, "context"));
115 124
     if (!mrb_nil_p(ctx)) {
116 125
       mrb_uv_context* context;
117 126
       Data_Get_Struct(mrb, ctx, &uv_context_type, context);
118  
-      if (context || context->mrb == NULL) {
119  
-        //mrb_hash_delete_key(mrb, uv_gc_hash, key);
  127
+      if (!context || context->mrb == NULL) {
  128
+        mrb_funcall(mrb, uv_gc_table, "delete_at", 1, mrb_fixnum_value(i));
  129
+        i--;
  130
+        l--;
120 131
       }
121 132
     }
122 133
   }
@@ -229,7 +240,6 @@ _uv_read_cb(uv_stream_t* stream, ssize_t nread, uv_buf_t buf)
229 240
   if (!mrb) return;
230 241
   mrb_value proc = mrb_iv_get(mrb, context->instance, mrb_intern(mrb, "read_cb"));
231 242
   if (!mrb_nil_p(proc)) {
232  
-    mrb_iv_set(mrb, context->instance, mrb_intern(mrb, "read_cb"), mrb_nil_value());
233 243
     mrb_value args[1];
234 244
     if (nread == -1) {
235 245
       args[0] = mrb_nil_value();
@@ -1073,7 +1083,7 @@ mrb_uv_addrinfo_next(mrb_state *mrb, mrb_value self)
1073 1083
 }
1074 1084
 
1075 1085
 /*********************************************************
1076  
- * UV::Ip4Addr / UV::Ip6Addr
  1086
+ * UV::Ip4Addr
1077 1087
  *********************************************************/
1078 1088
 static void
1079 1089
 uv_ip4addr_free(mrb_state *mrb, void *p)
@@ -1132,6 +1142,65 @@ mrb_uv_ip4addr_to_s(mrb_state *mrb, mrb_value self)
1132 1142
 }
1133 1143
 
1134 1144
 /*********************************************************
  1145
+ * UV::Ip6Addr
  1146
+ *********************************************************/
  1147
+static void
  1148
+uv_ip6addr_free(mrb_state *mrb, void *p)
  1149
+{
  1150
+  free(p);
  1151
+}
  1152
+
  1153
+static const struct mrb_data_type uv_ip6addr_type = {
  1154
+  "uv_ip6addr", uv_ip6addr_free,
  1155
+};
  1156
+
  1157
+static mrb_value
  1158
+mrb_uv_ip6_addr(mrb_state *mrb, mrb_value self)
  1159
+{
  1160
+  int argc;
  1161
+  mrb_value *argv;
  1162
+  mrb_get_args(mrb, "*", &argv, &argc);
  1163
+  return mrb_class_new_instance(mrb, argc, argv, _class_uv_ip6addr);
  1164
+}
  1165
+
  1166
+static mrb_value
  1167
+mrb_uv_ip6addr_init(mrb_state *mrb, mrb_value self)
  1168
+{
  1169
+  mrb_value arg_host = mrb_nil_value(), arg_port = mrb_nil_value();
  1170
+  struct sockaddr_in6 vaddr;
  1171
+  struct sockaddr_in6 *addr = NULL;
  1172
+
  1173
+  mrb_get_args(mrb, "Si", &arg_host, &arg_port);
  1174
+  if (!mrb_nil_p(arg_host) && !mrb_nil_p(arg_port)) {
  1175
+    vaddr = uv_ip6_addr((const char*) RSTRING_PTR(arg_host), mrb_fixnum(arg_port));
  1176
+    addr = (struct sockaddr_in6*) malloc(sizeof(struct sockaddr_in));
  1177
+    memcpy(addr, &vaddr, sizeof(vaddr));
  1178
+  }
  1179
+  mrb_iv_set(mrb, self, mrb_intern(mrb, "context"), mrb_obj_value(
  1180
+    Data_Wrap_Struct(mrb, mrb->object_class,
  1181
+    &uv_ip6addr_type, (void*) addr)));
  1182
+  return self;
  1183
+}
  1184
+
  1185
+static mrb_value
  1186
+mrb_uv_ip6addr_to_s(mrb_state *mrb, mrb_value self)
  1187
+{
  1188
+  mrb_value value_addr;
  1189
+  struct sockaddr_in6* addr = NULL;
  1190
+  char name[256];
  1191
+
  1192
+  value_addr = mrb_iv_get(mrb, self, mrb_intern(mrb, "context"));
  1193
+  Data_Get_Struct(mrb, value_addr, &uv_ip6addr_type, addr);
  1194
+  if (!addr) {
  1195
+    return mrb_nil_value();
  1196
+  }
  1197
+  if (uv_ip6_name(addr, name, sizeof(name)) != 0) {
  1198
+    mrb_raise(mrb, E_RUNTIME_ERROR, uv_strerror(uv_last_error(uv_default_loop())));
  1199
+  }
  1200
+  return mrb_str_new(mrb, name, strlen(name));
  1201
+}
  1202
+
  1203
+/*********************************************************
1135 1204
  * UV::TCP
1136 1205
  *********************************************************/
1137 1206
 static mrb_value
@@ -1305,7 +1374,7 @@ mrb_uv_tcp_accept(mrb_state *mrb, mrb_value self)
1305 1374
   }
1306 1375
 
1307 1376
   ARENA_SAVE;
1308  
-  mrb_hash_set(mrb, uv_gc_hash, c, c);
  1377
+  mrb_ary_push(mrb, uv_gc_table, c);
1309 1378
   ARENA_RESTORE;
1310 1379
   return c;
1311 1380
 }
@@ -1547,7 +1616,7 @@ _uv_udp_recv_cb(uv_udp_t* handle, ssize_t nread, uv_buf_t buf, struct sockaddr*
1547 1616
 {
1548 1617
   mrb_uv_context* context = (mrb_uv_context*) handle->data;
1549 1618
   mrb_state* mrb = context->mrb;
1550  
-  mrb_value proc = mrb_iv_get(mrb, context->instance, mrb_intern(mrb, "timer_cb"));
  1619
+  mrb_value proc = mrb_iv_get(mrb, context->instance, mrb_intern(mrb, "udp_recv_cb"));
1551 1620
   mrb_value args[3];
1552 1621
   ARENA_SAVE;
1553 1622
   if (nread != -1) {
@@ -1588,6 +1657,7 @@ mrb_uv_udp_recv_start(mrb_state *mrb, mrb_value self)
1588 1657
     mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid argument");
1589 1658
   }
1590 1659
 
  1660
+  mrb_get_args(mrb, "&", &b);
1591 1661
   if (mrb_nil_p(b)) {
1592 1662
     udp_recv_cb = NULL;
1593 1663
   }
@@ -1630,7 +1700,7 @@ mrb_uv_pipe_init(mrb_state *mrb, mrb_value self)
1630 1700
   uv_loop_t* loop;
1631 1701
   int ipc = 0;
1632 1702
 
1633  
-  mrb_get_args(mrb, "|oi", &arg_loop, &arg_ipc);
  1703
+  mrb_get_args(mrb, "i|o", &arg_ipc, &arg_loop);
1634 1704
   if (!mrb_nil_p(arg_loop)) {
1635 1705
     if (!strcmp(mrb_obj_classname(mrb, arg_loop), "UV::Loop")) {
1636 1706
       mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid argument");
@@ -1789,7 +1859,7 @@ mrb_uv_pipe_accept(mrb_state *mrb, mrb_value self)
1789 1859
   }
1790 1860
 
1791 1861
   ARENA_SAVE;
1792  
-  mrb_hash_set(mrb, uv_gc_hash, c, c);
  1862
+  mrb_ary_push(mrb, uv_gc_table, c);
1793 1863
   ARENA_RESTORE;
1794 1864
   return c;
1795 1865
 }
@@ -1915,7 +1985,7 @@ mrb_uv_fs_open(mrb_state *mrb, mrb_value self)
1915 1985
   }
1916 1986
 
1917 1987
   ARENA_SAVE;
1918  
-  mrb_hash_set(mrb, uv_gc_hash, c, c);
  1988
+  mrb_ary_push(mrb, uv_gc_table, c);
1919 1989
   ARENA_RESTORE;
1920 1990
   return c;
1921 1991
 }
@@ -2689,6 +2759,311 @@ mrb_uv_signal_stop(mrb_state *mrb, mrb_value self)
2689 2759
 }
2690 2760
 
2691 2761
 /*********************************************************
  2762
+ * UV::TTY
  2763
+ *********************************************************/
  2764
+static mrb_value
  2765
+mrb_uv_tty_init(mrb_state *mrb, mrb_value self)
  2766
+{
  2767
+  mrb_value arg_loop = mrb_nil_value();
  2768
+  mrb_value arg_file = mrb_fixnum_value(-1);
  2769
+  mrb_value arg_readable = mrb_fixnum_value(0);
  2770
+  mrb_value value_context;
  2771
+  mrb_uv_context* context = NULL;
  2772
+  mrb_uv_context* loop_context = NULL;
  2773
+  uv_loop_t* loop;
  2774
+
  2775
+  mrb_get_args(mrb, "ii|o", &arg_file, &arg_readable, &arg_loop);
  2776
+  if (!mrb_nil_p(arg_loop)) {
  2777
+    if (!strcmp(mrb_obj_classname(mrb, arg_loop), "UV::Loop")) {
  2778
+      mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid argument");
  2779
+      value_context = mrb_iv_get(mrb, arg_loop, mrb_intern(mrb, "context"));
  2780
+      Data_Get_Struct(mrb, value_context, &uv_context_type, loop_context);
  2781
+      if (!loop_context) {
  2782
+        mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid argument");
  2783
+      }
  2784
+      loop = loop_context->loop;
  2785
+    } else {
  2786
+      loop = uv_default_loop();
  2787
+    }
  2788
+  } else {
  2789
+    loop = uv_default_loop();
  2790
+  }
  2791
+
  2792
+  context = uv_context_alloc(mrb);
  2793
+  if (!context) {
  2794
+    mrb_raise(mrb, E_RUNTIME_ERROR, "can't alloc memory");
  2795
+  }
  2796
+  context->instance = self;
  2797
+  context->loop = loop;
  2798
+
  2799
+  if (uv_tty_init(loop, &context->any.tty, mrb_fixnum(arg_file), mrb_fixnum(arg_readable)) != 0) {
  2800
+    mrb_raise(mrb, E_RUNTIME_ERROR, uv_strerror(uv_last_error(loop)));
  2801
+  }
  2802
+  context->any.tty.data = context;
  2803
+  mrb_iv_set(mrb, self, mrb_intern(mrb, "context"), mrb_obj_value(
  2804
+    Data_Wrap_Struct(mrb, mrb->object_class,
  2805
+    &uv_context_type, (void*) context)));
  2806
+  return self;
  2807
+}
  2808
+
  2809
+static mrb_value
  2810
+mrb_uv_tty_set_mode(mrb_state *mrb, mrb_value self)
  2811
+{
  2812
+  mrb_value arg_mode;
  2813
+  mrb_value value_context;
  2814
+  mrb_uv_context* context = NULL;
  2815
+
  2816
+  mrb_get_args(mrb, "i", &arg_mode);
  2817
+
  2818
+  value_context = mrb_iv_get(mrb, self, mrb_intern(mrb, "context"));
  2819
+  Data_Get_Struct(mrb, value_context, &uv_context_type, context);
  2820
+  if (!context) {
  2821
+    mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid argument");
  2822
+  }
  2823
+
  2824
+  return mrb_fixnum_value(uv_tty_set_mode(&context->any.tty, mrb_fixnum(arg_mode)));
  2825
+}
  2826
+
  2827
+static mrb_value
  2828
+mrb_uv_tty_reset_mode(mrb_state *mrb, mrb_value self)
  2829
+{
  2830
+  uv_tty_reset_mode();
  2831
+  return mrb_nil_value();
  2832
+}
  2833
+
  2834
+static mrb_value
  2835
+mrb_uv_tty_get_winsize(mrb_state *mrb, mrb_value self)
  2836
+{
  2837
+  mrb_value value_context;
  2838
+  mrb_uv_context* context = NULL;
  2839
+
  2840
+  value_context = mrb_iv_get(mrb, self, mrb_intern(mrb, "context"));
  2841
+  Data_Get_Struct(mrb, value_context, &uv_context_type, context);
  2842
+  if (!context) {
  2843
+    mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid argument");
  2844
+  }
  2845
+
  2846
+  int width = 0, height = 0;
  2847
+  if (uv_tty_get_winsize(&context->any.tty, &width, &height) != 0) {
  2848
+    mrb_raise(mrb, E_RUNTIME_ERROR, uv_strerror(uv_last_error(context->loop)));
  2849
+  }
  2850
+  mrb_value ary = mrb_ary_new(mrb);
  2851
+  mrb_ary_push(mrb, ary, mrb_fixnum_value(width));
  2852
+  mrb_ary_push(mrb, ary, mrb_fixnum_value(height));
  2853
+  return ary;
  2854
+}
  2855
+
  2856
+/*********************************************************
  2857
+ * UV::Process
  2858
+ *********************************************************/
  2859
+static void
  2860
+_uv_exit_cb(uv_process_t* process, int exit_status, int term_signal)
  2861
+{
  2862
+  mrb_uv_context* context = (mrb_uv_context*) process->data;
  2863
+  mrb_state* mrb = context->mrb;
  2864
+  mrb_value proc = mrb_iv_get(mrb, context->instance, mrb_intern(mrb, "exit_cb"));
  2865
+  if (!mrb_nil_p(proc)) {
  2866
+     mrb_value args[2];
  2867
+     args[0] = mrb_fixnum_value(exit_status);
  2868
+     args[1] = mrb_fixnum_value(term_signal);
  2869
+     mrb_yield_argv(mrb, proc, 2, args);
  2870
+  }
  2871
+}
  2872
+
  2873
+static mrb_value
  2874
+mrb_uv_process_init(mrb_state *mrb, mrb_value self)
  2875
+{
  2876
+  mrb_value arg_opt = mrb_nil_value();
  2877
+
  2878
+  mrb_get_args(mrb, "H", &arg_opt);
  2879
+  if (mrb_nil_p(arg_opt)) mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid argument");
  2880
+  mrb_value arg_file = mrb_hash_get(mrb, arg_opt, mrb_str_new_cstr(mrb, "file"));
  2881
+  if (mrb_type(arg_file) != MRB_TT_STRING) mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid argument");
  2882
+  mrb_value arg_args = mrb_hash_get(mrb, arg_opt, mrb_str_new_cstr(mrb, "args"));
  2883
+  if (mrb_type(arg_args) != MRB_TT_ARRAY) mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid argument");
  2884
+
  2885
+  mrb_uv_context* context = uv_context_alloc(mrb);
  2886
+  if (!context) {
  2887
+    mrb_raise(mrb, E_RUNTIME_ERROR, "can't alloc memory");
  2888
+  }
  2889
+  context->instance = self;
  2890
+  context->loop = uv_default_loop();
  2891
+
  2892
+  mrb_iv_set(mrb, self, mrb_intern(mrb, "context"), mrb_obj_value(
  2893
+    Data_Wrap_Struct(mrb, mrb->object_class,
  2894
+    &uv_context_type, (void*) context)));
  2895
+
  2896
+  mrb_iv_set(mrb, self, mrb_intern(mrb, "options"), arg_opt);
  2897
+  mrb_iv_set(mrb, self, mrb_intern(mrb, "stdout_pipe"), mrb_nil_value());
  2898
+  mrb_iv_set(mrb, self, mrb_intern(mrb, "stderr_pipe"), mrb_nil_value());
  2899
+  mrb_iv_set(mrb, self, mrb_intern(mrb, "stdin_pipe"), mrb_nil_value());
  2900
+
  2901
+  return self;
  2902
+}
  2903
+
  2904
+static mrb_value
  2905
+mrb_uv_process_spawn(mrb_state *mrb, mrb_value self)
  2906
+{
  2907
+  mrb_value value_context;
  2908
+  mrb_uv_context* context = NULL;
  2909
+  mrb_value b = mrb_nil_value();
  2910
+  uv_exit_cb exit_cb = _uv_exit_cb;
  2911
+
  2912
+  value_context = mrb_iv_get(mrb, self, mrb_intern(mrb, "context"));
  2913
+  Data_Get_Struct(mrb, value_context, &uv_context_type, context);
  2914
+  if (!context) {
  2915
+    mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid argument");
  2916
+  }
  2917
+
  2918
+  mrb_value options = mrb_iv_get(mrb, self, mrb_intern(mrb, "options"));
  2919
+  mrb_value arg_file = mrb_hash_get(mrb, options, mrb_str_new_cstr(mrb, "file"));
  2920
+  mrb_value arg_args = mrb_hash_get(mrb, options, mrb_str_new_cstr(mrb, "args"));
  2921
+  mrb_value stdin_pipe = mrb_iv_get(mrb, self, mrb_intern(mrb, "stdin_pipe"));
  2922
+  mrb_value stdout_pipe = mrb_iv_get(mrb, self, mrb_intern(mrb, "stdout_pipe"));
  2923
+  mrb_value stderr_pipe = mrb_iv_get(mrb, self, mrb_intern(mrb, "stderr_pipe"));
  2924
+
  2925
+  mrb_get_args(mrb, "|&", &b);
  2926
+  if (mrb_nil_p(b)) {
  2927
+    exit_cb = NULL;
  2928
+  }
  2929
+  mrb_iv_set(mrb, self, mrb_intern(mrb, "exit_cb"), b);
  2930
+
  2931
+  char cwd[PATH_MAX] = {0};
  2932
+  uv_cwd(cwd, sizeof(cwd));
  2933
+  char** args = malloc(sizeof(char*) * (RARRAY_LEN(arg_args)+2));
  2934
+  int i;
  2935
+  args[0] = RSTRING_PTR(arg_file);
  2936
+  for (i = 0; i < RARRAY_LEN(arg_args); i++) {
  2937
+    args[i+1] = RSTRING_PTR(mrb_ary_entry(arg_args, i));
  2938
+  }
  2939
+  args[i+1] = NULL;
  2940
+
  2941
+  uv_stdio_container_t stdio[3];
  2942
+
  2943
+  if (!mrb_nil_p(stdin_pipe)) {
  2944
+    mrb_value pipe_context = mrb_iv_get(mrb, stdin_pipe, mrb_intern(mrb, "context"));
  2945
+    mrb_uv_context* pcontext = NULL;
  2946
+    Data_Get_Struct(mrb, pipe_context, &uv_context_type, pcontext);
  2947
+    if (!pcontext) {
  2948
+      mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid argument");
  2949
+    }
  2950
+    stdio[0].flags = UV_CREATE_PIPE | UV_READABLE_PIPE;
  2951
+    stdio[0].data.stream = &pcontext->any.stream;
  2952
+  } else {
  2953
+    stdio[0].flags = UV_IGNORE;
  2954
+  }
  2955
+
  2956
+  if (!mrb_nil_p(stdout_pipe)) {
  2957
+    mrb_value pipe_context = mrb_iv_get(mrb, stdout_pipe, mrb_intern(mrb, "context"));
  2958
+    mrb_uv_context* pcontext = NULL;
  2959
+    Data_Get_Struct(mrb, pipe_context, &uv_context_type, pcontext);
  2960
+    if (!pcontext) {
  2961
+      mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid argument");
  2962
+    }
  2963
+    stdio[1].flags = UV_CREATE_PIPE | UV_WRITABLE_PIPE;
  2964
+    stdio[1].data.stream = &pcontext->any.stream;
  2965
+  } else {
  2966
+    stdio[1].flags = UV_IGNORE;
  2967
+  }
  2968
+
  2969
+  if (!mrb_nil_p(stderr_pipe)) {
  2970
+    mrb_value pipe_context = mrb_iv_get(mrb, stderr_pipe, mrb_intern(mrb, "context"));
  2971
+    mrb_uv_context* pcontext = NULL;
  2972
+    Data_Get_Struct(mrb, pipe_context, &uv_context_type, pcontext);
  2973
+    if (!pcontext) {
  2974
+      mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid argument");
  2975
+    }
  2976
+    stdio[2].flags = UV_CREATE_PIPE | UV_WRITABLE_PIPE;
  2977
+    stdio[2].data.stream = &pcontext->any.stream;
  2978
+  } else {
  2979
+    stdio[2].flags = UV_IGNORE;
  2980
+  }
  2981
+
  2982
+  uv_process_options_t opt = {0};
  2983
+  opt.file = RSTRING_PTR(arg_file);
  2984
+  opt.args = uv_setup_args(RARRAY_LEN(arg_args)+1, args);
  2985
+  opt.env = environ;
  2986
+  opt.cwd = cwd;
  2987
+  opt.exit_cb = exit_cb;
  2988
+  opt.stdio_count = 3;
  2989
+  opt.stdio = stdio;
  2990
+  opt.uid = 0;
  2991
+  opt.gid = 0;
  2992
+  opt.flags = 0;
  2993
+
  2994
+  int ret = uv_spawn(context->loop, &context->any.process, opt);
  2995
+  free(args);
  2996
+  if (ret != 0) {
  2997
+    mrb_raise(mrb, E_RUNTIME_ERROR, uv_strerror(uv_last_error(context->loop)));
  2998
+  }
  2999
+  context->any.process.data = context;
  3000
+  return mrb_nil_value();
  3001
+}
  3002
+
  3003
+static mrb_value
  3004
+mrb_uv_process_kill(mrb_state *mrb, mrb_value self)
  3005
+{
  3006
+  mrb_value arg_signum;
  3007
+  mrb_value value_context;
  3008
+  mrb_uv_context* context = NULL;
  3009
+
  3010
+  mrb_get_args(mrb, "i", &arg_signum);
  3011
+
  3012
+  value_context = mrb_iv_get(mrb, self, mrb_intern(mrb, "context"));
  3013
+  Data_Get_Struct(mrb, value_context, &uv_context_type, context);
  3014
+  if (!context) {
  3015
+    mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid argument");
  3016
+  }
  3017
+
  3018
+  return mrb_fixnum_value(uv_process_kill(&context->any.process, mrb_fixnum(arg_signum)));
  3019
+}
  3020
+
  3021
+static mrb_value
  3022
+mrb_uv_process_stdout_pipe_get(mrb_state *mrb, mrb_value self)
  3023
+{
  3024
+  return mrb_iv_get(mrb, self, mrb_intern(mrb, "stdout_pipe"));
  3025
+}
  3026
+
  3027
+static mrb_value
  3028
+mrb_uv_process_stdout_pipe_set(mrb_state *mrb, mrb_value self)
  3029
+{
  3030
+  mrb_value arg;
  3031
+  mrb_get_args(mrb, "o", &arg);
  3032
+  mrb_iv_set(mrb, self, mrb_intern(mrb, "stdout_pipe"), arg);
  3033
+  return mrb_nil_value();
  3034
+}
  3035
+
  3036
+static mrb_value
  3037
+mrb_uv_process_stdin_pipe_get(mrb_state *mrb, mrb_value self)
  3038
+{
  3039
+  return mrb_iv_get(mrb, self, mrb_intern(mrb, "stdin_pipe"));
  3040
+}
  3041
+
  3042
+static mrb_value
  3043
+mrb_uv_process_stdin_pipe_set(mrb_state *mrb, mrb_value self)
  3044
+{
  3045
+  mrb_value arg;
  3046
+  mrb_get_args(mrb, "o", &arg);
  3047
+  mrb_iv_set(mrb, self, mrb_intern(mrb, "stdin_pipe"), arg);
  3048
+  return mrb_nil_value();
  3049
+}
  3050
+
  3051
+static mrb_value
  3052
+mrb_uv_process_stderr_pipe_get(mrb_state *mrb, mrb_value self)
  3053
+{
  3054
+  return mrb_iv_get(mrb, self, mrb_intern(mrb, "stderr_pipe"));
  3055
+}
  3056
+
  3057
+static mrb_value
  3058
+mrb_uv_process_stderr_pipe_set(mrb_state *mrb, mrb_value self)
  3059
+{
  3060
+  mrb_value arg;
  3061
+  mrb_get_args(mrb, "o", &arg);
  3062
+  mrb_iv_set(mrb, self, mrb_intern(mrb, "stderr_pipe"), arg);
  3063
+  return mrb_nil_value();
  3064
+}
  3065
+
  3066
+/*********************************************************
2692 3067
  * register
2693 3068
  *********************************************************/
2694 3069
 
@@ -2702,11 +3077,17 @@ mrb_mruby_uv_gem_init(mrb_state* mrb) {
2702 3077
   mrb_define_module_function(mrb, _class_uv, "run2", mrb_uv_run2, ARGS_REQ(1));
2703 3078
   mrb_define_module_function(mrb, _class_uv, "default_loop", mrb_uv_default_loop, ARGS_NONE());
2704 3079
   mrb_define_module_function(mrb, _class_uv, "ip4_addr", mrb_uv_ip4_addr, ARGS_REQ(2));
  3080
+  mrb_define_module_function(mrb, _class_uv, "ip6_addr", mrb_uv_ip6_addr, ARGS_REQ(2));
2705 3081
   mrb_define_module_function(mrb, _class_uv, "getaddrinfo", mrb_uv_getaddrinfo, ARGS_REQ(3));
2706 3082
   mrb_define_module_function(mrb, _class_uv, "gc", mrb_uv_gc, ARGS_NONE());
2707 3083
   mrb_define_const(mrb, _class_uv, "UV_RUN_DEFAULT", mrb_fixnum_value(UV_RUN_DEFAULT));
2708 3084
   mrb_define_const(mrb, _class_uv, "UV_RUN_ONCE", mrb_fixnum_value(UV_RUN_ONCE));
2709 3085
   mrb_define_const(mrb, _class_uv, "UV_RUN_NOWAIT", mrb_fixnum_value(UV_RUN_NOWAIT));
  3086
+#ifdef _WIN32
  3087
+  mrb_define_const(mrb, _class_uv, "IS_WINDOWS", mrb_true_value());
  3088
+#else
  3089
+  mrb_define_const(mrb, _class_uv, "IS_WINDOWS", mrb_false_value());
  3090
+#endif
2710 3091
   ARENA_RESTORE;
2711 3092
 
2712 3093
   _class_uv_loop = mrb_define_class_under(mrb, _class_uv, "Loop", mrb->object_class);
@@ -2719,34 +3100,36 @@ mrb_mruby_uv_gem_init(mrb_state* mrb) {
2719 3100
   ARENA_RESTORE;
2720 3101
 
2721 3102
   _class_uv_timer = mrb_define_class_under(mrb, _class_uv, "Timer", mrb->object_class);
2722  
-  mrb_define_method(mrb, _class_uv_timer, "initialize", mrb_uv_timer_init, ARGS_OPT(1));
  3103
+  mrb_define_method(mrb, _class_uv_timer, "initialize", mrb_uv_timer_init, ARGS_NONE());
2723 3104
   mrb_define_method(mrb, _class_uv_timer, "start", mrb_uv_timer_start, ARGS_REQ(2));
2724 3105
   mrb_define_method(mrb, _class_uv_timer, "stop", mrb_uv_timer_stop, ARGS_NONE());
2725  
-  mrb_define_method(mrb, _class_uv_timer, "close", mrb_uv_close, ARGS_OPT(1));
  3106
+  mrb_define_method(mrb, _class_uv_timer, "close", mrb_uv_close, ARGS_NONE());
2726 3107
   mrb_define_method(mrb, _class_uv_timer, "data=", mrb_uv_data_set, ARGS_REQ(1));
2727 3108
   mrb_define_method(mrb, _class_uv_timer, "data", mrb_uv_data_get, ARGS_NONE());
2728 3109
   ARENA_RESTORE;
2729 3110
 
2730 3111
   _class_uv_idle = mrb_define_class_under(mrb, _class_uv, "Idle", mrb->object_class);
2731  
-  mrb_define_method(mrb, _class_uv_idle, "initialize", mrb_uv_idle_init, ARGS_OPT(1));
  3112
+  mrb_define_method(mrb, _class_uv_idle, "initialize", mrb_uv_idle_init, ARGS_NONE());
2732 3113
   mrb_define_method(mrb, _class_uv_idle, "start", mrb_uv_idle_start, ARGS_NONE());
2733 3114
   mrb_define_method(mrb, _class_uv_idle, "stop", mrb_uv_idle_stop, ARGS_NONE());
2734  
-  mrb_define_method(mrb, _class_uv_idle, "close", mrb_uv_close, ARGS_OPT(1));
  3115
+  mrb_define_method(mrb, _class_uv_idle, "close", mrb_uv_close, ARGS_NONE());
2735 3116
   mrb_define_method(mrb, _class_uv_idle, "data=", mrb_uv_data_set, ARGS_REQ(1));
2736 3117
   mrb_define_method(mrb, _class_uv_idle, "data", mrb_uv_data_get, ARGS_NONE());
2737 3118
   ARENA_RESTORE;
2738 3119
 
2739 3120
   _class_uv_async = mrb_define_class_under(mrb, _class_uv, "Async", mrb->object_class);
2740  
-  mrb_define_method(mrb, _class_uv_async, "initialize", mrb_uv_async_init, ARGS_OPT(1));
  3121
+  mrb_define_method(mrb, _class_uv_async, "initialize", mrb_uv_async_init, ARGS_NONE());
2741 3122
   mrb_define_method(mrb, _class_uv_async, "send", mrb_uv_async_send, ARGS_NONE());
  3123
+  mrb_define_method(mrb, _class_uv_async, "close", mrb_uv_close, ARGS_NONE());
2742 3124
   mrb_define_method(mrb, _class_uv_async, "data=", mrb_uv_data_set, ARGS_REQ(1));
2743 3125
   mrb_define_method(mrb, _class_uv_async, "data", mrb_uv_data_get, ARGS_NONE());
2744 3126
   ARENA_RESTORE;
2745 3127
 
2746 3128
   _class_uv_prepare = mrb_define_class_under(mrb, _class_uv, "Prepare", mrb->object_class);
2747  
-  mrb_define_method(mrb, _class_uv_prepare, "initialize", mrb_uv_prepare_init, ARGS_OPT(1));
  3129
+  mrb_define_method(mrb, _class_uv_prepare, "initialize", mrb_uv_prepare_init, ARGS_NONE());
2748 3130
   mrb_define_method(mrb, _class_uv_prepare, "start", mrb_uv_prepare_start, ARGS_REQ(1));
2749 3131
   mrb_define_method(mrb, _class_uv_prepare, "stop", mrb_uv_prepare_stop, ARGS_NONE());
  3132
+  mrb_define_method(mrb, _class_uv_prepare, "close", mrb_uv_close, ARGS_NONE());
2750 3133
   mrb_define_method(mrb, _class_uv_prepare, "data=", mrb_uv_data_set, ARGS_REQ(1));
2751 3134
   mrb_define_method(mrb, _class_uv_prepare, "data", mrb_uv_data_get, ARGS_NONE());
2752 3135
   ARENA_RESTORE;
@@ -2766,14 +3149,19 @@ mrb_mruby_uv_gem_init(mrb_state* mrb) {
2766 3149
   mrb_define_method(mrb, _class_uv_ip4addr, "to_s", mrb_uv_ip4addr_to_s, ARGS_NONE());
2767 3150
   ARENA_RESTORE;
2768 3151
 
  3152
+  _class_uv_ip6addr = mrb_define_class_under(mrb, _class_uv, "Ip6Addr", mrb->object_class);
  3153
+  mrb_define_method(mrb, _class_uv_ip6addr, "initialize", mrb_uv_ip6addr_init, ARGS_REQ(2));
  3154
+  mrb_define_method(mrb, _class_uv_ip6addr, "to_s", mrb_uv_ip6addr_to_s, ARGS_NONE());
  3155
+  ARENA_RESTORE;
  3156
+
2769 3157
   _class_uv_tcp = mrb_define_class_under(mrb, _class_uv, "TCP", mrb->object_class);
2770  
-  mrb_define_method(mrb, _class_uv_tcp, "initialize", mrb_uv_tcp_init, ARGS_OPT(1));
  3158
+  mrb_define_method(mrb, _class_uv_tcp, "initialize", mrb_uv_tcp_init, ARGS_NONE());
2771 3159
   mrb_define_method(mrb, _class_uv_tcp, "connect", mrb_uv_tcp_connect, ARGS_REQ(2));
2772 3160
   mrb_define_method(mrb, _class_uv_tcp, "read_start", mrb_uv_read_start, ARGS_REQ(2));
2773 3161
   mrb_define_method(mrb, _class_uv_tcp, "read_stop", mrb_uv_read_stop, ARGS_NONE());
2774  
-  mrb_define_method(mrb, _class_uv_tcp, "write", mrb_uv_write, ARGS_OPT(2));
2775  
-  mrb_define_method(mrb, _class_uv_tcp, "close", mrb_uv_close, ARGS_OPT(1));
2776  
-  mrb_define_method(mrb, _class_uv_tcp, "shutdown", mrb_uv_shutdown, ARGS_OPT(1));
  3162
+  mrb_define_method(mrb, _class_uv_tcp, "write", mrb_uv_write, ARGS_REQ(2));
  3163
+  mrb_define_method(mrb, _class_uv_tcp, "close", mrb_uv_close, ARGS_NONE());
  3164
+  mrb_define_method(mrb, _class_uv_tcp, "shutdown", mrb_uv_shutdown, ARGS_NONE());
2777 3165
   mrb_define_method(mrb, _class_uv_tcp, "bind", mrb_uv_tcp_bind, ARGS_REQ(1));
2778 3166
   mrb_define_method(mrb, _class_uv_tcp, "listen", mrb_uv_tcp_listen, ARGS_REQ(1));
2779 3167
   mrb_define_method(mrb, _class_uv_tcp, "accept", mrb_uv_tcp_accept, ARGS_NONE());
@@ -2788,24 +3176,24 @@ mrb_mruby_uv_gem_init(mrb_state* mrb) {
2788 3176
   ARENA_RESTORE;
2789 3177
 
2790 3178
   _class_uv_udp = mrb_define_class_under(mrb, _class_uv, "UDP", mrb->object_class);
2791  
-  mrb_define_method(mrb, _class_uv_udp, "initialize", mrb_uv_udp_init, ARGS_OPT(1));
2792  
-  mrb_define_method(mrb, _class_uv_udp, "recv_start", mrb_uv_udp_recv_start, ARGS_REQ(2));
  3179
+  mrb_define_method(mrb, _class_uv_udp, "initialize", mrb_uv_udp_init, ARGS_NONE());
  3180
+  mrb_define_method(mrb, _class_uv_udp, "recv_start", mrb_uv_udp_recv_start, ARGS_NONE());
2793 3181
   mrb_define_method(mrb, _class_uv_udp, "recv_stop", mrb_uv_udp_recv_stop, ARGS_NONE());
2794  
-  mrb_define_method(mrb, _class_uv_udp, "send", mrb_uv_udp_send, ARGS_OPT(3));
2795  
-  mrb_define_method(mrb, _class_uv_udp, "close", mrb_uv_close, ARGS_OPT(1));
  3182
+  mrb_define_method(mrb, _class_uv_udp, "send", mrb_uv_udp_send, ARGS_REQ(2));
  3183
+  mrb_define_method(mrb, _class_uv_udp, "close", mrb_uv_close, ARGS_NONE());
2796 3184
   mrb_define_method(mrb, _class_uv_udp, "bind", mrb_uv_udp_bind, ARGS_REQ(1));
2797 3185
   mrb_define_method(mrb, _class_uv_udp, "data=", mrb_uv_data_set, ARGS_REQ(1));
2798 3186
   mrb_define_method(mrb, _class_uv_udp, "data", mrb_uv_data_get, ARGS_NONE());
2799 3187
   ARENA_RESTORE;
2800 3188
 
2801 3189
   _class_uv_pipe = mrb_define_class_under(mrb, _class_uv, "Pipe", mrb->object_class);
2802  
-  mrb_define_method(mrb, _class_uv_pipe, "initialize", mrb_uv_pipe_init, ARGS_OPT(1));
  3190
+  mrb_define_method(mrb, _class_uv_pipe, "initialize", mrb_uv_pipe_init, ARGS_REQ(1));
2803 3191
   mrb_define_method(mrb, _class_uv_pipe, "connect", mrb_uv_pipe_connect, ARGS_REQ(2));
2804 3192
   mrb_define_method(mrb, _class_uv_pipe, "read_start", mrb_uv_read_start, ARGS_REQ(2));
2805 3193
   mrb_define_method(mrb, _class_uv_pipe, "read_stop", mrb_uv_read_stop, ARGS_NONE());
2806 3194
   mrb_define_method(mrb, _class_uv_pipe, "write", mrb_uv_write, ARGS_REQ(1));
2807  
-  mrb_define_method(mrb, _class_uv_pipe, "close", mrb_uv_close, ARGS_OPT(1));
2808  
-  mrb_define_method(mrb, _class_uv_pipe, "shutdown", mrb_uv_shutdown, ARGS_OPT(1));
  3195
+  mrb_define_method(mrb, _class_uv_pipe, "close", mrb_uv_close, ARGS_NONE());
  3196
+  mrb_define_method(mrb, _class_uv_pipe, "shutdown", mrb_uv_shutdown, ARGS_NONE());
2809 3197
   mrb_define_method(mrb, _class_uv_pipe, "bind", mrb_uv_pipe_bind, ARGS_REQ(1));
2810 3198
   mrb_define_method(mrb, _class_uv_pipe, "listen", mrb_uv_pipe_listen, ARGS_REQ(1));
2811 3199
   mrb_define_method(mrb, _class_uv_pipe, "accept", mrb_uv_pipe_accept, ARGS_NONE());
@@ -2839,13 +3227,13 @@ mrb_mruby_uv_gem_init(mrb_state* mrb) {
2839 3227
   mrb_define_const(mrb, _class_uv_fs, "S_IWRITE", mrb_fixnum_value(S_IWRITE));
2840 3228
   mrb_define_const(mrb, _class_uv_fs, "S_IREAD", mrb_fixnum_value(S_IREAD));
2841 3229
   mrb_define_module_function(mrb, _class_uv_fs, "fd", mrb_uv_fs_fd, ARGS_NONE());
2842  
-  mrb_define_module_function(mrb, _class_uv_fs, "open", mrb_uv_fs_open, ARGS_OPT(1));
2843  
-  mrb_define_method(mrb, _class_uv_fs, "write", mrb_uv_fs_write, ARGS_OPT(1));
2844  
-  mrb_define_method(mrb, _class_uv_fs, "read", mrb_uv_fs_read, ARGS_OPT(1));
2845  
-  mrb_define_method(mrb, _class_uv_fs, "close", mrb_uv_fs_close, ARGS_OPT(1));
  3230
+  mrb_define_module_function(mrb, _class_uv_fs, "open", mrb_uv_fs_open, ARGS_REQ(2));
  3231
+  mrb_define_method(mrb, _class_uv_fs, "write", mrb_uv_fs_write, ARGS_REQ(2));
  3232
+  mrb_define_method(mrb, _class_uv_fs, "read", mrb_uv_fs_read, ARGS_REQ(2));
  3233
+  mrb_define_method(mrb, _class_uv_fs, "close", mrb_uv_fs_close, ARGS_NONE());
2846 3234
   mrb_define_module_function(mrb, _class_uv_fs, "unlink", mrb_uv_fs_unlink, ARGS_REQ(1));
2847 3235
   mrb_define_module_function(mrb, _class_uv_fs, "mkdir", mrb_uv_fs_mkdir, ARGS_REQ(2));
2848  
-  mrb_define_module_function(mrb, _class_uv_fs, "rmdir", mrb_uv_fs_rmdir, ARGS_OPT(1));
  3236
+  mrb_define_module_function(mrb, _class_uv_fs, "rmdir", mrb_uv_fs_rmdir, ARGS_REQ(1));
2849 3237
   mrb_define_module_function(mrb, _class_uv_fs, "readdir", mrb_uv_fs_readdir, ARGS_REQ(2));
2850 3238
   mrb_define_module_function(mrb, _class_uv_fs, "stat", mrb_uv_fs_stat, ARGS_REQ(1));
2851 3239
   mrb_define_module_function(mrb, _class_uv_fs, "fstat", mrb_uv_fs_fstat, ARGS_REQ(1));
@@ -2874,12 +3262,14 @@ mrb_mruby_uv_gem_init(mrb_state* mrb) {
2874 3262
   mrb_define_method(mrb, _class_uv_fs_poll, "initialize", mrb_uv_fs_poll_init, ARGS_NONE());
2875 3263
   mrb_define_method(mrb, _class_uv_fs_poll, "start", mrb_uv_fs_poll_start, ARGS_REQ(2));
2876 3264
   mrb_define_method(mrb, _class_uv_fs_poll, "stop", mrb_uv_fs_poll_stop, ARGS_NONE());
  3265
+  mrb_define_method(mrb, _class_uv_fs_poll, "close", mrb_uv_close, ARGS_NONE());
2877 3266
   ARENA_RESTORE;
2878 3267
 
2879 3268
   _class_uv_signal = mrb_define_class_under(mrb, _class_uv, "Signal", mrb->object_class);
2880 3269
   mrb_define_method(mrb, _class_uv_signal, "initialize", mrb_uv_signal_init, ARGS_NONE());
2881 3270
   mrb_define_method(mrb, _class_uv_signal, "start", mrb_uv_signal_start, ARGS_REQ(1));
2882 3271
   mrb_define_method(mrb, _class_uv_signal, "stop", mrb_uv_signal_stop, ARGS_NONE());
  3272
+  mrb_define_method(mrb, _class_uv_signal, "close", mrb_uv_close, ARGS_NONE());
2883 3273
   mrb_define_const(mrb, _class_uv_signal, "SIGINT", mrb_fixnum_value(SIGINT));
2884 3274
 #ifdef SIGBREAK
2885 3275
   mrb_define_const(mrb, _class_uv_signal, "SIGBREAK", mrb_fixnum_value(SIGBREAK));
@@ -2894,15 +3284,42 @@ mrb_mruby_uv_gem_init(mrb_state* mrb) {
2894 3284
   mrb_define_const(mrb, _class_uv_signal, "SIGKILL", mrb_fixnum_value(SIGKILL));
2895 3285
   ARENA_RESTORE;
2896 3286
 
  3287
+  _class_uv_tty = mrb_define_class_under(mrb, _class_uv, "TTY", mrb->object_class);
  3288
+  mrb_define_method(mrb, _class_uv_tty, "initialize", mrb_uv_tty_init, ARGS_REQ(2));
  3289
+  mrb_define_method(mrb, _class_uv_tty, "set_mode", mrb_uv_tty_set_mode, ARGS_REQ(1));
  3290
+  mrb_define_module_function(mrb, _class_uv_tty, "reset_mode", mrb_uv_tty_reset_mode, ARGS_NONE());
  3291
+  mrb_define_method(mrb, _class_uv_tty, "get_winsize", mrb_uv_tty_get_winsize, ARGS_NONE());
  3292
+  mrb_define_method(mrb, _class_uv_tty, "close", mrb_uv_close, ARGS_NONE());
  3293
+  ARENA_RESTORE;
  3294
+
  3295
+  _class_uv_process = mrb_define_class_under(mrb, _class_uv, "Process", mrb->object_class);
  3296
+  mrb_define_method(mrb, _class_uv_process, "initialize", mrb_uv_process_init, ARGS_REQ(1));
  3297
+  mrb_define_method(mrb, _class_uv_process, "spawn", mrb_uv_process_spawn, ARGS_NONE());
  3298
+  mrb_define_method(mrb, _class_uv_process, "stdout_pipe=", mrb_uv_process_stdout_pipe_set, ARGS_REQ(1));
  3299
+  mrb_define_method(mrb, _class_uv_process, "stdout_pipe", mrb_uv_process_stdout_pipe_get, ARGS_NONE());
  3300
+  mrb_define_method(mrb, _class_uv_process, "stdin_pipe=", mrb_uv_process_stdin_pipe_set, ARGS_REQ(1));
  3301
+  mrb_define_method(mrb, _class_uv_process, "stdin_pipe", mrb_uv_process_stdin_pipe_get, ARGS_NONE());
  3302
+  mrb_define_method(mrb, _class_uv_process, "stderr_pipe=", mrb_uv_process_stderr_pipe_set, ARGS_REQ(1));
  3303
+  mrb_define_method(mrb, _class_uv_process, "stderr_pipe", mrb_uv_process_stderr_pipe_get, ARGS_NONE());
  3304
+  mrb_define_method(mrb, _class_uv_process, "kill", mrb_uv_process_kill, ARGS_NONE());
  3305
+  mrb_define_method(mrb, _class_uv_process, "close", mrb_uv_close, ARGS_NONE());
  3306
+  mrb_define_method(mrb, _class_uv_process, "data=", mrb_uv_data_set, ARGS_REQ(1));
  3307
+  mrb_define_method(mrb, _class_uv_process, "data", mrb_uv_data_get, ARGS_NONE());
  3308
+  ARENA_RESTORE;
  3309
+
2897 3310
   /* TODO
2898  
-  TTY
2899  
-  PROCESS
2900  
-  WORK
  3311
+  dl
  3312
+  barrier
  3313
+  process
  3314
+  queue/work
  3315
+  cpuinfo
  3316
+  uv_once
  3317
+  uv_thread
2901 3318
   etc...
2902 3319
   */
2903 3320
 
2904  
-  uv_gc_hash = mrb_hash_new(mrb);
2905  
-  mrb_define_const(mrb, _class_uv, "$GC", uv_gc_hash);
  3321
+  uv_gc_table = mrb_ary_new(mrb);
  3322
+  mrb_define_const(mrb, _class_uv, "$GC", uv_gc_table);
2906 3323
 }
2907 3324
 
2908 3325
 /* vim:set et ts=2 sts=2 sw=2 tw=0: */

No commit comments for this range

Something went wrong with that request. Please try again.