noderb 0.0.10 → 0.0.11

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.
Files changed (50) hide show
  1. data/ext/noderb_extension/extconf.rb +15 -11
  2. data/ext/noderb_extension/libuv/AUTHORS +3 -0
  3. data/ext/noderb_extension/libuv/{README → README.md} +48 -6
  4. data/ext/noderb_extension/libuv/common.gypi +6 -1
  5. data/ext/noderb_extension/libuv/config-unix.mk +1 -1
  6. data/ext/noderb_extension/libuv/include/uv-private/uv-linux.h +29 -0
  7. data/ext/noderb_extension/libuv/include/uv-private/uv-unix.h +9 -0
  8. data/ext/noderb_extension/libuv/include/uv-private/uv-win.h +38 -3
  9. data/ext/noderb_extension/libuv/include/uv.h +55 -3
  10. data/ext/noderb_extension/libuv/src/unix/cares.c +1 -0
  11. data/ext/noderb_extension/libuv/src/unix/core.c +20 -4
  12. data/ext/noderb_extension/libuv/src/unix/cygwin.c +16 -0
  13. data/ext/noderb_extension/libuv/src/unix/darwin.c +18 -0
  14. data/ext/noderb_extension/libuv/src/unix/freebsd.c +18 -1
  15. data/ext/noderb_extension/libuv/src/unix/fs.c +18 -9
  16. data/ext/noderb_extension/libuv/src/unix/internal.h +24 -0
  17. data/ext/noderb_extension/libuv/src/unix/linux.c +133 -1
  18. data/ext/noderb_extension/libuv/src/unix/netbsd.c +18 -1
  19. data/ext/noderb_extension/libuv/src/unix/stream.c +21 -7
  20. data/ext/noderb_extension/libuv/src/unix/sunos.c +18 -1
  21. data/ext/noderb_extension/libuv/src/unix/tty.c +41 -0
  22. data/ext/noderb_extension/libuv/src/unix/udp.c +1 -0
  23. data/ext/noderb_extension/libuv/src/win/core.c +3 -0
  24. data/ext/noderb_extension/libuv/src/win/fs-event.c +384 -0
  25. data/ext/noderb_extension/libuv/src/win/getaddrinfo.c +7 -2
  26. data/ext/noderb_extension/libuv/src/win/handle.c +41 -0
  27. data/ext/noderb_extension/libuv/src/win/internal.h +36 -0
  28. data/ext/noderb_extension/libuv/src/win/pipe.c +3 -0
  29. data/ext/noderb_extension/libuv/src/win/process.c +7 -2
  30. data/ext/noderb_extension/libuv/src/win/req.c +10 -0
  31. data/ext/noderb_extension/libuv/src/win/stream.c +10 -3
  32. data/ext/noderb_extension/libuv/src/win/tcp.c +3 -1
  33. data/ext/noderb_extension/libuv/src/win/tty.c +1559 -5
  34. data/ext/noderb_extension/libuv/test/benchmark-getaddrinfo.c +2 -0
  35. data/ext/noderb_extension/libuv/test/runner-unix.c +2 -0
  36. data/ext/noderb_extension/libuv/test/test-fs-event.c +217 -0
  37. data/ext/noderb_extension/libuv/test/test-fs.c +0 -4
  38. data/ext/noderb_extension/libuv/test/test-getaddrinfo.c +7 -3
  39. data/ext/noderb_extension/libuv/test/test-list.h +23 -0
  40. data/ext/noderb_extension/libuv/test/test-tcp-close.c +47 -0
  41. data/ext/noderb_extension/libuv/test/test-tcp-write-error.c +168 -0
  42. data/ext/noderb_extension/libuv/test/test-timer.c +40 -0
  43. data/ext/noderb_extension/libuv/test/test-tty.c +56 -0
  44. data/ext/noderb_extension/libuv/uv.gyp +17 -18
  45. data/ext/noderb_extension/noderb.c +0 -2
  46. data/ext/noderb_extension/noderb_dns.c +6 -7
  47. data/ext/noderb_extension/noderb_fs.c +11 -10
  48. data/ext/noderb_extension/noderb_timers.c +5 -5
  49. data/lib/noderb/version.rb +1 -1
  50. metadata +8 -3
@@ -19,15 +19,29 @@
19
19
  */
20
20
 
21
21
  #include "uv.h"
22
+ #include "internal.h"
22
23
 
23
24
  #include <stdint.h>
