Begin implementation of UNIX uv_fs_ functions

Adding this incomplete work now to ease rebase troubles later as it moves
the functions to src/unix/fs.c and introduces src/unix/internal.h.
This commit is contained in:
Ryan Dahl 2011-08-29 14:36:31 -07:00
parent 925564e968
commit 3be275bad7
9 changed files with 361 additions and 192 deletions

View File

@ -85,15 +85,18 @@ endif
RUNNER_LIBS=
RUNNER_SRC=test/runner-unix.c
uv.a: src/uv-unix.o src/uv-common.o src/uv-platform.o src/ev/ev.o src/uv-eio.o src/eio/eio.o $(CARES_OBJS)
$(AR) rcs uv.a src/uv-unix.o src/uv-platform.o src/uv-common.o src/uv-eio.o src/ev/ev.o \
uv.a: src/uv-unix.o src/unix/fs.o src/uv-common.o src/uv-platform.o src/ev/ev.o src/uv-eio.o src/eio/eio.o $(CARES_OBJS)
$(AR) rcs uv.a src/uv-unix.o src/unix/fs.o src/uv-platform.o src/uv-common.o src/uv-eio.o src/ev/ev.o \
src/eio/eio.o $(CARES_OBJS)
src/uv-platform.o: src/$(UV_OS_FILE) include/uv.h include/uv-unix.h
$(CC) $(CSTDFLAG) $(CPPFLAGS) $(CFLAGS) -c src/$(UV_OS_FILE) -o src/uv-platform.o
src/uv-unix.o: src/uv-unix.c include/uv.h include/uv-unix.h
$(CC) $(CSTDFLAG) $(CPPFLAGS) -Ieio $(CFLAGS) -c src/uv-unix.c -o src/uv-unix.o
src/uv-unix.o: src/uv-unix.c include/uv.h include/uv-unix.h src/unix/internal.h
$(CC) $(CSTDFLAG) $(CPPFLAGS) -Isrc $(CFLAGS) -c src/uv-unix.c -o src/uv-unix.o
src/unix/fs.o: src/unix/fs.c include/uv.h include/uv-unix.h src/unix/internal.h
$(CC) $(CSTDFLAG) $(CPPFLAGS) -Isrc/ $(CFLAGS) -c src/unix/fs.c -o src/unix/fs.o
src/uv-common.o: src/uv-common.c include/uv.h include/uv-unix.h
$(CC) $(CSTDFLAG) $(CPPFLAGS) $(CFLAGS) -c src/uv-common.c -o src/uv-common.o

View File

@ -25,6 +25,7 @@
#include "ngx-queue.h"
#include "ev.h"
#include "eio.h"
#include <sys/types.h>
#include <sys/socket.h>
@ -157,7 +158,8 @@ typedef int uv_file;
#define UV_PROCESS_PRIVATE_FIELDS \
ev_child child_watcher;
#define UV_FS_PRIVATE_FIELDS
#define UV_FS_PRIVATE_FIELDS \
eio_req* eio;
#define UV_WORK_PRIVATE_FIELDS

View File

