Permalink
Browse files

uv_fs & uv_work APIs

  • Loading branch information...
1 parent 39aac4a commit 0e322fa0977c146ad957846ced35f0b632de9a32 Igor Zinkovsky committed Aug 19, 2011
Showing with 1,674 additions and 0 deletions.
  1. +5 −0 include/uv-unix.h
  2. +19 −0 include/uv-win.h
  3. +94 −0 include/uv.h
  4. +155 −0 src/uv-unix.c
  5. +3 −0 src/win/core.c
  6. +732 −0 src/win/fs.c
  7. +13 −0 src/win/internal.h
  8. +8 −0 src/win/req.c
  9. +69 −0 src/win/threadpool.c
  10. +501 −0 test/test-fs.c
  11. +12 −0 test/test-list.h
  12. +59 −0 test/test-threadpool.c
  13. +4 −0 uv.gyp
View
@@ -39,6 +39,8 @@ typedef struct {
size_t len;
} uv_buf_t;
+typedef int uv_file;
+
#define UV_REQ_BUFSML_SIZE (4)
#define UV_REQ_PRIVATE_FIELDS /* empty */
@@ -155,4 +157,7 @@ typedef struct {
#define UV_PROCESS_PRIVATE_FIELDS \
ev_child child_watcher;
+#define UV_FS_PRIVATE_FIELDS \
+#define UV_WORK_PRIVATE_FIELDS \
+
#endif /* UV_UNIX_H */
View
@@ -42,6 +42,8 @@ typedef struct uv_buf_t {
char* base;
} uv_buf_t;
+typedef int uv_file;
+
#define UV_REQ_TYPE_PRIVATE \
/* TODO: remove the req suffix */ \
UV_ARES_EVENT_REQ, \
@@ -208,5 +210,22 @@ typedef struct uv_buf_t {
HANDLE process_handle; \
HANDLE close_handle;
+#define UV_FS_PRIVATE_FIELDS \
+ int flags; \
+ void* arg0; \
+ union { \
+ struct { \
+ void* arg1; \
+ void* arg2; \
+ void* arg3; \
+ }; \
+ struct { \
+ ssize_t arg4; \
+ ssize_t arg5; \
+ }; \
+ };
+
+#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);
View
@@ -60,6 +60,8 @@ typedef struct uv_shutdown_s uv_shutdown_t;
typedef struct uv_write_s uv_write_t;
typedef struct uv_connect_s uv_connect_t;
typedef struct uv_udp_send_s uv_udp_send_t;
+typedef struct uv_fs_s uv_fs_t;
+typedef struct uv_work_s uv_work_t;
#if defined(__unix__) || defined(__POSIX__) || defined(__APPLE__)
# include "uv-unix.h"
@@ -123,6 +125,9 @@ 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_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);
+typedef void (*uv_after_work_cb)(uv_work_t* req);
/* Expand this list if necessary. */
@@ -199,6 +204,8 @@ typedef enum {
UV_SHUTDOWN,
UV_WAKEUP,
UV_UDP_SEND,
+ UV_FS,
+ UV_WORK,
UV_REQ_TYPE_PRIVATE
} uv_req_type;
@@ -801,6 +808,89 @@ int uv_spawn(uv_process_t*, uv_process_options_t options);
int uv_process_kill(uv_process_t*, int signum);
+/*
+ * uv_work_t is a subclass of uv_req_t
+ */
+struct uv_work_s {
+ UV_REQ_FIELDS
+ 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, uv_after_work_cb after_work_cb);
+
+
+typedef enum {
+ UV_FS_UNKNOWN = -1,
+ UV_FS_CUSTOM,
+ UV_FS_OPEN,
+ UV_FS_CLOSE,
+ UV_FS_READ,
+ UV_FS_WRITE,
+ UV_FS_SENDFILE,
+ UV_FS_STAT,
+ UV_FS_LSTAT,
+ UV_FS_FSTAT,
+ UV_FS_FTRUNCATE,
+ UV_FS_UTIME,
+ UV_FS_FUTIME,
+ UV_FS_CHMOD,
+ UV_FS_FCHMOD,
+ UV_FS_FSYNC,
+ UV_FS_FDATASYNC,
+ UV_FS_UNLINK,
+ UV_FS_RMDIR,
+ UV_FS_MKDIR,
+ UV_FS_RENAME,
+ UV_FS_READDIR,
+ UV_FS_LINK,
+ UV_FS_SYMLINK,
+ UV_FS_READLINK,
+} uv_fs_type;
+
+/*
+ * uv_fs_t is a subclass of uv_req_t
+ */
+struct uv_fs_s {
+ UV_REQ_FIELDS
+ uv_fs_type fs_type;
+ uv_fs_cb cb;
+ ssize_t result;
+ void* ptr;
+ int errorno;
+ UV_FS_PRIVATE_FIELDS
+};
+
+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);
+
+
/* Utility */
/* Convert string ip addresses to binary structures */
@@ -843,6 +933,8 @@ union uv_any_req {
uv_write_t write;
uv_connect_t connect;
uv_shutdown_t shutdown;
+ uv_fs_t fs_req;
+ uv_work_t work_req;
};
@@ -876,6 +968,8 @@ uv_counters_t* uv_counters();
#undef UV_ASYNC_PRIVATE_FIELDS
#undef UV_TIMER_PRIVATE_FIELDS
#undef UV_GETADDRINFO_PRIVATE_FIELDS
+#undef UV_FS_REQ_PRIVATE_FIELDS
+#undef UV_WORK_PRIVATE_FIELDS
#ifdef __cplusplus
}
View
@@ -2961,3 +2961,158 @@ int uv_process_kill(uv_process_t* process, int signum) {
return 0;
}
}
+
+
+void uv_fs_req_cleanup(uv_fs_t* req) {
+ assert(0 && "implement me");
+}
+
+
+int uv_fs_close(uv_fs_t* req, uv_file file, uv_fs_cb cb) {
+ assert(0 && "implement me");
+ return -1;
+}
+
+
+int uv_fs_open(uv_fs_t* req, const char* path, int flags, int mode, uv_fs_cb cb) {
+ assert(0 && "implement me");
+ return -1;
+}
+
+
+int uv_fs_read(uv_fs_t* req, uv_file file, void* buf, size_t length, off_t offset, uv_fs_cb cb) {
+ assert(0 && "implement me");
+ return -1;
+}
+
+
+int uv_fs_unlink(uv_fs_t* req, const char* path, uv_fs_cb cb) {
+ assert(0 && "implement me");
+ return -1;
+}
+
+
+int uv_fs_write(uv_fs_t* req, uv_file file, void* buf, size_t length, off_t offset, uv_fs_cb cb) {
+ assert(0 && "implement me");
+ return -1;
+}
+
+
+int uv_fs_mkdir(uv_fs_t* req, const char* path, int mode, uv_fs_cb cb) {
+ assert(0 && "implement me");
+ return -1;
+}
+
+
+int uv_fs_rmdir(uv_fs_t* req, const char* path, uv_fs_cb cb) {
+ assert(0 && "implement me");
+ return -1;
+}
+
+
+int uv_fs_readdir(uv_fs_t* req, const char* path, int flags, uv_fs_cb cb) {
+ assert(0 && "implement me");
+ return -1;
+}
+
+
+int uv_fs_stat(uv_fs_t* req, const char* path, uv_fs_cb cb) {
+ assert(0 && "implement me");
+ return -1;
+}
+
+
+int uv_fs_fstat(uv_fs_t* req, uv_file file, uv_fs_cb cb) {
+ assert(0 && "implement me");
+ return -1;
+}
+
+
+int uv_fs_rename(uv_fs_t* req, const char* path, const char* new_path, uv_fs_cb cb) {
+ assert(0 && "implement me");
+ return -1;
+}
+
+
+int uv_fs_fsync(uv_fs_t* req, uv_file file, uv_fs_cb cb) {
+ assert(0 && "implement me");
+ return -1;
+}
+
+
+int uv_fs_fdatasync(uv_fs_t* req, uv_file file, uv_fs_cb cb) {
+ assert(0 && "implement me");
+ return -1;
+}
+
+
+int uv_fs_ftruncate(uv_fs_t* req, uv_file file, off_t offset, uv_fs_cb cb) {
+ assert(0 && "implement me");
+ return -1;
+}
+
+
+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) {
+ assert(0 && "implement me");
+ return -1;
+}
+
+
+int uv_fs_chmod(uv_fs_t* req, const char* path, int mode, uv_fs_cb cb) {
+ assert(0 && "implement me");
+ return -1;
+}
+
+
+int uv_fs_utime(uv_fs_t* req, const char* path, double atime, double mtime, uv_fs_cb cb) {
+ assert(0 && "implement me");
+ return -1;
+}
+
+
+int uv_fs_futime(uv_fs_t* req, uv_file file, double atime, double mtime, uv_fs_cb cb) {
+ assert(0 && "implement me");
+ return -1;
+}
+
+
+int uv_fs_lstat(uv_fs_t* req, const char* path, uv_fs_cb cb) {
+ assert(0 && "implement me");
+ return -1;
+}
+
+
+int uv_fs_link(uv_fs_t* req, const char* path, const char* new_path, uv_fs_cb cb) {
+ assert(0 && "implement me");
+ return -1;
+}
+
+
+int uv_fs_symlink(uv_fs_t* req, const char* path, const char* new_path, uv_fs_cb cb) {
+ assert(0 && "implement me");
+ return -1;
+}
+
+
+int uv_fs_readlink(uv_fs_t* req, const char* path, uv_fs_cb cb) {
+ assert(0 && "implement me");
+ return -1;
+}
+
+
+int uv_fs_fchmod(uv_fs_t* req, uv_file file, int mode, uv_fs_cb cb) {
+ assert(0 && "implement me");
+ return -1;
+}
+
+
+int uv_fs_chown(uv_fs_t* req, const char* path, int uid, int gid, uv_fs_cb cb) {
+ assert(0 && "implement me");
+ return -1;
+}
+
+
+int uv_fs_fchown(uv_fs_t* req, uv_file file, int uid, int gid, uv_fs_cb cb) {
+ assert(0 && "implement me");
+ return -1;
+}
View
@@ -73,6 +73,9 @@ void uv_init() {
/* Fetch winapi function pointers */
uv_winapi_init();
+ /* Initialize FS */
+ uv_fs_init();
+
/* Intialize event loop */
uv_loop_init();
}
Oops, something went wrong.

0 comments on commit 0e322fa

Please sign in to comment.