24
- #include <stddef.h>
25
+ #include <stdlib.h>
26
+ #include <string.h>
27
+ #include <assert.h>
28
+ #include <errno.h>
29
+
30
+ #include <sys/inotify.h>
25
31
  #include <unistd.h>
26
32
  #include <time.h>
27
33
 
28
34
  #undef NANOSEC
29
35
  #define NANOSEC 1000000000
30
36
 
37
+
38
+ /* Don't look aghast, this is exactly how glibc's basename() works. */
39
+ static char* basename_r(const char* path) {
40
+ char* s = strrchr(path, '/');
41
+ return s ? (s + 1) : (char*)path;
42
+ }
43
+
44
+
31
45
  /*
32
46
  * There's probably some way to get time from Linux than gettimeofday(). What
33
47
  * it is, I don't know.
@@ -49,3 +63,121 @@ int uv_exepath(char* buffer, size_t* size) {
49
63
  buffer[*size] = '\0';
50
64
  return 0;
51
65
  }
66
+
67
+
68
+ static int new_inotify_fd(void) {
69
+ #if defined(IN_NONBLOCK) && defined(IN_CLOEXEC)
70
+ return inotify_init1(IN_NONBLOCK | IN_CLOEXEC);
71
+ #else
72
+ int fd;
73
+
74
+ if ((fd = inotify_init()) == -1)
75
+ return -1;
76
+
77
+ if (uv__cloexec(fd, 1) || uv__nonblock(fd, 1)) {
78
+ SAVE_ERRNO(uv__close(fd));
79
+ fd = -1;
80
+ }
81
+
82
+ return fd;
83
+ #endif
84
+ }
85
+
86
+
87
+ static void uv__inotify_read(EV_P_ ev_io* w, int revents) {
88
+ struct inotify_event* e;
89
+ uv_fs_event_t* handle;
90
+ const char* filename;
91
+ ssize_t size;
92
+ int events;
93
+ char *p;
94
+ /* needs to be large enough for sizeof(inotify_event) + strlen(filename) */
95
+ char buf[4096];
96
+
97
+ handle = container_of(w, uv_fs_event_t, read_watcher);
98
+
99
+ do {
100
+ do {
101
+ size = read(handle->fd, buf, sizeof buf);
102
+ }
103
+ while (size == -1 && errno == EINTR);
104
+
105
+ if (size == -1) {
106
+ assert(errno == EAGAIN || errno == EWOULDBLOCK);
107
+ break;
108
+ }
109
+
110
+ assert(size > 0); /* pre-2.6.21 thing, size=0 == read buffer too small */
111
+
112
+ /* Now we have one or more inotify_event structs. */
113
+ for (p = buf; p < buf + size; p += sizeof(*e) + e->len) {
114
+ e = (void*)p;
115
+
116
+ events = 0;
117
+ if (e->mask & (IN_ATTRIB|IN_MODIFY))
118
+ events |= UV_CHANGE;
119
+ if (e->mask & ~(IN_ATTRIB|IN_MODIFY))
120
+ events |= UV_RENAME;
121
+
122
+ /* inotify does not return the filename when monitoring a single file
123
+ * for modifications. Repurpose the filename for API compatibility.
124
+ * I'm not convinced this is a good thing, maybe it should go.
125
+ */
126
+ filename = e->len ? e->name : basename_r(handle->filename);
127
+
128
+ handle->cb(handle, filename, events, 0);
129
+ }
130
+ }
131
+ while (handle->fd != -1); /* handle might've been closed by callback */
132
+ }
133
+
134
+
135
+ int uv_fs_event_init(uv_loop_t* loop,
136
+ uv_fs_event_t* handle,
137
+ const char* filename,
138
+ uv_fs_event_cb cb) {
139
+ int flags;
140
+ int fd;
141
+
142
+ /*
143
+ * TODO share a single inotify fd across the event loop?
144
+ * We'll run into fs.inotify.max_user_instances if we
145
+ * keep creating new inotify fds.
146
+ */
147
+ if ((fd = new_inotify_fd()) == -1) {
148
+ uv_err_new(loop, errno);
149
+ return -1;
150
+ }
151
+
152
+ flags = IN_ATTRIB
153
+ | IN_CREATE
154
+ | IN_MODIFY
155
+ | IN_DELETE
156
+ | IN_DELETE_SELF
157
+ | IN_MOVED_FROM
158
+ | IN_MOVED_TO;
159
+
160
+ if (inotify_add_watch(fd, filename, flags) == -1) {
161
+ uv_err_new(loop, errno);
162
+ uv__close(fd);
163
+ return -1;
164
+ }
165
+
166
+ uv__handle_init(loop, (uv_handle_t*)handle, UV_FS_EVENT);
167
+ handle->filename = strdup(filename); /* this should go! */
168
+ handle->cb = cb;
169
+ handle->fd = fd;
170
+
171
+ ev_io_init(&handle->read_watcher, uv__inotify_read, fd, EV_READ);
172
+ ev_io_start(loop->ev, &handle->read_watcher);
173
+
174
+ return 0;
175
+ }
176
+
177
+
178
+ void uv__fs_event_destroy(uv_fs_event_t* handle) {
179
+ ev_io_stop(handle->loop->ev, &handle->read_watcher);
180
+ uv__close(handle->fd);
181
+ handle->fd = -1;
182
+ free(handle->filename);
183
+ }
@@ -20,17 +20,20 @@
20
20
 