@ -849,7 +849,7 @@ typedef enum {
UV_FS_SYMLINK,
UV_FS_READLINK,
UV_FS_CHOWN,
UV_FS_FCHOWN,
UV_FS_FCHOWN
} uv_fs_type;
/*

294
src/unix/fs.c Normal file
View File

@ -0,0 +1,294 @@
/* 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 "eio.h"
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
static void uv_fs_req_init(uv_fs_t* req, uv_fs_type fs_type, uv_fs_cb cb) {
uv__req_init((uv_req_t*) req);
req->type = UV_FS;
req->fs_type = fs_type;
req->cb = cb;
req->result = 0;
req->ptr = NULL;
req->errorno = 0;
req->eio = NULL;
}
void uv_fs_req_cleanup(uv_fs_t* req) {
assert(0 && "implement me");
}
static int uv__fs_after(eio_req* eio) {
uv_fs_t* req = eio->data;
assert(req->cb);
req->result = req->eio->result;
req->eio = NULL; /* Freed by libeio */
req->cb(req);
return 0;
}
int uv_fs_close(uv_fs_t* req, uv_file file, uv_fs_cb cb) {
uv_fs_req_init(req, UV_FS_CLOSE, cb);
if (cb) {
/* async */
req->eio = eio_close(file, EIO_PRI_DEFAULT, uv__fs_after, req);
if (!req->eio) {
uv_err_new(NULL, ENOMEM);
return -1;
}
} else {
/* sync */
if ((req->result = uv__close(file))) {
uv_err_new(NULL, errno);
return -1;
}
}
return 0;
}
int uv_fs_open(uv_fs_t* req, const char* path, int flags, int mode,
uv_fs_cb cb) {
uv_fs_req_init(req, UV_FS_OPEN, cb);
if (cb) {
/* async */
req->eio = eio_open(path, flags, mode, EIO_PRI_DEFAULT, uv__fs_after, req);
if (!req->eio) {
uv_err_new(NULL, ENOMEM);
return -1;
}
} else {
/* sync */
req->result = open(path, flags, mode);
if (req->result < 0) {
uv_err_new(NULL, errno);
return -1;
}
uv__cloexec(req->result, 1);
}
return 0;
}
int uv_fs_read(uv_fs_t* req, uv_file fd, void* buf, size_t length,
off_t offset, uv_fs_cb cb) {
uv_fs_req_init(req, UV_FS_READ, cb);
if (cb) {
/* async */
req->eio = eio_read(fd, buf, length, offset, EIO_PRI_DEFAULT,
uv__fs_after, req);
if (!req->eio) {
uv_err_new(NULL, ENOMEM);
return -1;
}
} else {
/* sync */
req->result = offset < 0 ?
read(fd, buf, length) :
pread(fd, buf, length, offset);
if (req->result < 0) {
uv_err_new(NULL, errno);
return -1;
}
}
return 0;
}
int uv_fs_unlink(uv_fs_t* req, const char* path, uv_fs_cb cb) {
uv_fs_req_init(req, UV_FS_UNLINK, cb);
if (cb) {
/* async */
req->eio = eio_unlink(path, EIO_PRI_DEFAULT, uv__fs_after, req);
if (!req->eio) {
uv_err_new(NULL, ENOMEM);
return -1;
}
} else {
/* sync */
req->result = unlink(path);
if (req->result) {
uv_err_new(NULL, errno);
return -1;
}
}
return 0;
}
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;
}
int uv_queue_work(uv_work_t* req, uv_work_cb work_cb,
uv_after_work_cb after_work_cb) {
assert(0 && "implement me");
return -1;
}

34
src/unix/internal.h Normal file
View File

@ -0,0 +1,34 @@
/* 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_UNIX_INTERNAL_H_
#define UV_UNIX_INTERNAL_H_
#include "uv-common.h"
#include "uv-eio.h"
int uv__close(int fd);
void uv__req_init(uv_req_t*);
uv_err_t uv_err_new(uv_handle_t* handle, int sys_error);
int uv__nonblock(int fd, int set) __attribute__((unused));
int uv__cloexec(int fd, int set) __attribute__((unused));
#endif /* UV_UNIX_INTERNAL_H_ */

View File

@ -31,6 +31,13 @@
#define COUNTOF(a) (sizeof(a) / sizeof(a[0]))
/* Used for the uv_fs_ functions */
#define SET_REQ_RESULT(req, result) \
req->result = result; \
if (result == -1) { \
req->errorno = errno; \
}
/*
* Subclass of uv_handle_t. Used for integration of c-ares.
*/

View File

