Skip to content

Commit ea4b1c1

Browse files
committed
Upgrade libuv to bc4126b
1 parent 9b42d7d commit ea4b1c1

File tree

4 files changed

+66
-30
lines changed

4 files changed

+66
-30
lines changed

deps/uv/include/uv-private/uv-unix.h

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@
3636
#include <pwd.h>
3737
#include <termios.h>
3838

39+
#if __sun
40+
# include <sys/port.h>
41+
# include <port.h>
42+
#endif
43+
3944
/* Note: May be cast to struct iovec. See writev(2). */
4045
typedef struct {
4146
char* base;
@@ -52,6 +57,14 @@ typedef uid_t uv_uid_t;
5257
typedef void* uv_lib_t;
5358
#define UV_DYNAMIC /* empty */
5459

60+
#if defined(PORT_SOURCE_FILE)
61+
# define UV_LOOP_PRIVATE_PLATFORM_FIELDS \
62+
ev_io fs_event_watcher; \
63+
int fs_fd;
64+
#else
65+
# define UV_LOOP_PRIVATE_PLATFORM_FIELDS
66+
#endif
67+
5568
#define UV_LOOP_PRIVATE_FIELDS \
5669
ares_channel channel; \
5770
/* \
@@ -60,7 +73,8 @@ typedef void* uv_lib_t;
6073
* definition of ares_timeout(). \
6174
*/ \
6275
ev_timer timer; \
63-
struct ev_loop* ev;
76+
struct ev_loop* ev; \
77+
UV_LOOP_PRIVATE_PLATFORM_FIELDS
6478

6579
#define UV_REQ_BUFSML_SIZE (4)
6680

@@ -206,12 +220,8 @@ typedef void* uv_lib_t;
206220

207221
#elif defined(__sun)
208222

209-
#include <sys/port.h>
210-
#include <port.h>
211-
212223
#ifdef PORT_SOURCE_FILE
213224
# define UV_FS_EVENT_PRIVATE_FIELDS \
214-
ev_io event_watcher; \
215225
uv_fs_event_cb cb; \
216226
file_obj_t fo;
217227
#else /* !PORT_SOURCE_FILE */

deps/uv/src/unix/core.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*/
2020

2121
#include "uv.h"
22-
#include "unix/internal.h"
22+
#include "internal.h"
2323

2424
#include <stddef.h> /* NULL */
2525
#include <stdio.h> /* printf */
@@ -151,6 +151,9 @@ uv_loop_t* uv_loop_new(void) {
151151
uv_loop_t* loop = calloc(1, sizeof(uv_loop_t));
152152
loop->ev = ev_loop_new(0);
153153
ev_set_userdata(loop->ev, loop);
154+
#if HAVE_PORTS_FS
155+
loop->fs_fd = -1;
156+
#endif
154157
return loop;
155158
}
156159

@@ -163,6 +166,12 @@ void uv_loop_delete(uv_loop_t* loop) {
163166
memset(loop, 0, sizeof *loop);
164167
#endif
165168

169+
#if HAVE_PORTS_FS
170+
if (loop->fs_fd != -1) {
171+
uv__close(loop->fs_fd);
172+
}
173+
#endif
174+
166175
if (loop == default_loop_ptr)
167176
default_loop_ptr = NULL;
168177
else
@@ -182,6 +191,9 @@ uv_loop_t* uv_default_loop(void) {
182191
default_loop_struct.ev = ev_default_loop(EVBACKEND_KQUEUE);
183192
#else
184193
default_loop_struct.ev = ev_default_loop(EVFLAG_AUTO);
194+
#endif
195+
#if HAVE_PORTS_FS
196+
default_loop_struct.fs_fd = -1;
185197
#endif
186198
ev_set_userdata(default_loop_struct.ev, default_loop_ptr);
187199
}

deps/uv/src/unix/sunos.c

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@
3636
#if HAVE_PORTS_FS
3737
# include <sys/port.h>
3838
# include <port.h>
39+
40+
# define PORT_FIRED 0x69
41+
# define PORT_UNUSED 0x0
42+
# define PORT_LOADED 0x99
43+
# define PORT_DELETED -1
3944
#endif
4045

4146

@@ -90,36 +95,41 @@ void uv_loadavg(double avg[3]) {
9095

9196
#if HAVE_PORTS_FS
9297
static void uv__fs_event_rearm(uv_fs_event_t *handle) {
93-
if (port_associate(handle->fd,
98+
if (handle->fd == -1)
99+
return;
100+
101+
if (port_associate(handle->loop->fs_fd,
94102
PORT_SOURCE_FILE,
95103
(uintptr_t) &handle->fo,
96104
FILE_ATTRIB | FILE_MODIFIED,
97-
NULL) == -1) {
105+
handle) == -1) {
98106
uv__set_sys_error(handle->loop, errno);
99107
}
108+
handle->fd = PORT_LOADED;
100109
}
101110

102111

103112
static void uv__fs_event_read(EV_P_ ev_io* w, int revents) {
104113
uv_fs_event_t *handle;
114+
uv_loop_t *loop_;
105115
timespec_t timeout;
106116
port_event_t pe;
107117
int events;
108118
int r;
109119

110-
handle = container_of(w, uv_fs_event_t, event_watcher);
120+
loop_ = container_of(w, uv_loop_t, fs_event_watcher);
111121

112122
do {
113123
/* TODO use port_getn() */
114124
do {
115125
memset(&timeout, 0, sizeof timeout);
116-
r = port_get(handle->fd, &pe, &timeout);
126+
r = port_get(loop_->fs_fd, &pe, &timeout);
117127
}
118128
while (r == -1 && errno == EINTR);
119129

120130
if (r == -1 && errno == ETIME)
121131
break;
122-
132+
handle = (uv_fs_event_t *)pe.portev_user;
123133
assert((r == 0) && "unexpected port_get() error");
124134

125135
events = 0;
@@ -128,12 +138,12 @@ static void uv__fs_event_read(EV_P_ ev_io* w, int revents) {
128138
if (pe.portev_events & ~(FILE_ATTRIB | FILE_MODIFIED))
129139
events |= UV_RENAME;
130140
assert(events != 0);
131-
141+
handle->fd = PORT_FIRED;
132142
handle->cb(handle, NULL, events, 0);
133143
}
134-
while (handle->fd != -1);
144+
while (handle->fd != PORT_DELETED);
135145

136-
if (handle->fd != -1)
146+
if (handle->fd != PORT_DELETED)
137147
uv__fs_event_rearm(handle);
138148
}
139149

@@ -144,39 +154,45 @@ int uv_fs_event_init(uv_loop_t* loop,
144154
uv_fs_event_cb cb,
145155
int flags) {
146156
int portfd;
157+
int first_run = 0;
147158

148159
loop->counters.fs_event_init++;
149160

150161
/* We don't support any flags yet. */
151162
assert(!flags);
152-
153-
if ((portfd = port_create()) == -1) {
154-
uv__set_sys_error(loop, errno);
155-
return -1;
163+
if (loop->fs_fd == -1) {
164+
if ((portfd = port_create()) == -1) {
165+
uv__set_sys_error(loop, errno);
166+
return -1;
167+
}
168+
loop->fs_fd = portfd;
169+
first_run = 1;
156170
}
157171

158172
uv__handle_init(loop, (uv_handle_t*)handle, UV_FS_EVENT);
159173
handle->filename = strdup(filename);
160-
handle->fd = portfd;
174+
handle->fd = PORT_UNUSED;
161175
handle->cb = cb;
162176

163177
memset(&handle->fo, 0, sizeof handle->fo);
164178
handle->fo.fo_name = handle->filename;
165179
uv__fs_event_rearm(handle);
166180

167-
ev_io_init(&handle->event_watcher, uv__fs_event_read, portfd, EV_READ);
168-
ev_io_start(loop->ev, &handle->event_watcher);
169-
ev_unref(loop->ev);
181+
if (first_run) {
182+
ev_io_init(&loop->fs_event_watcher, uv__fs_event_read, portfd, EV_READ);
183+
ev_io_start(loop->ev, &loop->fs_event_watcher);
184+
ev_unref(loop->ev);
185+
}
170186

171187
return 0;
172188
}
173189

174190

175191
void uv__fs_event_destroy(uv_fs_event_t* handle) {
176-
ev_ref(handle->loop->ev);
177-
ev_io_stop(handle->loop->ev, &handle->event_watcher);
178-
uv__close(handle->fd);
179-
handle->fd = -1;
192+
if (handle->fd == PORT_FIRED) {
193+
port_dissociate(handle->loop->fs_fd, PORT_SOURCE_FILE, (uintptr_t)&handle->fo);
194+
}
195+
handle->fd = PORT_DELETED;
180196
free(handle->filename);
181197
handle->filename = NULL;
182198
handle->fo.fo_name = NULL;

deps/uv/src/win/fs.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,8 @@ void fs__open(uv_fs_t* req, const wchar_t* path, int flags, int mode) {
248248
goto end;
249249
}
250250

251-
/* Figure out whether path is a file or a directory. */
252-
if (GetFileAttributesW(path) & FILE_ATTRIBUTE_DIRECTORY) {
253-
attributes |= FILE_FLAG_BACKUP_SEMANTICS;
254-
}
251+
/* Setting this flag makes it possible to open a directory. */
252+
attributes |= FILE_FLAG_BACKUP_SEMANTICS;
255253

256254
file = CreateFileW(path,
257255
access,

0 commit comments

Comments
 (0)