21
21
  #include "uv.h"
22
22
 
23
+ #include <assert.h>
23
24
  #include <string.h>
24
- #include <time.h>
25
+ #include <errno.h>
25
26
 
26
27
  #include <sys/types.h>
27
28
  #include <sys/sysctl.h>
28
29
 
29
30
  #include <unistd.h>
31
+ #include <time.h>
30
32
 
31
33
  #undef NANOSEC
32
34
  #define NANOSEC 1000000000
33
35
 
36
+
34
37
  uint64_t uv_hrtime(void) {
35
38
  struct timespec ts;
36
39
  clock_gettime(CLOCK_MONOTONIC, &ts);
@@ -66,3 +69,17 @@ int uv_exepath(char* buffer, size_t* size) {
66
69
 
67
70
  return 0;
68
71
  }
72
+
73
+
74
+ int uv_fs_event_init(uv_loop_t* loop,
75
+ uv_fs_event_t* handle,
76
+ const char* filename,
77
+ uv_fs_event_cb cb) {
78
+ uv_err_new(loop, ENOSYS);
79
+ return -1;
80
+ }
81
+
82
+
83
+ void uv__fs_event_destroy(uv_fs_event_t* handle) {
84
+ assert(0 && "implement me");
85
+ }
@@ -129,8 +129,8 @@ void uv__stream_destroy(uv_stream_t* stream) {
129
129
 
130
130
  req = ngx_queue_data(q, uv_write_t, queue);
131
131
  if (req->cb) {
132
- uv_err_new_artificial(req->handle->loop, UV_OK);
133
- req->cb(req, 0);
132
+ uv_err_new_artificial(stream->loop, req->error);
133
+ req->cb(req, req->error ? -1 : 0);
134
134
  }
135
135
  }
136
136
  }
@@ -287,6 +287,17 @@ static void uv__drain(uv_stream_t* stream) {
287
287
  }
288
288
 
289
289
 