@ -23,8 +23,7 @@
#endif
#include "uv.h"
#include "uv-common.h"
#include "uv-eio.h"
#include "unix/internal.h"
#include <stddef.h> /* NULL */
#include <stdio.h> /* printf */
@ -100,11 +99,9 @@ struct uv_ares_data_s {
static struct uv_ares_data_s ares_data;
void uv__req_init(uv_req_t*);
void uv__next(EV_P_ ev_idle* watcher, int revents);
static int uv__stream_open(uv_stream_t*, int fd, int flags);
static void uv__finish_close(uv_handle_t* handle);
static uv_err_t uv_err_new(uv_handle_t* handle, int sys_error);
static int uv_tcp_listen(uv_tcp_t* tcp, int backlog, uv_connection_cb cb);
static int uv_pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb);
@ -141,13 +138,9 @@ static int uv__udp_send(uv_udp_send_t* req,
#define __attribute__(a)
#endif
/* Unused on systems that support O_CLOEXEC, SOCK_CLOEXEC, etc. */
static int uv__cloexec(int fd, int set) __attribute__((unused));
static int uv__nonblock(int fd, int set) __attribute__((unused));
static int uv__socket(int domain, int type, int protocol);
static int uv__accept(int sockfd, struct sockaddr* saddr, socklen_t len);
static int uv__close(int fd);
size_t uv__strlcpy(char* dst, const char* src, size_t size);
@ -226,7 +219,7 @@ static uv_err_t uv_err_new_artificial(uv_handle_t* handle, int code) {
}
static uv_err_t uv_err_new(uv_handle_t* handle, int sys_error) {
uv_err_t uv_err_new(uv_handle_t* handle, int sys_error) {
uv_err_t err;
err.sys_errno_ = sys_error;
err.code = uv_translate_sys_error(sys_error);
@ -2630,7 +2623,7 @@ static int uv__accept(int sockfd, struct sockaddr* saddr, socklen_t slen) {
}
static int uv__close(int fd) {
int uv__close(int fd) {
int status;
/*
@ -2647,7 +2640,7 @@ static int uv__close(int fd) {
}
static int uv__nonblock(int fd, int set) {
int uv__nonblock(int fd, int set) {
int flags;
if ((flags = fcntl(fd, F_GETFL)) == -1) {
@ -2668,7 +2661,7 @@ static int uv__nonblock(int fd, int set) {
}
static int uv__cloexec(int fd, int set) {
int uv__cloexec(int fd, int set) {
int flags;
if ((flags = fcntl(fd, F_GETFD)) == -1) {
@ -2962,164 +2955,3 @@ int uv_process_kill(uv_process_t* process, int signum) {
}
}
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;
}
int uv_queue_work(uv_work_t* req, uv_work_cb work_cb,
uv_after_work_cb after_work_cb) {
assert(0 && "implement me");
return -1;
}

View File

@ -37,12 +37,6 @@
#define UV_FS_FREE_PTR 0x0008
#define UV_FS_CLEANEDUP 0x0010
#define SET_REQ_RESULT(req, result) \
req->result = result; \
if (result == -1) { \
req->errorno = errno; \
}
#define STRDUP_ARG(req, i) \
req->arg##i = (void*)strdup((const char*)req->arg##i); \
if (!req->arg##i) { \

17
uv.gyp
View File

@ -140,6 +140,16 @@
'src/uv-eio.c',
'src/uv-eio.h',
'src/uv-unix.c',
'src/unix/fs.c',
'src/unix/internal.h',
'src/eio/ecb.h',
'src/eio/eio.c',
'src/eio/xthread.h',
'src/ev/ev.c',
'src/ev/ev_vars.h',
'src/ev/ev_wrap.h',
'src/ev/event.h',
# TODO: conditionally include the following based on OS?
'src/ares/config_cygwin/ares_config.h',
'src/ares/config_darwin/ares_config.h',
'src/ares/config_freebsd/ares_config.h',
@ -151,18 +161,11 @@
'src/eio/config_freebsd.h',
'src/eio/config_linux.h',
'src/eio/config_sunos.h',
'src/eio/ecb.h',
'src/eio/eio.c',
'src/eio/xthread.h',
'src/ev/config_cygwin.h',
'src/ev/config_darwin.h',
'src/ev/config_freebsd.h',
'src/ev/config_linux.h',
'src/ev/config_sunos.h',
'src/ev/ev.c',
'src/ev/ev_vars.h',
'src/ev/ev_wrap.h',
'src/ev/event.h',
],
'include_dirs': [
'src/ev'