Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

win: multiplicity

  • Loading branch information...
piscisaureus committed Aug 31, 2011
1 parent 3aec77f commit 78debf9f673f181cd1207e19af84f58e673cb0dd
Showing with 1,095 additions and 824 deletions.
  1. +38 −2 include/uv-win.h
  2. +48 −29 include/uv.h
  3. +14 −10 src/win/async.c
  4. +64 −64 src/win/cares.c
  5. +59 −49 src/win/core.c
  6. +17 −13 src/win/error.c
  7. +141 −99 src/win/fs.c
  8. +61 −36 src/win/getaddrinfo.c
  9. +30 −26 src/win/handle.c
  10. +69 −97 src/win/internal.h
  11. +21 −17 src/win/loop-watcher.c
  12. +137 −111 src/win/pipe.c
  13. +72 −39 src/win/process.c
  14. +41 −34 src/win/req.c
  15. +5 −5 src/win/stdio.c
  16. +19 −13 src/win/stream.c
  17. +113 −81 src/win/tcp.c
  18. +13 −9 src/win/threadpool.c
  19. +44 −36 src/win/timer.c
  20. +69 −48 src/win/udp.c
  21. +20 −6 src/win/util.c
@@ -44,6 +44,40 @@ typedef struct uv_buf_t {

typedef int uv_file;

RB_HEAD(uv_timer_tree_s, uv_timer_s);

#define UV_LOOP_PRIVATE_FIELDS \
/* The loop's I/O completion port */ \
HANDLE iocp; \
/* Reference count that keeps the event loop alive */ \
int refs; \
/* The current time according to the event loop. in msecs. */ \
int64_t time; \
/* Tail of a single-linked circular queue of pending reqs. If the queue */ \
/* is empty, tail_ is NULL. If there is only one item, */ \
/* tail_->next_req == tail_ */ \
uv_req_t* pending_reqs_tail; \
/* Head of a single-linked list of closed handles */ \
uv_handle_t* endgame_handles; \
/* The head of the timers tree */ \
struct uv_timer_tree_s timers; \
/* Lists of active loop (prepare / check / idle) watchers */ \
uv_prepare_t* prepare_handles; \
uv_check_t* check_handles; \
uv_idle_t* idle_handles; \
/* This pointer will refer to the prepare/check/idle handle whose */ \
/* callback is scheduled to be called next. This is needed to allow */ \
/* safe removal from one of the lists above while that list being */ \
/* iterated over. */ \
uv_prepare_t* next_prepare_handle; \
uv_check_t* next_check_handle; \
uv_idle_t* next_idle_handle; \
ares_channel ares_channel; \
int ares_active_sockets; \
uv_timer_t ares_polling_timer; \
/* Last error code */ \
uv_err_t last_error;

#define UV_REQ_TYPE_PRIVATE \
/* TODO: remove the req suffix */ \
UV_ARES_EVENT_REQ, \
@@ -227,5 +261,7 @@ typedef int uv_file;

#define UV_WORK_PRIVATE_FIELDS \

int uv_utf16_to_utf8(const wchar_t* utf16Buffer, size_t utf16Size, char* utf8Buffer, size_t utf8Size);
int uv_utf8_to_utf16(const char* utf8Buffer, wchar_t* utf16Buffer, size_t utf16Size);
int uv_utf16_to_utf8(const wchar_t* utf16Buffer, size_t utf16Size,
char* utf8Buffer, size_t utf8Size);
int uv_utf8_to_utf16(const char* utf8Buffer, wchar_t* utf16Buffer,
size_t utf16Size);
@@ -86,7 +86,7 @@ uv_loop_t* uv_loop_new();

void uv_loop_delete(uv_loop_t*);

/*
/*
* Returns the default loop.
*/
uv_loop_t* uv_default_loop();
@@ -130,7 +130,8 @@ typedef void (*uv_async_cb)(uv_async_t* handle, int status);
typedef void (*uv_prepare_cb)(uv_prepare_t* handle, int status);
typedef void (*uv_check_cb)(uv_check_t* handle, int status);
typedef void (*uv_idle_cb)(uv_idle_t* handle, int status);
typedef void (*uv_getaddrinfo_cb)(uv_getaddrinfo_t* handle, int status, struct addrinfo* res);
typedef void (*uv_getaddrinfo_cb)(uv_getaddrinfo_t* handle, int status,
struct addrinfo* res);
typedef void (*uv_exit_cb)(uv_process_t*, int exit_status, int term_signal);
typedef void (*uv_fs_cb)(uv_fs_t* req);
typedef void (*uv_work_cb)(uv_work_t* req);
@@ -237,7 +238,6 @@ const char* uv_err_name(uv_err_t err);

#define UV_REQ_FIELDS \
/* read-only */ \
uv_loop_t* loop; \
uv_req_type type; \
/* public */ \
void* data; \
@@ -825,13 +825,14 @@ int uv_process_kill(uv_process_t*, int signum);
*/
struct uv_work_s {
UV_REQ_FIELDS
uv_loop_t* loop;
uv_work_cb work_cb;
uv_after_work_cb after_work_cb;
UV_WORK_PRIVATE_FIELDS
};

/* Queues a work request to execute asynchronously on the thread pool. */
int uv_queue_work(uv_work_t* req, uv_work_cb work_cb,
int uv_queue_work(uv_loop_t* loop, uv_work_t* req, uv_work_cb work_cb,
uv_after_work_cb after_work_cb);


@@ -870,6 +871,7 @@ typedef enum {
*/
struct uv_fs_s {
UV_REQ_FIELDS
uv_loop_t* loop;
uv_fs_type fs_type;
uv_fs_cb cb;
ssize_t result;
@@ -879,31 +881,48 @@ struct uv_fs_s {
};

void uv_fs_req_cleanup(uv_fs_t* req);
int uv_fs_close(uv_fs_t* req, uv_file file, uv_fs_cb cb);
int uv_fs_open(uv_fs_t* req, const char* path, int flags, int mode, uv_fs_cb cb);
int uv_fs_read(uv_fs_t* req, uv_file file, void* buf, size_t length, off_t offset, uv_fs_cb cb);
int uv_fs_unlink(uv_fs_t* req, const char* path, uv_fs_cb cb);
int uv_fs_write(uv_fs_t* req, uv_file file, void* buf, size_t length, off_t offset, uv_fs_cb cb);
int uv_fs_mkdir(uv_fs_t* req, const char* path, int mode, uv_fs_cb cb);
int uv_fs_rmdir(uv_fs_t* req, const char* path, uv_fs_cb cb);
int uv_fs_readdir(uv_fs_t* req, const char* path, int flags, uv_fs_cb cb);
int uv_fs_stat(uv_fs_t* req, const char* path, uv_fs_cb cb);
int uv_fs_fstat(uv_fs_t* req, uv_file file, uv_fs_cb cb);
int uv_fs_rename(uv_fs_t* req, const char* path, const char* new_path, uv_fs_cb cb);
int uv_fs_fsync(uv_fs_t* req, uv_file file, uv_fs_cb cb);
int uv_fs_fdatasync(uv_fs_t* req, uv_file file, uv_fs_cb cb);
int uv_fs_ftruncate(uv_fs_t* req, uv_file file, off_t offset, uv_fs_cb cb);
int uv_fs_sendfile(uv_fs_t* req, uv_file out_fd, uv_file in_fd, off_t in_offset, size_t length, uv_fs_cb cb);
int uv_fs_chmod(uv_fs_t* req, const char* path, int mode, uv_fs_cb cb);
int uv_fs_utime(uv_fs_t* req, const char* path, double atime, double mtime, uv_fs_cb cb);
int uv_fs_futime(uv_fs_t* req, uv_file file, double atime, double mtime, uv_fs_cb cb);
int uv_fs_lstat(uv_fs_t* req, const char* path, uv_fs_cb cb);
int uv_fs_link(uv_fs_t* req, const char* path, const char* new_path, uv_fs_cb cb);
int uv_fs_symlink(uv_fs_t* req, const char* path, const char* new_path, uv_fs_cb cb);
int uv_fs_readlink(uv_fs_t* req, const char* path, uv_fs_cb cb);
int uv_fs_fchmod(uv_fs_t* req, uv_file file, int mode, uv_fs_cb cb);
int uv_fs_chown(uv_fs_t* req, const char* path, int uid, int gid, uv_fs_cb cb);
int uv_fs_fchown(uv_fs_t* req, uv_file file, int uid, int gid, uv_fs_cb cb);
int uv_fs_close(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb);
int uv_fs_open(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags,
int mode, uv_fs_cb cb);
int uv_fs_read(uv_loop_t* loop, uv_fs_t* req, uv_file file, void* buf,
size_t length, off_t offset, uv_fs_cb cb);
int uv_fs_unlink(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb);
int uv_fs_write(uv_loop_t* loop, uv_fs_t* req, uv_file file, void* buf,
size_t length, off_t offset, uv_fs_cb cb);
int uv_fs_mkdir(uv_loop_t* loop, uv_fs_t* req, const char* path, int mode,
uv_fs_cb cb);
int uv_fs_rmdir(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb);
int uv_fs_readdir(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags,
uv_fs_cb cb);
int uv_fs_stat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb);
int uv_fs_fstat(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb);
int uv_fs_rename(uv_loop_t* loop, uv_fs_t* req, const char* path,
const char* new_path, uv_fs_cb cb);
int uv_fs_fsync(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb);
int uv_fs_fdatasync(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb);
int uv_fs_ftruncate(uv_loop_t* loop, uv_fs_t* req, uv_file file,
off_t offset, uv_fs_cb cb);
int uv_fs_sendfile(uv_loop_t* loop, uv_fs_t* req, uv_file out_fd,
uv_file in_fd, off_t in_offset, size_t length, uv_fs_cb cb);
int uv_fs_chmod(uv_loop_t* loop, uv_fs_t* req, const char* path, int mode,
uv_fs_cb cb);
int uv_fs_utime(uv_loop_t* loop, uv_fs_t* req, const char* path, double atime,
double mtime, uv_fs_cb cb);
int uv_fs_futime(uv_loop_t* loop, uv_fs_t* req, uv_file file, double atime,
double mtime, uv_fs_cb cb);
int uv_fs_lstat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb);
int uv_fs_link(uv_loop_t* loop, uv_fs_t* req, const char* path,
const char* new_path, uv_fs_cb cb);
int uv_fs_symlink(uv_loop_t* loop, uv_fs_t* req, const char* path,
const char* new_path, uv_fs_cb cb);
int uv_fs_readlink(uv_loop_t* loop, uv_fs_t* req, const char* path,
uv_fs_cb cb);
int uv_fs_fchmod(uv_loop_t* loop, uv_fs_t* req, uv_file file, int mode,
uv_fs_cb cb);
int uv_fs_chown(uv_loop_t* loop, uv_fs_t* req, const char* path, int uid,
int gid, uv_fs_cb cb);
int uv_fs_fchown(uv_loop_t* loop, uv_fs_t* req, uv_file file, int uid,
int gid, uv_fs_cb cb);


/* Utility */
@@ -54,7 +54,7 @@ static inline char uv_atomic_exchange_set(char volatile* target) {
#endif


void uv_async_endgame(uv_async_t* handle) {
void uv_async_endgame(uv_loop_t* loop, uv_async_t* handle) {
if (handle->flags & UV_HANDLE_CLOSING &&
!handle->async_sent) {
assert(!(handle->flags & UV_HANDLE_CLOSED));
@@ -64,34 +64,37 @@ void uv_async_endgame(uv_async_t* handle) {
handle->close_cb((uv_handle_t*)handle);
}

uv_unref();
uv_unref(loop);
}
}


int uv_async_init(uv_async_t* handle, uv_async_cb async_cb) {
int uv_async_init(uv_loop_t* loop, uv_async_t* handle, uv_async_cb async_cb) {
uv_req_t* req;

uv_counters()->handle_init++;
uv_counters()->async_init++;
loop->counters.handle_init++;
loop->counters.async_init++;

handle->type = UV_ASYNC;
handle->loop = loop;
handle->flags = 0;
handle->async_sent = 0;
handle->async_cb = async_cb;

req = &handle->async_req;
uv_req_init(req);
uv_req_init(loop, req);
req->type = UV_WAKEUP;
req->data = handle;

uv_ref();
uv_ref(loop);

return 0;
}


int uv_async_send(uv_async_t* handle) {
uv_loop_t* loop = handle->loop;

if (handle->type != UV_ASYNC) {
/* Can't set errno because that's not thread-safe. */
return -1;
@@ -102,14 +105,15 @@ int uv_async_send(uv_async_t* handle) {
assert(!(handle->flags & UV_HANDLE_CLOSING));

if (!uv_atomic_exchange_set(&handle->async_sent)) {
POST_COMPLETION_FOR_REQ(&handle->async_req);
POST_COMPLETION_FOR_REQ(loop, &handle->async_req);
}

return 0;
}


void uv_process_async_wakeup_req(uv_async_t* handle, uv_req_t* req) {
void uv_process_async_wakeup_req(uv_loop_t* loop, uv_async_t* handle,
uv_req_t* req) {
assert(handle->type == UV_ASYNC);
assert(req->type == UV_WAKEUP);

@@ -118,6 +122,6 @@ void uv_process_async_wakeup_req(uv_async_t* handle, uv_req_t* req) {
handle->async_cb((uv_async_t*) handle, 0);
}
if (handle->flags & UV_HANDLE_CLOSING) {
uv_want_endgame((uv_handle_t*)handle);
uv_want_endgame(loop, (uv_handle_t*)handle);
}
}

0 comments on commit 78debf9

Please sign in to comment.
You can’t perform that action at this time.