290
+ static size_t uv__write_req_size(uv_write_t* req) {
291
+ size_t size;
292
+
293
+ size = uv__buf_count(req->bufs + req->write_index,
294
+ req->bufcnt - req->write_index);
295
+ assert(req->handle->write_queue_size >= size);
296
+
297
+ return size;
298
+ }
299
+
300
+
290
301
  static void uv__write_req_finish(uv_write_t* req) {
291
302
  uv_stream_t* stream = req->handle;
292
303
 
@@ -351,6 +362,7 @@ static void uv__write(uv_stream_t* stream) {
351
362
  if (errno != EAGAIN) {
352
363
  /* Error */
353
364
  req->error = errno;
365
+ stream->write_queue_size -= uv__write_req_size(req);
354
366
  uv__write_req_finish(req);
355
367
  return;
356
368
  }
@@ -517,8 +529,8 @@ int uv_shutdown(uv_shutdown_t* req, uv_stream_t* stream, uv_shutdown_cb cb) {
517
529
  void uv__stream_io(EV_P_ ev_io* watcher, int revents) {
518
530
  uv_stream_t* stream = watcher->data;
519
531
 
520
- assert(stream->type == UV_TCP ||
521
- stream->type == UV_NAMED_PIPE);
532
+ assert(stream->type == UV_TCP || stream->type == UV_NAMED_PIPE ||
533
+ stream->type == UV_TTY);
522
534
  assert(watcher == &stream->read_watcher ||
523
535
  watcher == &stream->write_watcher);
524
536
  assert(!(stream->flags & UV_CLOSING));
@@ -667,8 +679,9 @@ int uv_write(uv_write_t* req, uv_stream_t* stream, uv_buf_t bufs[], int bufcnt,
667
679
  uv_write_cb cb) {
668
680
  int empty_queue;
669
681
 
670
- assert((stream->type == UV_TCP || stream->type == UV_NAMED_PIPE)
671
- && "uv_write (unix) does not yet support other types of streams");
682
+ assert((stream->type == UV_TCP || stream->type == UV_NAMED_PIPE ||
683
+ stream->type == UV_TTY) &&
684
+ "uv_write (unix) does not yet support other types of streams");
672
685
 
673
686
  if (stream->fd < 0) {
674
687
  uv_err_new(stream->loop, EBADF);
@@ -725,7 +738,8 @@ int uv_write(uv_write_t* req, uv_stream_t* stream, uv_buf_t bufs[], int bufcnt,
725
738
 
726
739
 
727
740
  int uv_read_start(uv_stream_t* stream, uv_alloc_cb alloc_cb, uv_read_cb read_cb) {
728
- assert(stream->type == UV_TCP || stream->type == UV_NAMED_PIPE);
741
+ assert(stream->type == UV_TCP || stream->type == UV_NAMED_PIPE ||
742
+ stream->type == UV_TTY);
729
743
 
730
744
  if (stream->flags & UV_CLOSING) {
731
745
  uv_err_new(stream->loop, EINVAL);
@@ -22,8 +22,11 @@
22
22
 
23
23
  #include <stdio.h>
24
24
  #include <stdint.h>
25
- #include <unistd.h>
25
+ #include <assert.h>
26
+ #include <errno.h>
27
+
26
28
  #include <sys/time.h>
29
+ #include <unistd.h>
27
30
 
28
31
 
29
32
  uint64_t uv_hrtime() {
@@ -58,3 +61,17 @@ int uv_exepath(char* buffer, size_t* size) {
58
61
  *size = res;
59
62
  return (0);
60
63
  }
64
+
65
+
66
+ int uv_fs_event_init(uv_loop_t* loop,
67
+ uv_fs_event_t* handle,
68
+ const char* filename,
69
+ uv_fs_event_cb cb) {
70
+ uv_err_new(loop, ENOSYS);
71
+ return -1;
72
+ }
73
+
74
+
75
+ void uv__fs_event_destroy(uv_fs_event_t* handle) {
76
+ assert(0 && "implement me");
77
+ }
@@ -23,8 +23,10 @@
23
23
  #include "internal.h"
24
24
 
25
25
  #include <assert.h>
26
+ #include <unistd.h>
26
27
  #include <termios.h>
27
28
  #include <errno.h>
29
+ #include <sys/ioctl.h>
28
30
 
29
31
 
30
32
  int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, int fd) {
@@ -67,3 +69,42 @@ fatal:
67
69
  return -1;
68
70
  }
69
71
 
72
+
73
+ int uv_tty_get_winsize(uv_tty_t* tty, int* width, int* height) {
74
+ struct winsize ws;
75
+
76
+ if (ioctl(tty->fd, TIOCGWINSZ, &ws) < 0) {
77
+ uv_err_new(tty->loop, errno);
78
+ return -1;
79
+ }
80
+
81
+ *width = ws.ws_col;
82
+ *height = ws.ws_row;
83
+
84
+ return 0;
85
+ }
86
+
87
+
88
+ uv_handle_type uv_guess_handle(uv_file file) {
89
+ struct stat s;
90
+
91
+ if (file < 0) {
92
+ uv_err_new(NULL, EINVAL); /* XXX Need loop? */
93
+ return -1;
94
+ }
95
+
96
+ if (isatty(file)) {
97
+ return UV_TTY;
98
+ }
99
+
100
+ if (fstat(file, &s)) {
101
+ uv_err_new(NULL, errno); /* XXX Need loop? */
102
+ return -1;
103
+ }
104
+
105
+ if (!S_ISSOCK(s.st_mode) && !S_ISFIFO(s.st_mode)) {
106
+ return UV_FILE;
107
+ }
108
+
109
+ return UV_NAMED_PIPE;
110
+ }
@@ -301,6 +301,7 @@ static int uv__udp_bind(uv_udp_t* handle,
301
301
 
302
302
  saved_errno = errno;
303
303
  status = -1;
304
+ fd = -1;
304
305
 
305
306
  /* Check for bad flags. */
306
307
  if (flags & ~UV_UDP_IPV6ONLY) {
@@ -48,6 +48,9 @@ static void uv_init(void) {
48
48
 
49
49
  /* Initialize FS */
50
50
  uv_fs_init();
51
+
52
+ /* Initialize console */
53
+ uv_console_init();
51
54
  }
52
55
 
53
56