mirror of https://github.com/lukechilds/node.git
Bert Belder
13 years ago
67 changed files with 1965 additions and 1327 deletions
@ -0,0 +1,58 @@ |
|||
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
|||
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|||
* of this software and associated documentation files (the "Software"), to |
|||
* deal in the Software without restriction, including without limitation the |
|||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
|||
* sell copies of the Software, and to permit persons to whom the Software is |
|||
* furnished to do so, subject to the following conditions: |
|||
* |
|||
* The above copyright notice and this permission notice shall be included in |
|||
* all copies or substantial portions of the Software. |
|||
* |
|||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
|||
* IN THE SOFTWARE. |
|||
*/ |
|||
|
|||
#include "uv.h" |
|||
#include "internal.h" |
|||
|
|||
|
|||
static void uv__async(EV_P_ ev_async* w, int revents) { |
|||
uv_async_t* async = container_of(w, uv_async_t, async_watcher); |
|||
|
|||
if (async->async_cb) { |
|||
async->async_cb(async, 0); |
|||
} |
|||
} |
|||
|
|||
|
|||
int uv_async_init(uv_loop_t* loop, uv_async_t* async, uv_async_cb async_cb) { |
|||
uv__handle_init(loop, (uv_handle_t*)async, UV_ASYNC); |
|||
loop->counters.async_init++; |
|||
|
|||
ev_async_init(&async->async_watcher, uv__async); |
|||
async->async_cb = async_cb; |
|||
|
|||
/* Note: This does not have symmetry with the other libev wrappers. */ |
|||
ev_async_start(loop->ev, &async->async_watcher); |
|||
ev_unref(loop->ev); |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
|
|||
int uv_async_send(uv_async_t* async) { |
|||
ev_async_send(async->loop->ev, &async->async_watcher); |
|||
return 0; |
|||
} |
|||
|
|||
|
|||
void uv__async_close(uv_async_t* handle) { |
|||
ev_async_stop(handle->loop->ev, &handle->async_watcher); |
|||
ev_ref(handle->loop->ev); |
|||
} |
@ -0,0 +1,80 @@ |
|||
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
|||
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|||
* of this software and associated documentation files (the "Software"), to |
|||
* deal in the Software without restriction, including without limitation the |
|||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
|||
* sell copies of the Software, and to permit persons to whom the Software is |
|||
* furnished to do so, subject to the following conditions: |
|||
* |
|||
* The above copyright notice and this permission notice shall be included in |
|||
* all copies or substantial portions of the Software. |
|||
* |
|||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
|||
* IN THE SOFTWARE. |
|||
*/ |
|||
|
|||
#include "uv.h" |
|||
#include "internal.h" |
|||
|
|||
|
|||
static void uv__check(EV_P_ ev_check* w, int revents) { |
|||
uv_check_t* check = container_of(w, uv_check_t, check_watcher); |
|||
|
|||
if (check->check_cb) { |
|||
check->check_cb(check, 0); |
|||
} |
|||
} |
|||
|
|||
|
|||
int uv_check_init(uv_loop_t* loop, uv_check_t* check) { |
|||
uv__handle_init(loop, (uv_handle_t*)check, UV_CHECK); |
|||
loop->counters.check_init++; |
|||
|
|||
ev_check_init(&check->check_watcher, uv__check); |
|||
check->check_cb = NULL; |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
|
|||
int uv_check_start(uv_check_t* check, uv_check_cb cb) { |
|||
int was_active = ev_is_active(&check->check_watcher); |
|||
|
|||
check->check_cb = cb; |
|||
|
|||
ev_check_start(check->loop->ev, &check->check_watcher); |
|||
|
|||
if (!was_active) { |
|||
ev_unref(check->loop->ev); |
|||
} |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
|
|||
int uv_check_stop(uv_check_t* check) { |
|||
int was_active = ev_is_active(&check->check_watcher); |
|||
|
|||
ev_check_stop(check->loop->ev, &check->check_watcher); |
|||
|
|||
if (was_active) { |
|||
ev_ref(check->loop->ev); |
|||
} |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
|
|||
int uv__check_active(const uv_check_t* handle) { |
|||
return ev_is_active(&handle->check_watcher); |
|||
} |
|||
|
|||
|
|||
void uv__check_close(uv_check_t* handle) { |
|||
uv_check_stop(handle); |
|||
} |
@ -0,0 +1,79 @@ |
|||
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
|||
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|||
* of this software and associated documentation files (the "Software"), to |
|||
* deal in the Software without restriction, including without limitation the |
|||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
|||
* sell copies of the Software, and to permit persons to whom the Software is |
|||
* furnished to do so, subject to the following conditions: |
|||
* |
|||
* The above copyright notice and this permission notice shall be included in |
|||
* all copies or substantial portions of the Software. |
|||
* |
|||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
|||
* IN THE SOFTWARE. |
|||
*/ |
|||
|
|||
#include "uv.h" |
|||
#include "internal.h" |
|||
|
|||
|
|||
static void uv__idle(EV_P_ ev_idle* w, int revents) { |
|||
uv_idle_t* idle = container_of(w, uv_idle_t, idle_watcher); |
|||
|
|||
if (idle->idle_cb) { |
|||
idle->idle_cb(idle, 0); |
|||
} |
|||
} |
|||
|
|||
|
|||
int uv_idle_init(uv_loop_t* loop, uv_idle_t* idle) { |
|||
uv__handle_init(loop, (uv_handle_t*)idle, UV_IDLE); |
|||
loop->counters.idle_init++; |
|||
|
|||
ev_idle_init(&idle->idle_watcher, uv__idle); |
|||
idle->idle_cb = NULL; |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
|
|||
int uv_idle_start(uv_idle_t* idle, uv_idle_cb cb) { |
|||
int was_active = ev_is_active(&idle->idle_watcher); |
|||
|
|||
idle->idle_cb = cb; |
|||
ev_idle_start(idle->loop->ev, &idle->idle_watcher); |
|||
|
|||
if (!was_active) { |
|||
ev_unref(idle->loop->ev); |
|||
} |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
|
|||
int uv_idle_stop(uv_idle_t* idle) { |
|||
int was_active = ev_is_active(&idle->idle_watcher); |
|||
|
|||
ev_idle_stop(idle->loop->ev, &idle->idle_watcher); |
|||
|
|||
if (was_active) { |
|||
ev_ref(idle->loop->ev); |
|||
} |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
|
|||
int uv__idle_active(const uv_idle_t* handle) { |
|||
return ev_is_active(&handle->idle_watcher); |
|||
} |
|||
|
|||
|
|||
void uv__idle_close(uv_idle_t* handle) { |
|||
uv_idle_stop(handle); |
|||
} |
@ -0,0 +1,230 @@ |
|||
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
|||
* |
|||
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|||
* of this software and associated documentation files (the "Software"), to |
|||
* deal in the Software without restriction, including without limitation the |
|||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
|||
* sell copies of the Software, and to permit persons to whom the Software is |
|||
* furnished to do so, subject to the following conditions: |
|||
* |
|||
* The above copyright notice and this permission notice shall be included in |
|||
* all copies or substantial portions of the Software. |
|||
* |
|||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
|||
* IN THE SOFTWARE. |
|||
*/ |
|||
|
|||
#include "syscalls.h" |
|||
#include <unistd.h> |
|||
#include <sys/syscall.h> |
|||
#include <sys/types.h> |
|||
#include <errno.h> |
|||
|
|||
#if __i386__ |
|||
# ifndef __NR_socketcall |
|||
# define __NR_socketcall 102 |
|||
# endif |
|||
#endif |
|||
|
|||
#if __arm__ |
|||
# if __thumb__ || __ARM_EABI__ |
|||
# define UV_SYSCALL_BASE 0 |
|||
# else |
|||
# define UV_SYSCALL_BASE 0x900000 |
|||
# endif |
|||
#endif /* __arm__ */ |
|||
|
|||
#ifndef __NR_accept4 |
|||
# if __x86_64__ |
|||
# define __NR_accept4 288 |
|||
# elif __i386__ |
|||
/* Nothing. Handled through socketcall(). */ |
|||
# elif __arm__ |
|||
# define __NR_accept4 (UV_SYSCALL_BASE + 366) |
|||
# endif |
|||
#endif /* __NR_accept4 */ |
|||
|
|||
#ifndef __NR_inotify_init |
|||
# if __x86_64__ |
|||
# define __NR_inotify_init 253 |
|||
# elif __i386__ |
|||
# define __NR_inotify_init 291 |
|||
# elif __arm__ |
|||
# define __NR_inotify_init (UV_SYSCALL_BASE + 316) |
|||
# endif |
|||
#endif /* __NR_inotify_init */ |
|||
|
|||
#ifndef __NR_inotify_init1 |
|||
# if __x86_64__ |
|||
# define __NR_inotify_init1 294 |
|||
# elif __i386__ |
|||
# define __NR_inotify_init1 332 |
|||
# elif __arm__ |
|||
# define __NR_inotify_init1 (UV_SYSCALL_BASE + 360) |
|||
# endif |
|||
#endif /* __NR_inotify_init1 */ |
|||
|
|||
#ifndef __NR_inotify_add_watch |
|||
# if __x86_64__ |
|||
# define __NR_inotify_add_watch 254 |
|||
# elif __i386__ |
|||
# define __NR_inotify_add_watch 292 |
|||
# elif __arm__ |
|||
# define __NR_inotify_add_watch (UV_SYSCALL_BASE + 317) |
|||
# endif |
|||
#endif /* __NR_inotify_add_watch */ |
|||
|
|||
#ifndef __NR_inotify_rm_watch |
|||
# if __x86_64__ |
|||
# define __NR_inotify_rm_watch 255 |
|||
# elif __i386__ |
|||
# define __NR_inotify_rm_watch 293 |
|||
# elif __arm__ |
|||
# define __NR_inotify_rm_watch (UV_SYSCALL_BASE + 318) |
|||
# endif |
|||
#endif /* __NR_inotify_rm_watch */ |
|||
|
|||
#ifndef __NR_pipe2 |
|||
# if __x86_64__ |
|||
# define __NR_pipe2 293 |
|||
# elif __i386__ |
|||
# define __NR_pipe2 331 |
|||
# elif __arm__ |
|||
# define __NR_pipe2 (UV_SYSCALL_BASE + 359) |
|||
# endif |
|||
#endif /* __NR_pipe2 */ |
|||
|
|||
#ifndef __NR_recvmmsg |
|||
# if __x86_64__ |
|||
# define __NR_recvmmsg 299 |
|||
# elif __i386__ |
|||
# define __NR_recvmmsg 337 |
|||
# elif __arm__ |
|||
# define __NR_recvmmsg (UV_SYSCALL_BASE + 365) |
|||
# endif |
|||
#endif /* __NR_recvmsg */ |
|||
|
|||
#ifndef __NR_sendmmsg |
|||
# if __x86_64__ |
|||
# define __NR_sendmmsg 307 |
|||
# elif __i386__ |
|||
# define __NR_sendmmsg 345 |
|||
# elif __arm__ |
|||
# define __NR_recvmmsg (UV_SYSCALL_BASE + 374) |
|||
# endif |
|||
#endif /* __NR_sendmmsg */ |
|||
|
|||
#ifndef __NR_utimensat |
|||
# if __x86_64__ |
|||
# define __NR_utimensat 280 |
|||
# elif __i386__ |
|||
# define __NR_utimensat 320 |
|||
# elif __arm__ |
|||
# define __NR_utimensat (UV_SYSCALL_BASE + 348) |
|||
# endif |
|||
#endif /* __NR_utimensat */ |
|||
|
|||
|
|||
int uv__accept4(int fd, struct sockaddr* addr, socklen_t* addrlen, int flags) { |
|||
#if __i386__ |
|||
unsigned long args[] = { |
|||
(unsigned long) fd, |
|||
(unsigned long) addr, |
|||
(unsigned long) addrlen, |
|||
(unsigned long) flags |
|||
}; |
|||
return syscall(__NR_socketcall, 18 /* SYS_ACCEPT4 */, args); |
|||
#elif __NR_accept4 |
|||
return syscall(__NR_accept4, fd, addr, addrlen, flags); |
|||
#else |
|||
return errno = ENOSYS, -1; |
|||
#endif |
|||
} |
|||
|
|||
|
|||
int uv__inotify_init(void) { |
|||
#if __NR_inotify_init |
|||
return syscall(__NR_inotify_init); |
|||
#else |
|||
return errno = ENOSYS, -1; |
|||
#endif |
|||
} |
|||
|
|||
|
|||
int uv__inotify_init1(int flags) { |
|||
#if __NR_inotify_init1 |
|||
return syscall(__NR_inotify_init1, flags); |
|||
#else |
|||
return errno = ENOSYS, -1; |
|||
#endif |
|||
} |
|||
|
|||
|
|||
int uv__inotify_add_watch(int fd, const char* path, __u32 mask) { |
|||
#if __NR_inotify_add_watch |
|||
return syscall(__NR_inotify_add_watch, fd, path, mask); |
|||
#else |
|||
return errno = ENOSYS, -1; |
|||
#endif |
|||
} |
|||
|
|||
|
|||
int uv__inotify_rm_watch(int fd, __s32 wd) { |
|||
#if __NR_inotify_rm_watch |
|||
return syscall(__NR_inotify_rm_watch, fd, wd); |
|||
#else |
|||
return errno = ENOSYS, -1; |
|||
#endif |
|||
} |
|||
|
|||
|
|||
int uv__pipe2(int pipefd[2], int flags) { |
|||
#if __NR_pipe2 |
|||
return syscall(__NR_pipe2, pipefd, flags); |
|||
#else |
|||
return errno = ENOSYS, -1; |
|||
#endif |
|||
} |
|||
|
|||
|
|||
int uv__sendmmsg(int fd, |
|||
struct uv__mmsghdr* mmsg, |
|||
unsigned int vlen, |
|||
unsigned int flags) { |
|||
#if __NR_sendmmsg |
|||
return syscall(__NR_sendmmsg, fd, mmsg, vlen, flags); |
|||
#else |
|||
return errno = ENOSYS, -1; |
|||
#endif |
|||
} |
|||
|
|||
|
|||
int uv__recvmmsg(int fd, |
|||
struct uv__mmsghdr* mmsg, |
|||
unsigned int vlen, |
|||
unsigned int flags, |
|||
struct timespec* timeout) { |
|||
#if __NR_recvmmsg |
|||
return syscall(__NR_recvmmsg, fd, mmsg, vlen, flags, timeout); |
|||
#else |
|||
return errno = ENOSYS, -1; |
|||
#endif |
|||
} |
|||
|
|||
|
|||
int uv__utimesat(int dirfd, |
|||
const char* path, |
|||
const struct timespec times[2], |
|||
int flags) |
|||
{ |
|||
#if __NR_utimensat |
|||
return syscall(__NR_utimensat, dirfd, path, times, flags); |
|||
#else |
|||
return errno = ENOSYS, -1; |
|||
#endif |
|||
} |
@ -0,0 +1,87 @@ |
|||
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
|||
* |
|||
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|||
* of this software and associated documentation files (the "Software"), to |
|||
* deal in the Software without restriction, including without limitation the |
|||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
|||
* sell copies of the Software, and to permit persons to whom the Software is |
|||
* furnished to do so, subject to the following conditions: |
|||
* |
|||
* The above copyright notice and this permission notice shall be included in |
|||
* all copies or substantial portions of the Software. |
|||
* |
|||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
|||
* IN THE SOFTWARE. |
|||
*/ |
|||
|
|||
#ifndef UV_LINUX_SYSCALL_H_ |
|||
#define UV_LINUX_SYSCALL_H_ |
|||
|
|||
#undef _GNU_SOURCE |
|||
#define _GNU_SOURCE |
|||
|
|||
#include <sys/types.h> |
|||
#include <sys/socket.h> |
|||
#include <linux/types.h> |
|||
|
|||
#define UV__O_NONBLOCK 0x800 |
|||
#define UV__O_CLOEXEC 0x80000 |
|||
|
|||
#define UV__SOCK_CLOEXEC UV__O_CLOEXEC |
|||
#define UV__SOCK_NONBLOCK UV__O_NONBLOCK |
|||
|
|||
#define UV__IN_CLOEXEC UV__O_CLOEXEC |
|||
#define UV__IN_NONBLOCK UV__O_NONBLOCK |
|||
|
|||
#define UV__IN_ACCESS 0x001 |
|||
#define UV__IN_MODIFY 0x002 |
|||
#define UV__IN_ATTRIB 0x004 |
|||
#define UV__IN_CLOSE_WRITE 0x008 |
|||
#define UV__IN_CLOSE_NOWRITE 0x010 |
|||
#define UV__IN_OPEN 0x020 |
|||
#define UV__IN_MOVED_FROM 0x040 |
|||
#define UV__IN_MOVED_TO 0x080 |
|||
#define UV__IN_CREATE 0x100 |
|||
#define UV__IN_DELETE 0x200 |
|||
#define UV__IN_DELETE_SELF 0x400 |
|||
#define UV__IN_MOVE_SELF 0x800 |
|||
|
|||
struct uv__inotify_event { |
|||
__s32 wd; |
|||
__u32 mask; |
|||
__u32 cookie; |
|||
__u32 len; |
|||
/* char name[0]; */ |
|||
}; |
|||
|
|||
struct uv__mmsghdr { |
|||
struct msghdr msg_hdr; |
|||
unsigned int msg_len; |
|||
}; |
|||
|
|||
int uv__accept4(int fd, struct sockaddr* addr, socklen_t* addrlen, int flags); |
|||
int uv__inotify_init(void); |
|||
int uv__inotify_init1(int flags); |
|||
int uv__inotify_add_watch(int fd, const char* path, __u32 mask); |
|||
int uv__inotify_rm_watch(int fd, __s32 wd); |
|||
int uv__pipe2(int pipefd[2], int flags); |
|||
int uv__recvmmsg(int fd, |
|||
struct uv__mmsghdr* mmsg, |
|||
unsigned int vlen, |
|||
unsigned int flags, |
|||
struct timespec* timeout); |
|||
int uv__sendmmsg(int fd, |
|||
struct uv__mmsghdr* mmsg, |
|||
unsigned int vlen, |
|||
unsigned int flags); |
|||
int uv__utimesat(int dirfd, |
|||
const char* path, |
|||
const struct timespec times[2], |
|||
int flags); |
|||
|
|||
#endif /* UV_LINUX_SYSCALL_H_ */ |
@ -0,0 +1,58 @@ |
|||
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
|||
* |
|||
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|||
* of this software and associated documentation files (the "Software"), to |
|||
* deal in the Software without restriction, including without limitation the |
|||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
|||
* sell copies of the Software, and to permit persons to whom the Software is |
|||
* furnished to do so, subject to the following conditions: |
|||
* |
|||
* The above copyright notice and this permission notice shall be included in |
|||
* all copies or substantial portions of the Software. |
|||
* |
|||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
|||
* IN THE SOFTWARE. |
|||
*/ |
|||
|
|||
#include "uv.h" |
|||
#include "tree.h" |
|||
#include "internal.h" |
|||
#include <stdlib.h> |
|||
#include <string.h> |
|||
#include <unistd.h> |
|||
|
|||
|
|||
int uv__loop_init(uv_loop_t* loop, int default_loop) { |
|||
#if HAVE_KQUEUE |
|||
int flags = EVBACKEND_KQUEUE; |
|||
#else |
|||
int flags = EVFLAG_AUTO; |
|||
#endif |
|||
RB_INIT(&loop->uv_ares_handles_); |
|||
loop->endgame_handles = NULL; |
|||
loop->ev = (default_loop ? ev_default_loop : ev_loop_new)(flags); |
|||
ev_set_userdata(loop->ev, loop); |
|||
eio_channel_init(&loop->uv_eio_channel, loop); |
|||
#if __linux__ |
|||
RB_INIT(&loop->inotify_watchers); |
|||
loop->inotify_fd = -1; |
|||
#endif |
|||
return 0; |
|||
} |
|||
|
|||
|
|||
void uv__loop_delete(uv_loop_t* loop) { |
|||
uv_ares_destroy(loop, loop->channel); |
|||
ev_loop_destroy(loop->ev); |
|||
#if __linux__ |
|||
if (loop->inotify_fd == -1) return; |
|||
ev_io_stop(loop->ev, &loop->inotify_read_watcher); |
|||
close(loop->inotify_fd); |
|||
loop->inotify_fd = -1; |
|||
#endif |
|||
} |
@ -0,0 +1,79 @@ |
|||
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
|||
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|||
* of this software and associated documentation files (the "Software"), to |
|||
* deal in the Software without restriction, including without limitation the |
|||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
|||
* sell copies of the Software, and to permit persons to whom the Software is |
|||
* furnished to do so, subject to the following conditions: |
|||
* |
|||
* The above copyright notice and this permission notice shall be included in |
|||
* all copies or substantial portions of the Software. |
|||
* |
|||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
|||
* IN THE SOFTWARE. |
|||
*/ |
|||
|
|||
#include "uv.h" |
|||
#include "internal.h" |
|||
|
|||
|
|||
static void uv__prepare(EV_P_ ev_prepare* w, int revents) { |
|||
uv_prepare_t* prepare = container_of(w, uv_prepare_t, prepare_watcher); |
|||
|
|||
if (prepare->prepare_cb) { |
|||
prepare->prepare_cb(prepare, 0); |
|||
} |
|||
} |
|||
|
|||
|
|||
int uv_prepare_init(uv_loop_t* loop, uv_prepare_t* prepare) { |
|||
uv__handle_init(loop, (uv_handle_t*)prepare, UV_PREPARE); |
|||
loop->counters.prepare_init++; |
|||
|
|||
ev_prepare_init(&prepare->prepare_watcher, uv__prepare); |
|||
prepare->prepare_cb = NULL; |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
|
|||
int uv_prepare_start(uv_prepare_t* prepare, uv_prepare_cb cb) { |
|||
int was_active = ev_is_active(&prepare->prepare_watcher); |
|||
|
|||
prepare->prepare_cb = cb; |
|||
|
|||
ev_prepare_start(prepare->loop->ev, &prepare->prepare_watcher); |
|||
|
|||
if (!was_active) { |
|||
ev_unref(prepare->loop->ev); |
|||
} |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
|
|||
int uv_prepare_stop(uv_prepare_t* prepare) { |
|||
int was_active = ev_is_active(&prepare->prepare_watcher); |
|||
|
|||
ev_prepare_stop(prepare->loop->ev, &prepare->prepare_watcher); |
|||
|
|||
if (was_active) { |
|||
ev_ref(prepare->loop->ev); |
|||
} |
|||
return 0; |
|||
} |
|||
|
|||
|
|||
int uv__prepare_active(const uv_prepare_t* handle) { |
|||
return ev_is_active(&handle->prepare_watcher); |
|||
} |
|||
|
|||
|
|||
void uv__prepare_close(uv_prepare_t* handle) { |
|||
uv_prepare_stop(handle); |
|||
} |
@ -0,0 +1,127 @@ |
|||
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
|||
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|||
* of this software and associated documentation files (the "Software"), to |
|||
* deal in the Software without restriction, including without limitation the |
|||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
|||
* sell copies of the Software, and to permit persons to whom the Software is |
|||
* furnished to do so, subject to the following conditions: |
|||
* |
|||
* The above copyright notice and this permission notice shall be included in |
|||
* all copies or substantial portions of the Software. |
|||
* |
|||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
|||
* IN THE SOFTWARE. |
|||
*/ |
|||
|
|||
#include "uv.h" |
|||
#include "internal.h" |
|||
#include <assert.h> |
|||
|
|||
|
|||
static int uv__timer_repeating(const uv_timer_t* timer) { |
|||
return timer->flags & UV_TIMER_REPEAT; |
|||
} |
|||
|
|||
|
|||
static void uv__timer_cb(EV_P_ ev_timer* w, int revents) { |
|||
uv_timer_t* timer = container_of(w, uv_timer_t, timer_watcher); |
|||
|
|||
assert(uv__timer_active(timer)); |
|||
|
|||
if (!uv__timer_repeating(timer)) { |
|||
timer->flags &= ~UV_TIMER_ACTIVE; |
|||
ev_ref(EV_A); |
|||
} |
|||
|
|||
if (timer->timer_cb) { |
|||
timer->timer_cb(timer, 0); |
|||
} |
|||
} |
|||
|
|||
|
|||
int uv_timer_init(uv_loop_t* loop, uv_timer_t* timer) { |
|||
uv__handle_init(loop, (uv_handle_t*)timer, UV_TIMER); |
|||
loop->counters.timer_init++; |
|||
|
|||
ev_init(&timer->timer_watcher, uv__timer_cb); |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
|
|||
int uv_timer_start(uv_timer_t* timer, uv_timer_cb cb, int64_t timeout, |
|||
int64_t repeat) { |
|||
if (uv__timer_active(timer)) { |
|||
return -1; |
|||
} |
|||
|
|||
timer->timer_cb = cb; |
|||
timer->flags |= UV_TIMER_ACTIVE; |
|||
|
|||
if (repeat) |
|||
timer->flags |= UV_TIMER_REPEAT; |
|||
else |
|||
timer->flags &= ~UV_TIMER_REPEAT; |
|||
|
|||
ev_timer_set(&timer->timer_watcher, timeout / 1000.0, repeat / 1000.0); |
|||
ev_timer_start(timer->loop->ev, &timer->timer_watcher); |
|||
ev_unref(timer->loop->ev); |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
|
|||
int uv_timer_stop(uv_timer_t* timer) { |
|||
if (uv__timer_active(timer)) { |
|||
ev_ref(timer->loop->ev); |
|||
} |
|||
|
|||
timer->flags &= ~(UV_TIMER_ACTIVE | UV_TIMER_REPEAT); |
|||
ev_timer_stop(timer->loop->ev, &timer->timer_watcher); |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
|
|||
int uv_timer_again(uv_timer_t* timer) { |
|||
if (!uv__timer_active(timer)) { |
|||
uv__set_artificial_error(timer->loop, UV_EINVAL); |
|||
return -1; |
|||
} |
|||
|
|||
assert(uv__timer_repeating(timer)); |
|||
ev_timer_again(timer->loop->ev, &timer->timer_watcher); |
|||
return 0; |
|||
} |
|||
|
|||
|
|||
void uv_timer_set_repeat(uv_timer_t* timer, int64_t repeat) { |
|||
assert(timer->type == UV_TIMER); |
|||
timer->timer_watcher.repeat = repeat / 1000.0; |
|||
|
|||
if (repeat) |
|||
timer->flags |= UV_TIMER_REPEAT; |
|||
else |
|||
timer->flags &= ~UV_TIMER_REPEAT; |
|||
} |
|||
|
|||
|
|||
int64_t uv_timer_get_repeat(uv_timer_t* timer) { |
|||
assert(timer->type == UV_TIMER); |
|||
return (int64_t)(1000 * timer->timer_watcher.repeat); |
|||
} |
|||
|
|||
|
|||
int uv__timer_active(const uv_timer_t* timer) { |
|||
return timer->flags & UV_TIMER_ACTIVE; |
|||
} |
|||
|
|||
|
|||
void uv__timer_close(uv_timer_t* handle) { |
|||
uv_timer_stop(handle); |
|||
} |
Loading…
Reference in new issue