mirror of https://github.com/lukechilds/node.git
Ben Noordhuis
12 years ago
67 changed files with 1958 additions and 19300 deletions
@ -1,403 +0,0 @@ |
|||
/*
|
|||
* libeio API header |
|||
* |
|||
* Copyright (c) 2007,2008,2009,2010,2011 Marc Alexander Lehmann <libeio@schmorp.de> |
|||
* All rights reserved. |
|||
* |
|||
* Redistribution and use in source and binary forms, with or without modifica- |
|||
* tion, are permitted provided that the following conditions are met: |
|||
* |
|||
* 1. Redistributions of source code must retain the above copyright notice, |
|||
* this list of conditions and the following disclaimer. |
|||
* |
|||
* 2. Redistributions in binary form must reproduce the above copyright |
|||
* notice, this list of conditions and the following disclaimer in the |
|||
* documentation and/or other materials provided with the distribution. |
|||
* |
|||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
|||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER- |
|||
* CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
|||
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- |
|||
* CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
|||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
|||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH- |
|||
* ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
|||
* OF THE POSSIBILITY OF SUCH DAMAGE. |
|||
* |
|||
* Alternatively, the contents of this file may be used under the terms of |
|||
* the GNU General Public License ("GPL") version 2 or any later version, |
|||
* in which case the provisions of the GPL are applicable instead of |
|||
* the above. If you wish to allow the use of your version of this file |
|||
* only under the terms of the GPL and not to allow others to use your |
|||
* version of this file under the BSD license, indicate your decision |
|||
* by deleting the provisions above and replace them with the notice |
|||
* and other provisions required by the GPL. If you do not delete the |
|||
* provisions above, a recipient may use your version of this file under |
|||
* either the BSD or the GPL. |
|||
*/ |
|||
|
|||
#ifndef EIO_H_ |
|||
#define EIO_H_ |
|||
|
|||
#ifdef __cplusplus |
|||
extern "C" { |
|||
#endif |
|||
|
|||
#include <stddef.h> |
|||
#include <signal.h> |
|||
#include <sys/types.h> |
|||
|
|||
typedef struct eio_req eio_req; |
|||
typedef struct eio_dirent eio_dirent; |
|||
|
|||
typedef int (*eio_cb)(eio_req *req); |
|||
|
|||
#ifndef EIO_REQ_MEMBERS |
|||
# define EIO_REQ_MEMBERS |
|||
#endif |
|||
|
|||
#ifndef EIO_STRUCT_STAT |
|||
# ifdef _WIN32 |
|||
# define EIO_STRUCT_STAT struct _stati64 |
|||
# define EIO_STRUCT_STATI64 |
|||
# else |
|||
# define EIO_STRUCT_STAT struct stat |
|||
# endif |
|||
#endif |
|||
|
|||
#ifdef _WIN32 |
|||
typedef int eio_uid_t; |
|||
typedef int eio_gid_t; |
|||
typedef int eio_mode_t; |
|||
#ifdef __MINGW32__ /* no intptr_t */ |
|||
typedef ssize_t eio_ssize_t; |
|||
#else |
|||
typedef intptr_t eio_ssize_t; /* or SSIZE_T */ |
|||
#endif |
|||
#if __GNUC__ |
|||
typedef long long eio_ino_t; |
|||
#else |
|||
typedef __int64 eio_ino_t; /* unsigned not supported by msvc */ |
|||
#endif |
|||
#else |
|||
typedef uid_t eio_uid_t; |
|||
typedef gid_t eio_gid_t; |
|||
typedef ssize_t eio_ssize_t; |
|||
typedef ino_t eio_ino_t; |
|||
typedef mode_t eio_mode_t; |
|||
#endif |
|||
|
|||
#ifndef EIO_STRUCT_STATVFS |
|||
# define EIO_STRUCT_STATVFS struct statvfs |
|||
#endif |
|||
|
|||
/* for readdir */ |
|||
|
|||
/* eio_readdir flags */ |
|||
enum |
|||
{ |
|||
EIO_READDIR_DENTS = 0x01, /* ptr2 contains eio_dirents, not just the (unsorted) names */ |
|||
EIO_READDIR_DIRS_FIRST = 0x02, /* dirents gets sorted into a good stat() ing order to find directories first */ |
|||
EIO_READDIR_STAT_ORDER = 0x04, /* dirents gets sorted into a good stat() ing order to quickly stat all files */ |
|||
EIO_READDIR_FOUND_UNKNOWN = 0x80, /* set by eio_readdir when *_ARRAY was set and any TYPE=UNKNOWN's were found */ |
|||
|
|||
EIO_READDIR_CUSTOM1 = 0x100, /* for use by apps */ |
|||
EIO_READDIR_CUSTOM2 = 0x200 /* for use by apps */ |
|||
}; |
|||
|
|||
/* using "typical" values in the hope that the compiler will do something sensible */ |
|||
enum eio_dtype |
|||
{ |
|||
EIO_DT_UNKNOWN = 0, |
|||
EIO_DT_FIFO = 1, |
|||
EIO_DT_CHR = 2, |
|||
EIO_DT_MPC = 3, /* multiplexed char device (v7+coherent) */ |
|||
EIO_DT_DIR = 4, |
|||
EIO_DT_NAM = 5, /* xenix special named file */ |
|||
EIO_DT_BLK = 6, |
|||
EIO_DT_MPB = 7, /* multiplexed block device (v7+coherent) */ |
|||
EIO_DT_REG = 8, |
|||
EIO_DT_NWK = 9, /* HP-UX network special */ |
|||
EIO_DT_CMP = 9, /* VxFS compressed */ |
|||
EIO_DT_LNK = 10, |
|||
/* DT_SHAD = 11,*/ |
|||
EIO_DT_SOCK = 12, |
|||
EIO_DT_DOOR = 13, /* solaris door */ |
|||
EIO_DT_WHT = 14, |
|||
EIO_DT_MAX = 15 /* highest DT_VALUE ever, hopefully */ |
|||
}; |
|||
|
|||
struct eio_dirent |
|||
{ |
|||
int nameofs; /* offset of null-terminated name string in (char *)req->ptr2 */ |
|||
unsigned short namelen; /* size of filename without trailing 0 */ |
|||
unsigned char type; /* one of EIO_DT_* */ |
|||
signed char score; /* internal use */ |
|||
eio_ino_t inode; /* the inode number, if available, otherwise unspecified */ |
|||
}; |
|||
|
|||
/* eio_msync flags */ |
|||
enum |
|||
{ |
|||
EIO_MS_ASYNC = 1, |
|||
EIO_MS_INVALIDATE = 2, |
|||
EIO_MS_SYNC = 4 |
|||
}; |
|||
|
|||
/* eio_mtouch flags */ |
|||
enum |
|||
{ |
|||
EIO_MT_MODIFY = 1 |
|||
}; |
|||
|
|||
/* eio_sync_file_range flags */ |
|||
enum |
|||
{ |
|||
EIO_SYNC_FILE_RANGE_WAIT_BEFORE = 1, |
|||
EIO_SYNC_FILE_RANGE_WRITE = 2, |
|||
EIO_SYNC_FILE_RANGE_WAIT_AFTER = 4 |
|||
}; |
|||
|
|||
/* eio_fallocate flags */ |
|||
enum |
|||
{ |
|||
EIO_FALLOC_FL_KEEP_SIZE = 1 /* MUST match the value in linux/falloc.h */ |
|||
}; |
|||
|
|||
/* timestamps and differences - feel free to use double in your code directly */ |
|||
typedef double eio_tstamp; |
|||
|
|||
/* the eio request structure */ |
|||
enum |
|||
{ |
|||
EIO_CUSTOM, |
|||
EIO_OPEN, EIO_CLOSE, EIO_DUP2, |
|||
EIO_READ, EIO_WRITE, |
|||
EIO_READAHEAD, EIO_SENDFILE, |
|||
EIO_STAT, EIO_LSTAT, EIO_FSTAT, |
|||
EIO_STATVFS, EIO_FSTATVFS, |
|||
EIO_TRUNCATE, EIO_FTRUNCATE, |
|||
EIO_UTIME, EIO_FUTIME, |
|||
EIO_CHMOD, EIO_FCHMOD, |
|||
EIO_CHOWN, EIO_FCHOWN, |
|||
EIO_SYNC, EIO_FSYNC, EIO_FDATASYNC, EIO_SYNCFS, |
|||
EIO_MSYNC, EIO_MTOUCH, EIO_SYNC_FILE_RANGE, EIO_FALLOCATE, |
|||
EIO_MLOCK, EIO_MLOCKALL, |
|||
EIO_UNLINK, EIO_RMDIR, EIO_MKDIR, EIO_RENAME, |
|||
EIO_MKNOD, EIO_READDIR, |
|||
EIO_LINK, EIO_SYMLINK, EIO_READLINK, EIO_REALPATH, |
|||
EIO_GROUP, EIO_NOP, |
|||
EIO_BUSY |
|||
}; |
|||
|
|||
/* mlockall constants */ |
|||
enum |
|||
{ |
|||
EIO_MCL_CURRENT = 1, |
|||
EIO_MCL_FUTURE = 2 |
|||
}; |
|||
|
|||
/* request priorities */ |
|||
|
|||
enum { |
|||
EIO_PRI_MIN = -4, |
|||
EIO_PRI_MAX = 4, |
|||
EIO_PRI_DEFAULT = 0 |
|||
}; |
|||
|
|||
#define ETP_PRI_MIN EIO_PRI_MIN |
|||
#define ETP_PRI_MAX EIO_PRI_MAX |
|||
|
|||
#define ETP_NUM_PRI (ETP_PRI_MAX - ETP_PRI_MIN + 1) |
|||
|
|||
#define ETP_REQ eio_req |
|||
|
|||
/*
|
|||
* a somewhat faster data structure might be nice, but |
|||
* with 8 priorities this actually needs <20 insns |
|||
* per shift, the most expensive operation. |
|||
*/ |
|||
typedef struct { |
|||
ETP_REQ *qs[ETP_NUM_PRI], *qe[ETP_NUM_PRI]; /* qstart, qend */ |
|||
int size; |
|||
} etp_reqq; |
|||
|
|||
typedef struct { |
|||
etp_reqq res_queue; /* queue of outstanding responses for this channel */ |
|||
void *data; /* use this for what you want */ |
|||
} eio_channel; |
|||
|
|||
/* eio request structure */ |
|||
/* this structure is mostly read-only */ |
|||
/* when initialising it, all members must be zero-initialised */ |
|||
struct eio_req |
|||
{ |
|||
eio_req volatile *next; /* private ETP */ |
|||
|
|||
eio_ssize_t result; /* result of syscall, e.g. result = read (... */ |
|||
off_t offs; /* read, write, truncate, readahead, sync_file_range, fallocate: file offset, mknod: dev_t */ |
|||
size_t size; /* read, write, readahead, sendfile, msync, mlock, sync_file_range, fallocate: length */ |
|||
void *ptr1; /* all applicable requests: pathname, old name; readdir: optional eio_dirents */ |
|||
void *ptr2; /* all applicable requests: new name or memory buffer; readdir: name strings */ |
|||
eio_tstamp nv1; /* utime, futime: atime; busy: sleep time */ |
|||
eio_tstamp nv2; /* utime, futime: mtime */ |
|||
|
|||
int type; /* EIO_xxx constant ETP */ |
|||
int int1; /* all applicable requests: file descriptor; sendfile: output fd; open, msync, mlockall, readdir: flags */ |
|||
long int2; /* chown, fchown: uid; sendfile: input fd; open, chmod, mkdir, mknod: file mode, sync_file_range, fallocate: flags */ |
|||
long int3; /* chown, fchown: gid */ |
|||
int errorno; /* errno value on syscall return */ |
|||
|
|||
eio_channel *channel; /* data used to direct poll callbacks arising from this req */ |
|||
|
|||
#if defined(__i386) || defined(__amd64) |
|||
unsigned char cancelled; |
|||
#else |
|||
sig_atomic_t cancelled; |
|||
#endif |
|||
|
|||
unsigned char flags; /* private */ |
|||
signed char pri; /* the priority */ |
|||
|
|||
void *data; |
|||
eio_cb finish; |
|||
void (*destroy)(eio_req *req); /* called when request no longer needed */ |
|||
void (*feed)(eio_req *req); /* only used for group requests */ |
|||
|
|||
EIO_REQ_MEMBERS |
|||
|
|||
eio_req *grp, *grp_prev, *grp_next, *grp_first; /* private */ |
|||
}; |
|||
|
|||
/* _private_ request flags */ |
|||
enum { |
|||
EIO_FLAG_PTR1_FREE = 0x01, /* need to free(ptr1) */ |
|||
EIO_FLAG_PTR2_FREE = 0x02, /* need to free(ptr2) */ |
|||
EIO_FLAG_GROUPADD = 0x04 /* some request was added to the group */ |
|||
}; |
|||
|
|||
/* undocumented/unsupported/private helper */ |
|||
/*void eio_page_align (void **addr, size_t *length);*/ |
|||
|
|||
/* returns < 0 on error, errno set
|
|||
* need_poll, if non-zero, will be called when results are available |
|||
* and eio_poll_cb needs to be invoked (it MUST NOT call eio_poll_cb itself). |
|||
* done_poll is called when the need to poll is gone. |
|||
*/ |
|||
int eio_init (void (*want_poll)(eio_channel *), void (*done_poll)(eio_channel *)); |
|||
|
|||
/* initialises a channel */ |
|||
void eio_channel_init(eio_channel *, void *data); |
|||
|
|||
/* must be called regularly to handle pending requests */ |
|||
/* returns 0 if all requests were handled, -1 if not, or the value of EIO_FINISH if != 0 */ |
|||
int eio_poll (eio_channel *channel); |
|||
|
|||
/* stop polling if poll took longer than duration seconds */ |
|||
void eio_set_max_poll_time (eio_tstamp nseconds); |
|||
/* do not handle more then count requests in one call to eio_poll_cb */ |
|||
void eio_set_max_poll_reqs (unsigned int nreqs); |
|||
|
|||
/* set minimum required number
|
|||
* maximum wanted number |
|||
* or maximum idle number of threads */ |
|||
void eio_set_min_parallel (unsigned int nthreads); |
|||
void eio_set_max_parallel (unsigned int nthreads); |
|||
void eio_set_max_idle (unsigned int nthreads); |
|||
void eio_set_idle_timeout (unsigned int seconds); |
|||
|
|||
unsigned int eio_nreqs (void); /* number of requests in-flight */ |
|||
unsigned int eio_nready (void); /* number of not-yet handled requests */ |
|||
unsigned int eio_npending (void); /* number of finished but unhandled requests */ |
|||
unsigned int eio_nthreads (void); /* number of worker threads in use currently */ |
|||
|
|||
/*****************************************************************************/ |
|||
/* convenience wrappers */ |
|||
|
|||
#ifndef EIO_NO_WRAPPERS |
|||
eio_req *eio_nop (int pri, eio_cb cb, void *data, eio_channel *channel); /* does nothing except go through the whole process */ |
|||
eio_req *eio_busy (eio_tstamp delay, int pri, eio_cb cb, void *data, eio_channel *channel); /* ties a thread for this long, simulating busyness */ |
|||
eio_req *eio_sync (int pri, eio_cb cb, void *data, eio_channel *channel); |
|||
eio_req *eio_fsync (int fd, int pri, eio_cb cb, void *data, eio_channel *channel); |
|||
eio_req *eio_fdatasync (int fd, int pri, eio_cb cb, void *data, eio_channel *channel); |
|||
eio_req *eio_syncfs (int fd, int pri, eio_cb cb, void *data, eio_channel *channel); |
|||
eio_req *eio_msync (void *addr, size_t length, int flags, int pri, eio_cb cb, void *data, eio_channel *channel); |
|||
eio_req *eio_mtouch (void *addr, size_t length, int flags, int pri, eio_cb cb, void *data, eio_channel *channel); |
|||
eio_req *eio_mlock (void *addr, size_t length, int pri, eio_cb cb, void *data, eio_channel *channel); |
|||
eio_req *eio_mlockall (int flags, int pri, eio_cb cb, void *data, eio_channel *channel); |
|||
eio_req *eio_sync_file_range (int fd, off_t offset, size_t nbytes, unsigned int flags, int pri, eio_cb cb, void *data, eio_channel *channel); |
|||
eio_req *eio_fallocate (int fd, int mode, off_t offset, size_t len, int pri, eio_cb cb, void *data, eio_channel *channel); |
|||
eio_req *eio_close (int fd, int pri, eio_cb cb, void *data, eio_channel *channel); |
|||
eio_req *eio_readahead (int fd, off_t offset, size_t length, int pri, eio_cb cb, void *data, eio_channel *channel); |
|||
eio_req *eio_read (int fd, void *buf, size_t length, off_t offset, int pri, eio_cb cb, void *data, eio_channel *channel); |
|||
eio_req *eio_write (int fd, void *buf, size_t length, off_t offset, int pri, eio_cb cb, void *data, eio_channel *channel); |
|||
eio_req *eio_fstat (int fd, int pri, eio_cb cb, void *data, eio_channel *channel); /* stat buffer=ptr2 allocated dynamically */ |
|||
eio_req *eio_fstatvfs (int fd, int pri, eio_cb cb, void *data, eio_channel *channel); /* stat buffer=ptr2 allocated dynamically */ |
|||
eio_req *eio_futime (int fd, eio_tstamp atime, eio_tstamp mtime, int pri, eio_cb cb, void *data, eio_channel *channel); |
|||
eio_req *eio_ftruncate (int fd, off_t offset, int pri, eio_cb cb, void *data, eio_channel *channel); |
|||
eio_req *eio_fchmod (int fd, eio_mode_t mode, int pri, eio_cb cb, void *data, eio_channel *channel); |
|||
eio_req *eio_fchown (int fd, eio_uid_t uid, eio_gid_t gid, int pri, eio_cb cb, void *data, eio_channel *channel); |
|||
eio_req *eio_dup2 (int fd, int fd2, int pri, eio_cb cb, void *data, eio_channel *channel); |
|||
eio_req *eio_sendfile (int out_fd, int in_fd, off_t in_offset, size_t length, int pri, eio_cb cb, void *data, eio_channel *channel); |
|||
eio_req *eio_open (const char *path, int flags, eio_mode_t mode, int pri, eio_cb cb, void *data, eio_channel *channel); |
|||
eio_req *eio_utime (const char *path, eio_tstamp atime, eio_tstamp mtime, int pri, eio_cb cb, void *data, eio_channel *channel); |
|||
eio_req *eio_truncate (const char *path, off_t offset, int pri, eio_cb cb, void *data, eio_channel *channel); |
|||
eio_req *eio_chown (const char *path, eio_uid_t uid, eio_gid_t gid, int pri, eio_cb cb, void *data, eio_channel *channel); |
|||
eio_req *eio_chmod (const char *path, eio_mode_t mode, int pri, eio_cb cb, void *data, eio_channel *channel); |
|||
eio_req *eio_mkdir (const char *path, eio_mode_t mode, int pri, eio_cb cb, void *data, eio_channel *channel); |
|||
eio_req *eio_readdir (const char *path, int flags, int pri, eio_cb cb, void *data, eio_channel *channel); /* result=ptr2 allocated dynamically */ |
|||
eio_req *eio_rmdir (const char *path, int pri, eio_cb cb, void *data, eio_channel *channel); |
|||
eio_req *eio_unlink (const char *path, int pri, eio_cb cb, void *data, eio_channel *channel); |
|||
eio_req *eio_readlink (const char *path, int pri, eio_cb cb, void *data, eio_channel *channel); /* result=ptr2 allocated dynamically */ |
|||
eio_req *eio_realpath (const char *path, int pri, eio_cb cb, void *data, eio_channel *channel); /* result=ptr2 allocated dynamically */ |
|||
eio_req *eio_stat (const char *path, int pri, eio_cb cb, void *data, eio_channel *channel); /* stat buffer=ptr2 allocated dynamically */ |
|||
eio_req *eio_lstat (const char *path, int pri, eio_cb cb, void *data, eio_channel *channel); /* stat buffer=ptr2 allocated dynamically */ |
|||
eio_req *eio_statvfs (const char *path, int pri, eio_cb cb, void *data, eio_channel *channel); /* stat buffer=ptr2 allocated dynamically */ |
|||
eio_req *eio_mknod (const char *path, eio_mode_t mode, dev_t dev, int pri, eio_cb cb, void *data, eio_channel *channel); |
|||
eio_req *eio_link (const char *path, const char *new_path, int pri, eio_cb cb, void *data, eio_channel *channel); |
|||
eio_req *eio_symlink (const char *path, const char *new_path, int pri, eio_cb cb, void *data, eio_channel *channel); |
|||
eio_req *eio_rename (const char *path, const char *new_path, int pri, eio_cb cb, void *data, eio_channel *channel); |
|||
eio_req *eio_custom (void (*execute)(eio_req *), int pri, eio_cb cb, void *data, eio_channel *channel); |
|||
#endif |
|||
|
|||
/*****************************************************************************/ |
|||
/* groups */ |
|||
|
|||
eio_req *eio_grp (eio_cb cb, void *data, eio_channel *channel); |
|||
void eio_grp_feed (eio_req *grp, void (*feed)(eio_req *req), int limit); |
|||
void eio_grp_limit (eio_req *grp, int limit); |
|||
void eio_grp_add (eio_req *grp, eio_req *req); |
|||
void eio_grp_cancel (eio_req *grp); /* cancels all sub requests but not the group */ |
|||
|
|||
/*****************************************************************************/ |
|||
/* request api */ |
|||
|
|||
/* true if the request was cancelled, useful in the invoke callback */ |
|||
#define EIO_CANCELLED(req) ((req)->cancelled) |
|||
|
|||
#define EIO_RESULT(req) ((req)->result) |
|||
/* returns a pointer to the result buffer allocated by eio */ |
|||
#define EIO_BUF(req) ((req)->ptr2) |
|||
#define EIO_STAT_BUF(req) ((EIO_STRUCT_STAT *)EIO_BUF(req)) |
|||
#define EIO_STATVFS_BUF(req) ((EIO_STRUCT_STATVFS *)EIO_BUF(req)) |
|||
#define EIO_PATH(req) ((char *)(req)->ptr1) |
|||
|
|||
/* submit a request for execution */ |
|||
void eio_submit (eio_req *req); |
|||
/* cancel a request as soon fast as possible, if possible */ |
|||
void eio_cancel (eio_req *req); |
|||
|
|||
/*****************************************************************************/ |
|||
/* convenience functions */ |
|||
|
|||
eio_ssize_t eio_sendfile_sync (int ofd, int ifd, off_t offset, size_t count); |
|||
eio_ssize_t eio__pread (int fd, void *buf, size_t count, off_t offset); |
|||
eio_ssize_t eio__pwrite (int fd, void *buf, size_t count, off_t offset); |
|||
|
|||
#ifdef __cplusplus |
|||
} |
|||
#endif |
|||
|
|||
#endif |
|||
|
@ -1,63 +0,0 @@ |
|||
Revision history for libeio |
|||
|
|||
TODO: maybe add mincore support? available on at least darwin, solaris, linux, freebsd |
|||
TODO: openbsd requires stdint.h for intptr_t - why posix? |
|||
|
|||
TODO: make mtouch/readdir maybe others cancellable in-request |
|||
TODO: fadvise request |
|||
1.0 |
|||
- fix a deadlock where a wakeup signal could be missed when |
|||
a timeout occured at the same time. |
|||
- use nonstandard but maybe-working-on-bsd fork technique. |
|||
- use fewer time() syscalls when waiting for new requests. |
|||
- fix a path-memory-leak in readdir when using the wrappers |
|||
(reported by Thomas L. Shinnick). |
|||
- support a max_idle value of 0. |
|||
- support setting of idle timeout value (eio_set_idle_timeout). |
|||
- readdir: correctly handle malloc failures. |
|||
- readdir: new flags argument, can return inode |
|||
and possibly filetype, can sort in various ways. |
|||
- readdir: stop immediately when cancelled, do |
|||
not continue reading the directory. |
|||
- fix return value of eio_sendfile_sync. |
|||
- include sys/mman.h for msync. |
|||
- added EIO_STACKSIZE. |
|||
- added msync, mtouch support (untested). |
|||
- added sync_file_range (untested). |
|||
- fixed custom support. |
|||
- use a more robust feed-add detection method. |
|||
- "outbundled" from IO::AIO. |
|||
- eio_set_max_polltime did not properly convert time to ticks. |
|||
- tentatively support darwin in sendfile. |
|||
- fix freebsd/darwin sendfile. |
|||
- also use sendfile emulation for ENOTSUP and EOPNOTSUPP |
|||
error codes. |
|||
- add OS-independent EIO_MT_* and EIO_MS_* flag enums. |
|||
- add eio_statvfs/eio_fstatvfs. |
|||
- add eio_mlock/eio_mlockall and OS-independent MCL_* flag enums. |
|||
- no longer set errno to 0 before making syscalls, this only lures |
|||
people into the trap of believing errno shows success or failure. |
|||
- "fix" demo.c so that it works as non-root. |
|||
- suppoert utimes seperately from futimes, as some systems have |
|||
utimes but not futimes. |
|||
- use _POSIX_MEMLOCK_RANGE for mlock. |
|||
- do not (errornously) overwrite CFLAGS in configure.ac. |
|||
- mknod used int3 for dev_t (§2 bit), not offs (64 bit). |
|||
- fix memory corruption in eio_readdirx for the flags |
|||
combination EIO_READDIR_STAT_ORDER | EIO_READDIR_DIRS_FIRST. |
|||
- port to openbsd (another blatantly broken non-UNIX/POSIX platform). |
|||
- fix eio_custom prototype. |
|||
- work around a Linux (and likely FreeBSD and other kernels) bug |
|||
where sendfile would not transfer all the requested bytes on |
|||
large transfers, using a heuristic. |
|||
- use libecb, and apply lots of minor space optimisations. |
|||
- disable sendfile on darwin, broken as everything else. |
|||
- add realpath request and implementation. |
|||
- cancelled requests will still invoke their request callbacks. |
|||
- add fallocate. |
|||
- do not acquire any locks when forking. |
|||
- incorporated some mingw32 changes by traviscline. |
|||
- added syncfs support, using direct syscall. |
|||
- set thread name on linux (ps -L/Hcx, top, gdb). |
|||
- remove useless use of volatile variables. |
|||
|
@ -1,36 +0,0 @@ |
|||
All files in libeio are Copyright (C)2007,2008 Marc Alexander Lehmann. |
|||
|
|||
Redistribution and use in source and binary forms, with or without |
|||
modification, are permitted provided that the following conditions are |
|||
met: |
|||
|
|||
* Redistributions of source code must retain the above copyright |
|||
notice, this list of conditions and the following disclaimer. |
|||
|
|||
* Redistributions in binary form must reproduce the above |
|||
copyright notice, this list of conditions and the following |
|||
disclaimer in the documentation and/or other materials provided |
|||
with the distribution. |
|||
|
|||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|||
|
|||
Alternatively, the contents of this package may be used under the terms |
|||
of the GNU General Public License ("GPL") version 2 or any later version, |
|||
in which case the provisions of the GPL are applicable instead of the |
|||
above. If you wish to allow the use of your version of this package only |
|||
under the terms of the GPL and not to allow others to use your version of |
|||
this file under the BSD license, indicate your decision by deleting the |
|||
provisions above and replace them with the notice and other provisions |
|||
required by the GPL in this and the other files of this package. If you do |
|||
not delete the provisions above, a recipient may use your version of this |
|||
file under either the BSD or the GPL. |
@ -1,15 +0,0 @@ |
|||
AUTOMAKE_OPTIONS = foreign no-dependencies |
|||
|
|||
VERSION_INFO = 1:0 |
|||
|
|||
EXTRA_DIST = LICENSE Changes autogen.sh |
|||
|
|||
#man_MANS = ev.3
|
|||
|
|||
include_HEADERS = eio.h |
|||
|
|||
lib_LTLIBRARIES = libeio.la |
|||
|
|||
libeio_la_SOURCES = eio.c ecb.h xthread.h config.h |
|||
libeio_la_LDFLAGS = -version-info $(VERSION_INFO) |
|||
|
File diff suppressed because it is too large
@ -1,3 +0,0 @@ |
|||
#!/bin/sh |
|||
|
|||
autoreconf --install --symlink --force |
@ -1,86 +0,0 @@ |
|||
/* config.h.in. Generated from configure.ac by autoheader. */ |
|||
|
|||
/* Define to 1 if you have the <dlfcn.h> header file. */ |
|||
#undef HAVE_DLFCN_H |
|||
|
|||
/* fdatasync(2) is available */ |
|||
#undef HAVE_FDATASYNC |
|||
|
|||
/* futimes(2) is available */ |
|||
#undef HAVE_FUTIMES |
|||
|
|||
/* Define to 1 if you have the <inttypes.h> header file. */ |
|||
#undef HAVE_INTTYPES_H |
|||
|
|||
/* Define to 1 if you have the <memory.h> header file. */ |
|||
#undef HAVE_MEMORY_H |
|||
|
|||
/* posix_fadvise(2) is available */ |
|||
#undef HAVE_POSIX_FADVISE |
|||
|
|||
/* posix_madvise(2) is available */ |
|||
#undef HAVE_POSIX_MADVISE |
|||
|
|||
/* pread(2) and pwrite(2) are available */ |
|||
#undef HAVE_PREADWRITE |
|||
|
|||
/* readahead(2) is available (linux) */ |
|||
#undef HAVE_READAHEAD |
|||
|
|||
/* sendfile(2) is available and supported */ |
|||
#undef HAVE_SENDFILE |
|||
|
|||
/* Define to 1 if you have the <stdint.h> header file. */ |
|||
#undef HAVE_STDINT_H |
|||
|
|||
/* Define to 1 if you have the <stdlib.h> header file. */ |
|||
#undef HAVE_STDLIB_H |
|||
|
|||
/* Define to 1 if you have the <strings.h> header file. */ |
|||
#undef HAVE_STRINGS_H |
|||
|
|||
/* Define to 1 if you have the <string.h> header file. */ |
|||
#undef HAVE_STRING_H |
|||
|
|||
/* sync_file_range(2) is available */ |
|||
#undef HAVE_SYNC_FILE_RANGE |
|||
|
|||
/* Define to 1 if you have the <sys/stat.h> header file. */ |
|||
#undef HAVE_SYS_STAT_H |
|||
|
|||
/* Define to 1 if you have the <sys/types.h> header file. */ |
|||
#undef HAVE_SYS_TYPES_H |
|||
|
|||
/* Define to 1 if you have the <unistd.h> header file. */ |
|||
#undef HAVE_UNISTD_H |
|||
|
|||
/* utimes(2) is available */ |
|||
#undef HAVE_UTIMES |
|||
|
|||
/* Define to the sub-directory in which libtool stores uninstalled libraries.
|
|||
*/ |
|||
#undef LT_OBJDIR |
|||
|
|||
/* Name of package */ |
|||
#undef PACKAGE |
|||
|
|||
/* Define to the address where bug reports for this package should be sent. */ |
|||
#undef PACKAGE_BUGREPORT |
|||
|
|||
/* Define to the full name of this package. */ |
|||
#undef PACKAGE_NAME |
|||
|
|||
/* Define to the full name and version of this package. */ |
|||
#undef PACKAGE_STRING |
|||
|
|||
/* Define to the one symbol short name of this package. */ |
|||
#undef PACKAGE_TARNAME |
|||
|
|||
/* Define to the home page for this package. */ |
|||
#undef PACKAGE_URL |
|||
|
|||
/* Define to the version of this package. */ |
|||
#undef PACKAGE_VERSION |
|||
|
|||
/* Define to 1 if you have the ANSI C header files. */ |
|||
#undef STDC_HEADERS |
@ -1,84 +0,0 @@ |
|||
/* config.h. Generated from config.h.in by configure. */ |
|||
/* config.h.in. Generated from configure.ac by autoheader. */ |
|||
|
|||
/* Define to 1 if you have the <dlfcn.h> header file. */ |
|||
#define HAVE_DLFCN_H 1 |
|||
|
|||
/* fdatasync(2) is available */ |
|||
/* #undef HAVE_FDATASYNC */ |
|||
|
|||
/* utimes(2) is available */ |
|||
#define HAVE_UTIMES 1 |
|||
|
|||
/* futimes(2) is available */ |
|||
/* #undef HAVE_FUTIMES */ |
|||
|
|||
/* Define to 1 if you have the <inttypes.h> header file. */ |
|||
#define HAVE_INTTYPES_H 1 |
|||
|
|||
/* Define to 1 if you have the <memory.h> header file. */ |
|||
#define HAVE_MEMORY_H 1 |
|||
|
|||
/* pread(2) and pwrite(2) are available */ |
|||
#define HAVE_PREADWRITE 1 |
|||
|
|||
/* readahead(2) is available (linux) */ |
|||
/* #undef HAVE_READAHEAD */ |
|||
|
|||
/* sendfile(2) is available and supported */ |
|||
/* #undef HAVE_SENDFILE */ |
|||
|
|||
/* Define to 1 if you have the <stdint.h> header file. */ |
|||
#define HAVE_STDINT_H 1 |
|||
|
|||
/* Define to 1 if you have the <stdlib.h> header file. */ |
|||
#define HAVE_STDLIB_H 1 |
|||
|
|||
/* Define to 1 if you have the <strings.h> header file. */ |
|||
#define HAVE_STRINGS_H 1 |
|||
|
|||
/* Define to 1 if you have the <string.h> header file. */ |
|||
#define HAVE_STRING_H 1 |
|||
|
|||
/* sync_file_range(2) is available */ |
|||
/* #undef HAVE_SYNC_FILE_RANGE */ |
|||
|
|||
/* Define to 1 if you have the <sys/stat.h> header file. */ |
|||
#define HAVE_SYS_STAT_H 1 |
|||
|
|||
/* Define to 1 if you have the <sys/types.h> header file. */ |
|||
#define HAVE_SYS_TYPES_H 1 |
|||
|
|||
/* Define to 1 if you have the <unistd.h> header file. */ |
|||
#define HAVE_UNISTD_H 1 |
|||
|
|||
/* Define to the sub-directory in which libtool stores uninstalled libraries.
|
|||
*/ |
|||
#define LT_OBJDIR ".libs/" |
|||
|
|||
/* Name of package */ |
|||
#define PACKAGE "libeio" |
|||
|
|||
/* Define to the address where bug reports for this package should be sent. */ |
|||
#define PACKAGE_BUGREPORT "" |
|||
|
|||
/* Define to the full name of this package. */ |
|||
#define PACKAGE_NAME "" |
|||
|
|||
/* Define to the full name and version of this package. */ |
|||
#define PACKAGE_STRING "" |
|||
|
|||
/* Define to the one symbol short name of this package. */ |
|||
#define PACKAGE_TARNAME "" |
|||
|
|||
/* Define to the home page for this package. */ |
|||
#define PACKAGE_URL "" |
|||
|
|||
/* Define to the version of this package. */ |
|||
#define PACKAGE_VERSION "" |
|||
|
|||
/* Define to 1 if you have the ANSI C header files. */ |
|||
#define STDC_HEADERS 1 |
|||
|
|||
/* Version number of package */ |
|||
#define VERSION "1.0" |
@ -1,80 +0,0 @@ |
|||
/* config.h. Generated from config.h.in by configure. */ |
|||
/* config.h.in. Generated from configure.ac by autoheader. */ |
|||
|
|||
/* Define to 1 if you have the <dlfcn.h> header file. */ |
|||
#define HAVE_DLFCN_H 1 |
|||
|
|||
/* fdatasync(2) is available */ |
|||
#define HAVE_FDATASYNC 1 |
|||
|
|||
/* utimes(2) is available */ |
|||
#define HAVE_UTIMES 1 |
|||
|
|||
/* futimes(2) is available */ |
|||
#define HAVE_FUTIMES 1 |
|||
|
|||
/* Define to 1 if you have the <inttypes.h> header file. */ |
|||
#define HAVE_INTTYPES_H 1 |
|||
|
|||
/* Define to 1 if you have the <memory.h> header file. */ |
|||
#define HAVE_MEMORY_H 1 |
|||
|
|||
/* pread(2) and pwrite(2) are available */ |
|||
#define HAVE_PREADWRITE 1 |
|||
|
|||
/* readahead(2) is available (linux) */ |
|||
/* #undef HAVE_READAHEAD */ |
|||
|
|||
/* sendfile(2) is available and supported */ |
|||
/* #undef HAVE_SENDFILE */ |
|||
|
|||
/* Define to 1 if you have the <stdint.h> header file. */ |
|||
#define HAVE_STDINT_H 1 |
|||
|
|||
/* Define to 1 if you have the <stdlib.h> header file. */ |
|||
#define HAVE_STDLIB_H 1 |
|||
|
|||
/* Define to 1 if you have the <strings.h> header file. */ |
|||
#define HAVE_STRINGS_H 1 |
|||
|
|||
/* Define to 1 if you have the <string.h> header file. */ |
|||
#define HAVE_STRING_H 1 |
|||
|
|||
/* sync_file_range(2) is available */ |
|||
/* #undef HAVE_SYNC_FILE_RANGE */ |
|||
|
|||
/* Define to 1 if you have the <sys/stat.h> header file. */ |
|||
#define HAVE_SYS_STAT_H 1 |
|||
|
|||
/* Define to 1 if you have the <sys/types.h> header file. */ |
|||
#define HAVE_SYS_TYPES_H 1 |
|||
|
|||
/* Define to 1 if you have the <unistd.h> header file. */ |
|||
#define HAVE_UNISTD_H 1 |
|||
|
|||
/* Name of package */ |
|||
#define PACKAGE "libeio" |
|||
|
|||
/* Define to the address where bug reports for this package should be sent. */ |
|||
#define PACKAGE_BUGREPORT "" |
|||
|
|||
/* Define to the full name of this package. */ |
|||
#define PACKAGE_NAME "" |
|||
|
|||
/* Define to the full name and version of this package. */ |
|||
#define PACKAGE_STRING "" |
|||
|
|||
/* Define to the one symbol short name of this package. */ |
|||
#define PACKAGE_TARNAME "" |
|||
|
|||
/* Define to the home page for this package. */ |
|||
#define PACKAGE_URL "" |
|||
|
|||
/* Define to the version of this package. */ |
|||
#define PACKAGE_VERSION "" |
|||
|
|||
/* Define to 1 if you have the ANSI C header files. */ |
|||
#define STDC_HEADERS 1 |
|||
|
|||
/* Version number of package */ |
|||
#define VERSION "1.0" |
@ -1,141 +0,0 @@ |
|||
/* config.h. Generated from config.h.in by configure. */ |
|||
/* config.h.in. Generated from configure.ac by autoheader. */ |
|||
|
|||
/* Define to 1 if you have the <dlfcn.h> header file. */ |
|||
#define HAVE_DLFCN_H 1 |
|||
|
|||
/* fallocate(2) is available */ |
|||
/* #undef HAVE_FALLOCATE */ |
|||
|
|||
/* fdatasync(2) is available */ |
|||
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1060 |
|||
#define HAVE_FDATASYNC 1 |
|||
#else |
|||
#define HAVE_FDATASYNC 0 |
|||
#endif |
|||
|
|||
/* futimes(2) is available */ |
|||
#define HAVE_FUTIMES 1 |
|||
|
|||
/* Define to 1 if you have the <inttypes.h> header file. */ |
|||
#define HAVE_INTTYPES_H 1 |
|||
|
|||
/* Define to 1 if you have the <memory.h> header file. */ |
|||
#define HAVE_MEMORY_H 1 |
|||
|
|||
/* posix_fadvise(2) is available */ |
|||
/* #undef HAVE_POSIX_FADVISE */ |
|||
|
|||
/* posix_madvise(2) is available */ |
|||
#define HAVE_POSIX_MADVISE 1 |
|||
|
|||
/* prctl(PR_SET_NAME) is available */ |
|||
/* #undef HAVE_PRCTL_SET_NAME */ |
|||
|
|||
/* pread(2) and pwrite(2) are available */ |
|||
#define HAVE_PREADWRITE 1 |
|||
|
|||
/* readahead(2) is available (linux) */ |
|||
/* #undef HAVE_READAHEAD */ |
|||
|
|||
/* sendfile(2) is available and supported */ |
|||
#define HAVE_SENDFILE 1 |
|||
|
|||
/* Define to 1 if you have the <stdint.h> header file. */ |
|||
#define HAVE_STDINT_H 1 |
|||
|
|||
/* Define to 1 if you have the <stdlib.h> header file. */ |
|||
#define HAVE_STDLIB_H 1 |
|||
|
|||
/* Define to 1 if you have the <strings.h> header file. */ |
|||
#define HAVE_STRINGS_H 1 |
|||
|
|||
/* Define to 1 if you have the <string.h> header file. */ |
|||
#define HAVE_STRING_H 1 |
|||
|
|||
/* sync_file_range(2) is available */ |
|||
/* #undef HAVE_SYNC_FILE_RANGE */ |
|||
|
|||
/* Define to 1 if you have the <sys/prctl.h> header file. */ |
|||
/* #undef HAVE_SYS_PRCTL_H */ |
|||
|
|||
/* Define to 1 if you have the <sys/stat.h> header file. */ |
|||
#define HAVE_SYS_STAT_H 1 |
|||
|
|||
/* syscall(__NR_syncfs) is available */ |
|||
/* #undef HAVE_SYS_SYNCFS */ |
|||
|
|||
/* Define to 1 if you have the <sys/syscall.h> header file. */ |
|||
#define HAVE_SYS_SYSCALL_H 1 |
|||
|
|||
/* Define to 1 if you have the <sys/types.h> header file. */ |
|||
#define HAVE_SYS_TYPES_H 1 |
|||
|
|||
/* Define to 1 if you have the <unistd.h> header file. */ |
|||
#define HAVE_UNISTD_H 1 |
|||
|
|||
/* utimes(2) is available */ |
|||
#define HAVE_UTIMES 1 |
|||
|
|||
/* Define to the sub-directory in which libtool stores uninstalled libraries.
|
|||
*/ |
|||
#define LT_OBJDIR ".libs/" |
|||
|
|||
/* Name of package */ |
|||
#define PACKAGE "libeio" |
|||
|
|||
/* Define to the address where bug reports for this package should be sent. */ |
|||
#define PACKAGE_BUGREPORT "" |
|||
|
|||
/* Define to the full name of this package. */ |
|||
#define PACKAGE_NAME "" |
|||
|
|||
/* Define to the full name and version of this package. */ |
|||
#define PACKAGE_STRING "" |
|||
|
|||
/* Define to the one symbol short name of this package. */ |
|||
#define PACKAGE_TARNAME "" |
|||
|
|||
/* Define to the home page for this package. */ |
|||
#define PACKAGE_URL "" |
|||
|
|||
/* Define to the version of this package. */ |
|||
#define PACKAGE_VERSION "" |
|||
|
|||
/* Define to 1 if you have the ANSI C header files. */ |
|||
#define STDC_HEADERS 1 |
|||
|
|||
/* Enable extensions on AIX 3, Interix. */ |
|||
#ifndef _ALL_SOURCE |
|||
# define _ALL_SOURCE 1 |
|||
#endif |
|||
/* Enable GNU extensions on systems that have them. */ |
|||
#ifndef _GNU_SOURCE |
|||
# define _GNU_SOURCE 1 |
|||
#endif |
|||
/* Enable threading extensions on Solaris. */ |
|||
#ifndef _POSIX_PTHREAD_SEMANTICS |
|||
# define _POSIX_PTHREAD_SEMANTICS 1 |
|||
#endif |
|||
/* Enable extensions on HP NonStop. */ |
|||
#ifndef _TANDEM_SOURCE |
|||
# define _TANDEM_SOURCE 1 |
|||
#endif |
|||
/* Enable general extensions on Solaris. */ |
|||
#ifndef __EXTENSIONS__ |
|||
# define __EXTENSIONS__ 1 |
|||
#endif |
|||
|
|||
|
|||
/* Version number of package */ |
|||
#define VERSION "1.0" |
|||
|
|||
/* Define to 1 if on MINIX. */ |
|||
/* #undef _MINIX */ |
|||
|
|||
/* Define to 2 if the system does not provide POSIX.1 features except with
|
|||
this defined. */ |
|||
/* #undef _POSIX_1_SOURCE */ |
|||
|
|||
/* Define to 1 if you need to in order for `stat' and other things to work. */ |
|||
/* #undef _POSIX_SOURCE */ |
@ -1,81 +0,0 @@ |
|||
/* config.h. Generated from config.h.in by configure. */ |
|||
/* config.h.in. Generated from configure.ac by autoheader. */ |
|||
|
|||
/* Define to 1 if you have the <dlfcn.h> header file. */ |
|||
#define HAVE_DLFCN_H 1 |
|||
|
|||
/* fdatasync(2) is available */ |
|||
/* #undef HAVE_FDATASYNC */ |
|||
|
|||
/* utimes(2) is available */ |
|||
#define HAVE_UTIMES 1 |
|||
|
|||
/* futimes(2) is available */ |
|||
#define HAVE_FUTIMES 1 |
|||
|
|||
/* Define to 1 if you have the <inttypes.h> header file. */ |
|||
#define HAVE_INTTYPES_H 1 |
|||
|
|||
/* Define to 1 if you have the <memory.h> header file. */ |
|||
#define HAVE_MEMORY_H 1 |
|||
|
|||
/* pread(2) and pwrite(2) are available */ |
|||
#define HAVE_PREADWRITE 1 |
|||
|
|||
/* readahead(2) is available (linux) */ |
|||
/* #undef HAVE_READAHEAD */ |
|||
|
|||
/* sendfile(2) is available and supported */ |
|||
#define HAVE_SENDFILE 1 |
|||
|
|||
/* Define to 1 if you have the <stdint.h> header file. */ |
|||
#define HAVE_STDINT_H 1 |
|||
|
|||
/* Define to 1 if you have the <stdlib.h> header file. */ |
|||
#define HAVE_STDLIB_H 1 |
|||
|
|||
/* Define to 1 if you have the <strings.h> header file. */ |
|||
#define HAVE_STRINGS_H 1 |
|||
|
|||
/* Define to 1 if you have the <string.h> header file. */ |
|||
#define HAVE_STRING_H 1 |
|||
|
|||
/* sync_file_range(2) is available */ |
|||
/* #undef HAVE_SYNC_FILE_RANGE */ |
|||
|
|||
/* Define to 1 if you have the <sys/stat.h> header file. */ |
|||
#define HAVE_SYS_STAT_H 1 |
|||
|
|||
/* Define to 1 if you have the <sys/types.h> header file. */ |
|||
#define HAVE_SYS_TYPES_H 1 |
|||
|
|||
/* Define to 1 if you have the <unistd.h> header file. */ |
|||
#define HAVE_UNISTD_H 1 |
|||
|
|||
/* Define to the sub-directory in which libtool stores uninstalled libraries.
|
|||
*/ |
|||
#define LT_OBJDIR ".libs/" |
|||
|
|||
/* Name of package */ |
|||
#define PACKAGE "libeio" |
|||
|
|||
/* Define to the address where bug reports for this package should be sent. */ |
|||
#define PACKAGE_BUGREPORT "" |
|||
|
|||
/* Define to the full name of this package. */ |
|||
#define PACKAGE_NAME "" |
|||
|
|||
/* Define to the full name and version of this package. */ |
|||
#define PACKAGE_STRING "" |
|||
|
|||
/* Define to the one symbol short name of this package. */ |
|||
#define PACKAGE_TARNAME "" |
|||
|
|||
/* Define to the version of this package. */ |
|||
#define PACKAGE_VERSION "" |
|||
|
|||
/* Define to 1 if you have the ANSI C header files. */ |
|||
#define STDC_HEADERS 1 |
|||
|
|||
/* Version number of package */ |
|||
#define VERSION "1.0" |
@ -1,94 +0,0 @@ |
|||
/* config.h. Generated from config.h.in by configure. */ |
|||
/* config.h.in. Generated from configure.ac by autoheader. */ |
|||
|
|||
#include <linux/version.h> |
|||
#include <features.h> |
|||
|
|||
/* Define to 1 if you have the <dlfcn.h> header file. */ |
|||
#define HAVE_DLFCN_H 1 |
|||
|
|||
/* fdatasync(2) is available */ |
|||
#define HAVE_FDATASYNC 1 |
|||
|
|||
/* utimes(2) is available */ |
|||
#define HAVE_UTIMES 1 |
|||
|
|||
/* futimes(2) is available but we make the syscall directly. */ |
|||
#undef HAVE_FUTIMES |
|||
|
|||
/* Define to 1 if you have the <inttypes.h> header file. */ |
|||
#define HAVE_INTTYPES_H 1 |
|||
|
|||
/* Define to 1 if you have the <memory.h> header file. */ |
|||
#define HAVE_MEMORY_H 1 |
|||
|
|||
/* pread(2) and pwrite(2) are available */ |
|||
#define HAVE_PREADWRITE 1 |
|||
|
|||
/* readahead(2) is available (linux) */ |
|||
#define HAVE_READAHEAD 1 |
|||
|
|||
/* sendfile(2) is available and supported */ |
|||
#define HAVE_SENDFILE 1 |
|||
|
|||
/* Define to 1 if you have the <stdint.h> header file. */ |
|||
#define HAVE_STDINT_H 1 |
|||
|
|||
/* Define to 1 if you have the <stdlib.h> header file. */ |
|||
#define HAVE_STDLIB_H 1 |
|||
|
|||
/* Define to 1 if you have the <strings.h> header file. */ |
|||
#define HAVE_STRINGS_H 1 |
|||
|
|||
/* Define to 1 if you have the <string.h> header file. */ |
|||
#define HAVE_STRING_H 1 |
|||
|
|||
/* sync_file_range(2) is available if kernel >= 2.6.17 and glibc >= 2.6 */ |
|||
#if LINUX_VERSION_CODE >= 0x020611 && __GLIBC_PREREQ(2, 6) |
|||
#define HAVE_SYNC_FILE_RANGE 1 |
|||
#else |
|||
#define HAVE_SYNC_FILE_RANGE 0 |
|||
#endif |
|||
|
|||
/* Define to 1 if you have the <sys/stat.h> header file. */ |
|||
#define HAVE_SYS_STAT_H 1 |
|||
|
|||
/* Define to 1 if you have the <sys/types.h> header file. */ |
|||
#define HAVE_SYS_TYPES_H 1 |
|||
|
|||
/* Define to 1 if you have the <sys/syscall.h> header file. */ |
|||
#define HAVE_SYS_SYSCALL_H 1 |
|||
|
|||
/* Define to 1 if you have the <unistd.h> header file. */ |
|||
#define HAVE_UNISTD_H 1 |
|||
|
|||
/* Define to the sub-directory in which libtool stores uninstalled libraries.
|
|||
*/ |
|||
#define LT_OBJDIR ".libs/" |
|||
|
|||
/* Name of package */ |
|||
#define PACKAGE "libeio" |
|||
|
|||
/* Define to the address where bug reports for this package should be sent. */ |
|||
#define PACKAGE_BUGREPORT "" |
|||
|
|||
/* Define to the full name of this package. */ |
|||
#define PACKAGE_NAME "" |
|||
|
|||
/* Define to the full name and version of this package. */ |
|||
#define PACKAGE_STRING "" |
|||
|
|||
/* Define to the one symbol short name of this package. */ |
|||
#define PACKAGE_TARNAME "" |
|||
|
|||
/* Define to the home page for this package. */ |
|||
#define PACKAGE_URL "" |
|||
|
|||
/* Define to the version of this package. */ |
|||
#define PACKAGE_VERSION "" |
|||
|
|||
/* Define to 1 if you have the ANSI C header files. */ |
|||
#define STDC_HEADERS 1 |
|||
|
|||
/* Version number of package */ |
|||
#define VERSION "1.0" |
@ -1,81 +0,0 @@ |
|||
/* config.h. Generated from config.h.in by configure. */ |
|||
/* config.h.in. Generated from configure.ac by autoheader. */ |
|||
|
|||
/* Define to 1 if you have the <dlfcn.h> header file. */ |
|||
#define HAVE_DLFCN_H 1 |
|||
|
|||
/* fdatasync(2) is available */ |
|||
/* #undef HAVE_FDATASYNC */ |
|||
|
|||
/* utimes(2) is available */ |
|||
#define HAVE_UTIMES 1 |
|||
|
|||
/* futimes(2) is available */ |
|||
#define HAVE_FUTIMES 1 |
|||
|
|||
/* Define to 1 if you have the <inttypes.h> header file. */ |
|||
#define HAVE_INTTYPES_H 1 |
|||
|
|||
/* Define to 1 if you have the <memory.h> header file. */ |
|||
#define HAVE_MEMORY_H 1 |
|||
|
|||
/* pread(2) and pwrite(2) are available */ |
|||
#define HAVE_PREADWRITE 1 |
|||
|
|||
/* readahead(2) is available (linux) */ |
|||
/* #undef HAVE_READAHEAD */ |
|||
|
|||
/* sendfile(2) is available and supported */ |
|||
#define HAVE_SENDFILE 0 |
|||
|
|||
/* Define to 1 if you have the <stdint.h> header file. */ |
|||
#define HAVE_STDINT_H 1 |
|||
|
|||
/* Define to 1 if you have the <stdlib.h> header file. */ |
|||
#define HAVE_STDLIB_H 1 |
|||
|
|||
/* Define to 1 if you have the <strings.h> header file. */ |
|||
#define HAVE_STRINGS_H 1 |
|||
|
|||
/* Define to 1 if you have the <string.h> header file. */ |
|||
#define HAVE_STRING_H 1 |
|||
|
|||
/* sync_file_range(2) is available */ |
|||
/* #undef HAVE_SYNC_FILE_RANGE */ |
|||
|
|||
/* Define to 1 if you have the <sys/stat.h> header file. */ |
|||
#define HAVE_SYS_STAT_H 1 |
|||
|
|||
/* Define to 1 if you have the <sys/types.h> header file. */ |
|||
#define HAVE_SYS_TYPES_H 1 |
|||
|
|||
/* Define to 1 if you have the <unistd.h> header file. */ |
|||
#define HAVE_UNISTD_H 1 |
|||
|
|||
/* Define to the sub-directory in which libtool stores uninstalled libraries.
|
|||
*/ |
|||
#define LT_OBJDIR ".libs/" |
|||
|
|||
/* Name of package */ |
|||
#define PACKAGE "libeio" |
|||
|
|||
/* Define to the address where bug reports for this package should be sent. */ |
|||
#define PACKAGE_BUGREPORT "" |
|||
|
|||
/* Define to the full name of this package. */ |
|||
#define PACKAGE_NAME "" |
|||
|
|||
/* Define to the full name and version of this package. */ |
|||
#define PACKAGE_STRING "" |
|||
|
|||
/* Define to the one symbol short name of this package. */ |
|||
#define PACKAGE_TARNAME "" |
|||
|
|||
/* Define to the version of this package. */ |
|||
#define PACKAGE_VERSION "" |
|||
|
|||
/* Define to 1 if you have the ANSI C header files. */ |
|||
#define STDC_HEADERS 1 |
|||
|
|||
/* Version number of package */ |
|||
#define VERSION "1.0" |
@ -1,137 +0,0 @@ |
|||
/* config.h. Generated from config.h.in by configure. */ |
|||
/* config.h.in. Generated from configure.ac by autoheader. */ |
|||
|
|||
/* Define to 1 if you have the <dlfcn.h> header file. */ |
|||
#define HAVE_DLFCN_H 1 |
|||
|
|||
/* fallocate(2) is available */ |
|||
/* #undef HAVE_FALLOCATE */ |
|||
|
|||
/* fdatasync(2) is available */ |
|||
/* #undef HAVE_FDATASYNC */ |
|||
|
|||
/* futimes(2) is available */ |
|||
#define HAVE_FUTIMES 1 |
|||
|
|||
/* Define to 1 if you have the <inttypes.h> header file. */ |
|||
#define HAVE_INTTYPES_H 1 |
|||
|
|||
/* Define to 1 if you have the <memory.h> header file. */ |
|||
#define HAVE_MEMORY_H 1 |
|||
|
|||
/* posix_fadvise(2) is available */ |
|||
/* #undef HAVE_POSIX_FADVISE */ |
|||
|
|||
/* posix_madvise(2) is available */ |
|||
#define HAVE_POSIX_MADVISE 1 |
|||
|
|||
/* prctl(PR_SET_NAME) is available */ |
|||
/* #undef HAVE_PRCTL_SET_NAME */ |
|||
|
|||
/* pread(2) and pwrite(2) are available */ |
|||
#define HAVE_PREADWRITE 1 |
|||
|
|||
/* readahead(2) is available (linux) */ |
|||
/* #undef HAVE_READAHEAD */ |
|||
|
|||
/* sendfile(2) is available and supported */ |
|||
/* #undef HAVE_SENDFILE */ |
|||
|
|||
/* Define to 1 if you have the <stdint.h> header file. */ |
|||
#define HAVE_STDINT_H 1 |
|||
|
|||
/* Define to 1 if you have the <stdlib.h> header file. */ |
|||
#define HAVE_STDLIB_H 1 |
|||
|
|||
/* Define to 1 if you have the <strings.h> header file. */ |
|||
#define HAVE_STRINGS_H 1 |
|||
|
|||
/* Define to 1 if you have the <string.h> header file. */ |
|||
#define HAVE_STRING_H 1 |
|||
|
|||
/* sync_file_range(2) is available */ |
|||
/* #undef HAVE_SYNC_FILE_RANGE */ |
|||
|
|||
/* Define to 1 if you have the <sys/prctl.h> header file. */ |
|||
/* #undef HAVE_SYS_PRCTL_H */ |
|||
|
|||
/* Define to 1 if you have the <sys/stat.h> header file. */ |
|||
#define HAVE_SYS_STAT_H 1 |
|||
|
|||
/* syscall(__NR_syncfs) is available */ |
|||
/* #undef HAVE_SYS_SYNCFS */ |
|||
|
|||
/* Define to 1 if you have the <sys/syscall.h> header file. */ |
|||
#define HAVE_SYS_SYSCALL_H 1 |
|||
|
|||
/* Define to 1 if you have the <sys/types.h> header file. */ |
|||
#define HAVE_SYS_TYPES_H 1 |
|||
|
|||
/* Define to 1 if you have the <unistd.h> header file. */ |
|||
#define HAVE_UNISTD_H 1 |
|||
|
|||
/* utimes(2) is available */ |
|||
#define HAVE_UTIMES 1 |
|||
|
|||
/* Define to the sub-directory in which libtool stores uninstalled libraries.
|
|||
*/ |
|||
#define LT_OBJDIR ".libs/" |
|||
|
|||
/* Name of package */ |
|||
#define PACKAGE "libeio" |
|||
|
|||
/* Define to the address where bug reports for this package should be sent. */ |
|||
#define PACKAGE_BUGREPORT "" |
|||
|
|||
/* Define to the full name of this package. */ |
|||
#define PACKAGE_NAME "" |
|||
|
|||
/* Define to the full name and version of this package. */ |
|||
#define PACKAGE_STRING "" |
|||
|
|||
/* Define to the one symbol short name of this package. */ |
|||
#define PACKAGE_TARNAME "" |
|||
|
|||
/* Define to the home page for this package. */ |
|||
#define PACKAGE_URL "" |
|||
|
|||
/* Define to the version of this package. */ |
|||
#define PACKAGE_VERSION "" |
|||
|
|||
/* Define to 1 if you have the ANSI C header files. */ |
|||
#define STDC_HEADERS 1 |
|||
|
|||
/* Enable extensions on AIX 3, Interix. */ |
|||
#ifndef _ALL_SOURCE |
|||
# define _ALL_SOURCE 1 |
|||
#endif |
|||
/* Enable GNU extensions on systems that have them. */ |
|||
#ifndef _GNU_SOURCE |
|||
# define _GNU_SOURCE 1 |
|||
#endif |
|||
/* Enable threading extensions on Solaris. */ |
|||
#ifndef _POSIX_PTHREAD_SEMANTICS |
|||
# define _POSIX_PTHREAD_SEMANTICS 1 |
|||
#endif |
|||
/* Enable extensions on HP NonStop. */ |
|||
#ifndef _TANDEM_SOURCE |
|||
# define _TANDEM_SOURCE 1 |
|||
#endif |
|||
/* Enable general extensions on Solaris. */ |
|||
#ifndef __EXTENSIONS__ |
|||
# define __EXTENSIONS__ 1 |
|||
#endif |
|||
|
|||
|
|||
/* Version number of package */ |
|||
#define VERSION "1.0" |
|||
|
|||
/* Define to 1 if on MINIX. */ |
|||
/* #undef _MINIX */ |
|||
|
|||
/* Define to 2 if the system does not provide POSIX.1 features except with
|
|||
this defined. */ |
|||
/* #undef _POSIX_1_SOURCE */ |
|||
|
|||
/* Define to 1 if you need to in order for `stat' and other things to work. */ |
|||
/* #undef _POSIX_SOURCE */ |
@ -1,84 +0,0 @@ |
|||
/* config.h. Generated from config.h.in by configure. */ |
|||
/* config.h.in. Generated from configure.ac by autoheader. */ |
|||
|
|||
/* Define to 1 if you have the <dlfcn.h> header file. */ |
|||
#define HAVE_DLFCN_H 1 |
|||
|
|||
/* fdatasync(2) is available */ |
|||
#define HAVE_FDATASYNC 1 |
|||
|
|||
/* utimes(2) is available */ |
|||
#define HAVE_UTIMES 1 |
|||
|
|||
/* futimes(2) is available */ |
|||
#define HAVE_FUTIMES 1 |
|||
|
|||
/* Define to 1 if you have the <inttypes.h> header file. */ |
|||
#define HAVE_INTTYPES_H 1 |
|||
|
|||
/* Define to 1 if you have the <memory.h> header file. */ |
|||
#define HAVE_MEMORY_H 1 |
|||
|
|||
/* pread(2) and pwrite(2) are available */ |
|||
#define HAVE_PREADWRITE 1 |
|||
|
|||
/* readahead(2) is available (linux) */ |
|||
/* #undef HAVE_READAHEAD */ |
|||
|
|||
/* sendfile(2) is available and supported */ |
|||
/* #undef HAVE_SENDFILE */ |
|||
|
|||
/* Define to 1 if you have the <stdint.h> header file. */ |
|||
#define HAVE_STDINT_H 1 |
|||
|
|||
/* Define to 1 if you have the <stdlib.h> header file. */ |
|||
#define HAVE_STDLIB_H 1 |
|||
|
|||
/* Define to 1 if you have the <strings.h> header file. */ |
|||
#define HAVE_STRINGS_H 1 |
|||
|
|||
/* Define to 1 if you have the <string.h> header file. */ |
|||
#define HAVE_STRING_H 1 |
|||
|
|||
/* sync_file_range(2) is available */ |
|||
/* #undef HAVE_SYNC_FILE_RANGE */ |
|||
|
|||
/* Define to 1 if you have the <sys/stat.h> header file. */ |
|||
#define HAVE_SYS_STAT_H 1 |
|||
|
|||
/* Define to 1 if you have the <sys/types.h> header file. */ |
|||
#define HAVE_SYS_TYPES_H 1 |
|||
|
|||
/* Define to 1 if you have the <unistd.h> header file. */ |
|||
#define HAVE_UNISTD_H 1 |
|||
|
|||
/* Define to the sub-directory in which libtool stores uninstalled libraries.
|
|||
*/ |
|||
#define LT_OBJDIR ".libs/" |
|||
|
|||
/* Name of package */ |
|||
#define PACKAGE "libeio" |
|||
|
|||
/* Define to the address where bug reports for this package should be sent. */ |
|||
#define PACKAGE_BUGREPORT "" |
|||
|
|||
/* Define to the full name of this package. */ |
|||
#define PACKAGE_NAME "" |
|||
|
|||
/* Define to the full name and version of this package. */ |
|||
#define PACKAGE_STRING "" |
|||
|
|||
/* Define to the one symbol short name of this package. */ |
|||
#define PACKAGE_TARNAME "" |
|||
|
|||
/* Define to the home page for this package. */ |
|||
#define PACKAGE_URL "" |
|||
|
|||
/* Define to the version of this package. */ |
|||
#define PACKAGE_VERSION "" |
|||
|
|||
/* Define to 1 if you have the ANSI C header files. */ |
|||
#define STDC_HEADERS 1 |
|||
|
|||
/* Version number of package */ |
|||
#define VERSION "1.0" |
@ -1,22 +0,0 @@ |
|||
AC_PREREQ(2.59) |
|||
AC_INIT |
|||
AC_CONFIG_SRCDIR([eio.h]) |
|||
AC_CONFIG_HEADERS([config.h]) |
|||
|
|||
AM_INIT_AUTOMAKE(libeio,1.0) |
|||
AM_MAINTAINER_MODE |
|||
|
|||
AC_GNU_SOURCE |
|||
|
|||
AC_PROG_LIBTOOL |
|||
|
|||
AC_PROG_CC |
|||
|
|||
if test "x$GCC" = xyes ; then |
|||
CFLAGS="-O3 $CFLAGS" |
|||
fi |
|||
|
|||
m4_include([libeio.m4]) |
|||
|
|||
AC_CONFIG_FILES([Makefile]) |
|||
AC_OUTPUT |
@ -1,194 +0,0 @@ |
|||
#include <stdio.h> |
|||
#include <stdlib.h> |
|||
#include <unistd.h> |
|||
#include <poll.h> |
|||
#include <string.h> |
|||
#include <assert.h> |
|||
#include <fcntl.h> |
|||
#include <sys/types.h> |
|||
#include <sys/stat.h> |
|||
|
|||
#include "eio.h" |
|||
|
|||
int respipe [2]; |
|||
|
|||
void |
|||
want_poll (void) |
|||
{ |
|||
char dummy; |
|||
printf ("want_poll ()\n"); |
|||
write (respipe [1], &dummy, 1); |
|||
} |
|||
|
|||
void |
|||
done_poll (void) |
|||
{ |
|||
char dummy; |
|||
printf ("done_poll ()\n"); |
|||
read (respipe [0], &dummy, 1); |
|||
} |
|||
|
|||
void |
|||
event_loop (void) |
|||
{ |
|||
// an event loop. yeah.
|
|||
struct pollfd pfd; |
|||
pfd.fd = respipe [0]; |
|||
pfd.events = POLLIN; |
|||
|
|||
printf ("\nentering event loop\n"); |
|||
while (eio_nreqs ()) |
|||
{ |
|||
poll (&pfd, 1, -1); |
|||
printf ("eio_poll () = %d\n", eio_poll ()); |
|||
} |
|||
printf ("leaving event loop\n"); |
|||
} |
|||
|
|||
int |
|||
res_cb (eio_req *req) |
|||
{ |
|||
printf ("res_cb(%d|%s) = %d\n", req->type, req->data ? req->data : "?", EIO_RESULT (req)); |
|||
|
|||
if (req->result < 0) |
|||
abort (); |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
int |
|||
readdir_cb (eio_req *req) |
|||
{ |
|||
char *buf = (char *)EIO_BUF (req); |
|||
|
|||
printf ("readdir_cb = %d\n", EIO_RESULT (req)); |
|||
|
|||
if (EIO_RESULT (req) < 0) |
|||
return 0; |
|||
|
|||
while (EIO_RESULT (req)--) |
|||
{ |
|||
printf ("readdir = <%s>\n", buf); |
|||
buf += strlen (buf) + 1; |
|||
} |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
int |
|||
stat_cb (eio_req *req) |
|||
{ |
|||
struct stat *buf = EIO_STAT_BUF (req); |
|||
|
|||
if (req->type == EIO_FSTAT) |
|||
printf ("fstat_cb = %d\n", EIO_RESULT (req)); |
|||
else |
|||
printf ("stat_cb(%s) = %d\n", EIO_PATH (req), EIO_RESULT (req)); |
|||
|
|||
if (!EIO_RESULT (req)) |
|||
printf ("stat size %d perm 0%o\n", buf->st_size, buf->st_mode & 0777); |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
int |
|||
read_cb (eio_req *req) |
|||
{ |
|||
unsigned char *buf = (unsigned char *)EIO_BUF (req); |
|||
|
|||
printf ("read_cb = %d (%02x%02x%02x%02x %02x%02x%02x%02x)\n", |
|||
EIO_RESULT (req), |
|||
buf [0], buf [1], buf [2], buf [3], |
|||
buf [4], buf [5], buf [6], buf [7]); |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
int last_fd; |
|||
|
|||
int |
|||
open_cb (eio_req *req) |
|||
{ |
|||
printf ("open_cb = %d\n", EIO_RESULT (req)); |
|||
|
|||
last_fd = EIO_RESULT (req); |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
int |
|||
main (void) |
|||
{ |
|||
printf ("pipe ()\n"); |
|||
if (pipe (respipe)) abort (); |
|||
|
|||
printf ("eio_init ()\n"); |
|||
if (eio_init (want_poll, done_poll)) abort (); |
|||
|
|||
do |
|||
{ |
|||
/* avoid relative paths yourself(!) */ |
|||
eio_mkdir ("eio-test-dir", 0777, 0, res_cb, "mkdir"); |
|||
eio_nop (0, res_cb, "nop"); |
|||
event_loop (); |
|||
|
|||
eio_stat ("eio-test-dir", 0, stat_cb, "stat"); |
|||
eio_lstat ("eio-test-dir", 0, stat_cb, "stat"); |
|||
eio_open ("eio-test-dir/eio-test-file", O_RDWR | O_CREAT, 0777, 0, open_cb, "open"); |
|||
eio_symlink ("test", "eio-test-dir/eio-symlink", 0, res_cb, "symlink"); |
|||
eio_mknod ("eio-test-dir/eio-fifo", S_IFIFO, 0, 0, res_cb, "mknod"); |
|||
event_loop (); |
|||
|
|||
eio_utime ("eio-test-dir", 12345.678, 23456.789, 0, res_cb, "utime"); |
|||
eio_futime (last_fd, 92345.678, 93456.789, 0, res_cb, "futime"); |
|||
eio_chown ("eio-test-dir", getuid (), getgid (), 0, res_cb, "chown"); |
|||
eio_fchown (last_fd, getuid (), getgid (), 0, res_cb, "fchown"); |
|||
eio_fchmod (last_fd, 0723, 0, res_cb, "fchmod"); |
|||
eio_readdir ("eio-test-dir", 0, 0, readdir_cb, "readdir"); |
|||
eio_readdir ("/nonexistant", 0, 0, readdir_cb, "readdir"); |
|||
eio_fstat (last_fd, 0, stat_cb, "stat"); |
|||
eio_write (last_fd, "test\nfail\n", 10, 4, 0, res_cb, "write"); |
|||
event_loop (); |
|||
|
|||
eio_read (last_fd, 0, 8, 0, EIO_PRI_DEFAULT, read_cb, "read"); |
|||
eio_readlink ("eio-test-dir/eio-symlink", 0, res_cb, "readlink"); |
|||
event_loop (); |
|||
|
|||
eio_dup2 (1, 2, EIO_PRI_DEFAULT, res_cb, "dup"); // dup stdout to stderr
|
|||
eio_chmod ("eio-test-dir", 0765, 0, res_cb, "chmod"); |
|||
eio_ftruncate (last_fd, 9, 0, res_cb, "ftruncate"); |
|||
eio_fdatasync (last_fd, 0, res_cb, "fdatasync"); |
|||
eio_fsync (last_fd, 0, res_cb, "fsync"); |
|||
eio_sync (0, res_cb, "sync"); |
|||
eio_busy (0.5, 0, res_cb, "busy"); |
|||
event_loop (); |
|||
|
|||
eio_sendfile (1, last_fd, 4, 5, 0, res_cb, "sendfile"); // write "test\n" to stdout
|
|||
eio_fstat (last_fd, 0, stat_cb, "stat"); |
|||
event_loop (); |
|||
|
|||
eio_truncate ("eio-test-dir/eio-test-file", 6, 0, res_cb, "truncate"); |
|||
eio_readahead (last_fd, 0, 64, 0, res_cb, "readahead"); |
|||
event_loop (); |
|||
|
|||
eio_close (last_fd, 0, res_cb, "close"); |
|||
eio_link ("eio-test-dir/eio-test-file", "eio-test-dir/eio-test-file-2", 0, res_cb, "link"); |
|||
event_loop (); |
|||
|
|||
eio_rename ("eio-test-dir/eio-test-file", "eio-test-dir/eio-test-file-renamed", 0, res_cb, "rename"); |
|||
event_loop (); |
|||
|
|||
eio_unlink ("eio-test-dir/eio-fifo", 0, res_cb, "unlink"); |
|||
eio_unlink ("eio-test-dir/eio-symlink", 0, res_cb, "unlink"); |
|||
eio_unlink ("eio-test-dir/eio-test-file-2", 0, res_cb, "unlink"); |
|||
eio_unlink ("eio-test-dir/eio-test-file-renamed", 0, res_cb, "unlink"); |
|||
event_loop (); |
|||
|
|||
eio_rmdir ("eio-test-dir", 0, res_cb, "rmdir"); |
|||
event_loop (); |
|||
} |
|||
while (0); |
|||
|
|||
return 0; |
|||
} |
|||
|
@ -1,370 +0,0 @@ |
|||
/*
|
|||
* libecb - http://software.schmorp.de/pkg/libecb
|
|||
* |
|||
* Copyright (©) 2009-2011 Marc Alexander Lehmann <libecb@schmorp.de> |
|||
* Copyright (©) 2011 Emanuele Giaquinta |
|||
* All rights reserved. |
|||
* |
|||
* Redistribution and use in source and binary forms, with or without modifica- |
|||
* tion, are permitted provided that the following conditions are met: |
|||
* |
|||
* 1. Redistributions of source code must retain the above copyright notice, |
|||
* this list of conditions and the following disclaimer. |
|||
* |
|||
* 2. Redistributions in binary form must reproduce the above copyright |
|||
* notice, this list of conditions and the following disclaimer in the |
|||
* documentation and/or other materials provided with the distribution. |
|||
* |
|||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
|||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER- |
|||
* CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
|||
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- |
|||
* CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
|||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
|||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH- |
|||
* ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
|||
* OF THE POSSIBILITY OF SUCH DAMAGE. |
|||
*/ |
|||
|
|||
#ifndef ECB_H |
|||
#define ECB_H |
|||
|
|||
#ifdef _WIN32 |
|||
typedef signed char int8_t; |
|||
typedef unsigned char uint8_t; |
|||
typedef signed short int16_t; |
|||
typedef unsigned short uint16_t; |
|||
typedef signed int int32_t; |
|||
typedef unsigned int uint32_t; |
|||
#if __GNUC__ |
|||
typedef signed long long int64_t; |
|||
typedef unsigned long long uint64_t; |
|||
#else /* _MSC_VER || __BORLANDC__ */ |
|||
typedef signed __int64 int64_t; |
|||
typedef unsigned __int64 uint64_t; |
|||
#endif |
|||
#else |
|||
#include <inttypes.h> |
|||
#endif |
|||
|
|||
/* many compilers define _GNUC_ to some versions but then only implement
|
|||
* what their idiot authors think are the "more important" extensions, |
|||
* causing enourmous grief in return for some better fake benchmark numbers. |
|||
* or so. |
|||
* we try to detect these and simply assume they are not gcc - if they have |
|||
* an issue with that they should have done it right in the first place. |
|||
*/ |
|||
#ifndef ECB_GCC_VERSION |
|||
#if !defined(__GNUC_MINOR__) || defined(__INTEL_COMPILER) || defined(__SUNPRO_C) || defined(__SUNPRO_CC) || defined(__llvm__) || defined(__clang__) |
|||
#define ECB_GCC_VERSION(major,minor) 0 |
|||
#else |
|||
#define ECB_GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
|||
#endif |
|||
#endif |
|||
|
|||
/*****************************************************************************/ |
|||
|
|||
#ifndef ECB_MEMORY_FENCE |
|||
#if ECB_GCC_VERSION(2,5) |
|||
#if defined(__x86) || defined(__i386) |
|||
#define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory") |
|||
#define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE /* non-lock xchg might be enough */ |
|||
#define ECB_MEMORY_FENCE_RELEASE do { } while (0) /* unlikely to change in future cpus */ |
|||
#elif __amd64 |
|||
#define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory") |
|||
#define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("lfence" : : : "memory") |
|||
#define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("sfence") /* play safe - not needed in any current cpu */ |
|||
#endif |
|||
#endif |
|||
#endif |
|||
|
|||
#ifndef ECB_MEMORY_FENCE |
|||
#if ECB_GCC_VERSION(4,4) |
|||
#define ECB_MEMORY_FENCE __sync_synchronize () |
|||
#define ECB_MEMORY_FENCE_ACQUIRE ({ char dummy = 0; __sync_lock_test_and_set (&dummy, 1); }) |
|||
#define ECB_MEMORY_FENCE_RELEASE ({ char dummy = 1; __sync_lock_release (&dummy ); }) |
|||
#elif _MSC_VER >= 1400 /* VC++ 2005 */ |
|||
#pragma intrinsic(_ReadBarrier,_WriteBarrier,_ReadWriteBarrier) |
|||
#define ECB_MEMORY_FENCE _ReadWriteBarrier () |
|||
#define ECB_MEMORY_FENCE_ACQUIRE _ReadWriteBarrier () /* according to msdn, _ReadBarrier is not a load fence */ |
|||
#define ECB_MEMORY_FENCE_RELEASE _WriteBarrier () |
|||
#elif defined(_WIN32) |
|||
#include <WinNT.h> |
|||
#define ECB_MEMORY_FENCE MemoryBarrier () /* actually just xchg on x86... scary */ |
|||
#define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE |
|||
#define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE |
|||
#endif |
|||
#endif |
|||
|
|||
#ifndef ECB_MEMORY_FENCE |
|||
/*
|
|||
* if you get undefined symbol references to pthread_mutex_lock, |
|||
* or failure to find pthread.h, then you should implement |
|||
* the ECB_MEMORY_FENCE operations for your cpu/compiler |
|||
* OR proide pthread.h and link against the posix thread library |
|||
* of your system. |
|||
*/ |
|||
#include <pthread.h> |
|||
|
|||
static pthread_mutex_t ecb_mf_lock = PTHREAD_MUTEX_INITIALIZER; |
|||
#define ECB_MEMORY_FENCE do { pthread_mutex_lock (&ecb_mf_lock); pthread_mutex_unlock (&ecb_mf_lock); } while (0) |
|||
#define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE |
|||
#define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE |
|||
#endif |
|||
|
|||
/*****************************************************************************/ |
|||
|
|||
#define ECB_C99 (__STDC_VERSION__ >= 199901L) |
|||
|
|||
#if __cplusplus |
|||
#define ecb_inline static inline |
|||
#elif ECB_GCC_VERSION(2,5) |
|||
#define ecb_inline static __inline__ |
|||
#elif ECB_C99 |
|||
#define ecb_inline static inline |
|||
#else |
|||
#define ecb_inline static |
|||
#endif |
|||
|
|||
#if ECB_GCC_VERSION(3,3) |
|||
#define ecb_restrict __restrict__ |
|||
#elif ECB_C99 |
|||
#define ecb_restrict restrict |
|||
#else |
|||
#define ecb_restrict |
|||
#endif |
|||
|
|||
typedef int ecb_bool; |
|||
|
|||
#define ECB_CONCAT_(a, b) a ## b |
|||
#define ECB_CONCAT(a, b) ECB_CONCAT_(a, b) |
|||
#define ECB_STRINGIFY_(a) # a |
|||
#define ECB_STRINGIFY(a) ECB_STRINGIFY_(a) |
|||
|
|||
#define ecb_function_ ecb_inline |
|||
|
|||
#if ECB_GCC_VERSION(3,1) |
|||
#define ecb_attribute(attrlist) __attribute__(attrlist) |
|||
#define ecb_is_constant(expr) __builtin_constant_p (expr) |
|||
#define ecb_expect(expr,value) __builtin_expect ((expr),(value)) |
|||
#define ecb_prefetch(addr,rw,locality) __builtin_prefetch (addr, rw, locality) |
|||
#else |
|||
#define ecb_attribute(attrlist) |
|||
#define ecb_is_constant(expr) 0 |
|||
#define ecb_expect(expr,value) (expr) |
|||
#define ecb_prefetch(addr,rw,locality) |
|||
#endif |
|||
|
|||
/* no emulation for ecb_decltype */ |
|||
#if ECB_GCC_VERSION(4,5) |
|||
#define ecb_decltype(x) __decltype(x) |
|||
#elif ECB_GCC_VERSION(3,0) |
|||
#define ecb_decltype(x) __typeof(x) |
|||
#endif |
|||
|
|||
#define ecb_noinline ecb_attribute ((__noinline__)) |
|||
#define ecb_noreturn ecb_attribute ((__noreturn__)) |
|||
#define ecb_unused ecb_attribute ((__unused__)) |
|||
#define ecb_const ecb_attribute ((__const__)) |
|||
#define ecb_pure ecb_attribute ((__pure__)) |
|||
|
|||
#if ECB_GCC_VERSION(4,3) |
|||
#define ecb_artificial ecb_attribute ((__artificial__)) |
|||
#define ecb_hot ecb_attribute ((__hot__)) |
|||
#define ecb_cold ecb_attribute ((__cold__)) |
|||
#else |
|||
#define ecb_artificial |
|||
#define ecb_hot |
|||
#define ecb_cold |
|||
#endif |
|||
|
|||
/* put around conditional expressions if you are very sure that the */ |
|||
/* expression is mostly true or mostly false. note that these return */ |
|||
/* booleans, not the expression. */ |
|||
#define ecb_expect_false(expr) ecb_expect (!!(expr), 0) |
|||
#define ecb_expect_true(expr) ecb_expect (!!(expr), 1) |
|||
/* for compatibility to the rest of the world */ |
|||
#define ecb_likely(expr) ecb_expect_true (expr) |
|||
#define ecb_unlikely(expr) ecb_expect_false (expr) |
|||
|
|||
/* count trailing zero bits and count # of one bits */ |
|||
#if ECB_GCC_VERSION(3,4) |
|||
/* we assume int == 32 bit, long == 32 or 64 bit and long long == 64 bit */ |
|||
#define ecb_ld32(x) (__builtin_clz (x) ^ 31) |
|||
#define ecb_ld64(x) (__builtin_clzll (x) ^ 63) |
|||
#define ecb_ctz32(x) __builtin_ctz (x) |
|||
#define ecb_ctz64(x) __builtin_ctzll (x) |
|||
#define ecb_popcount32(x) __builtin_popcount (x) |
|||
/* no popcountll */ |
|||
#else |
|||
ecb_function_ int ecb_ctz32 (uint32_t x) ecb_const; |
|||
ecb_function_ int |
|||
ecb_ctz32 (uint32_t x) |
|||
{ |
|||
int r = 0; |
|||
|
|||
x &= ~x + 1; /* this isolates the lowest bit */ |
|||
|
|||
#if ECB_branchless_on_i386 |
|||
r += !!(x & 0xaaaaaaaa) << 0; |
|||
r += !!(x & 0xcccccccc) << 1; |
|||
r += !!(x & 0xf0f0f0f0) << 2; |
|||
r += !!(x & 0xff00ff00) << 3; |
|||
r += !!(x & 0xffff0000) << 4; |
|||
#else |
|||
if (x & 0xaaaaaaaa) r += 1; |
|||
if (x & 0xcccccccc) r += 2; |
|||
if (x & 0xf0f0f0f0) r += 4; |
|||
if (x & 0xff00ff00) r += 8; |
|||
if (x & 0xffff0000) r += 16; |
|||
#endif |
|||
|
|||
return r; |
|||
} |
|||
|
|||
ecb_function_ int ecb_ctz64 (uint64_t x) ecb_const; |
|||
ecb_function_ int |
|||
ecb_ctz64 (uint64_t x) |
|||
{ |
|||
int shift = x & 0xffffffffU ? 0 : 32; |
|||
return ecb_ctz32 (x >> shift) + shift; |
|||
} |
|||
|
|||
ecb_function_ int ecb_popcount32 (uint32_t x) ecb_const; |
|||
ecb_function_ int |
|||
ecb_popcount32 (uint32_t x) |
|||
{ |
|||
x -= (x >> 1) & 0x55555555; |
|||
x = ((x >> 2) & 0x33333333) + (x & 0x33333333); |
|||
x = ((x >> 4) + x) & 0x0f0f0f0f; |
|||
x *= 0x01010101; |
|||
|
|||
return x >> 24; |
|||
} |
|||
|
|||
/* you have the choice beetween something with a table lookup, */ |
|||
/* something using lots of bit arithmetic and a simple loop */ |
|||
/* we went for the loop */ |
|||
ecb_function_ int ecb_ld32 (uint32_t x) ecb_const; |
|||
ecb_function_ int ecb_ld32 (uint32_t x) |
|||
{ |
|||
int r = 0; |
|||
|
|||
if (x >> 16) { x >>= 16; r += 16; } |
|||
if (x >> 8) { x >>= 8; r += 8; } |
|||
if (x >> 4) { x >>= 4; r += 4; } |
|||
if (x >> 2) { x >>= 2; r += 2; } |
|||
if (x >> 1) { r += 1; } |
|||
|
|||
return r; |
|||
} |
|||
|
|||
ecb_function_ int ecb_ld64 (uint64_t x) ecb_const; |
|||
ecb_function_ int ecb_ld64 (uint64_t x) |
|||
{ |
|||
int r = 0; |
|||
|
|||
if (x >> 32) { x >>= 32; r += 32; } |
|||
|
|||
return r + ecb_ld32 (x); |
|||
} |
|||
#endif |
|||
|
|||
/* popcount64 is only available on 64 bit cpus as gcc builtin */ |
|||
/* so for this version we are lazy */ |
|||
ecb_function_ int ecb_popcount64 (uint64_t x) ecb_const; |
|||
ecb_function_ int |
|||
ecb_popcount64 (uint64_t x) |
|||
{ |
|||
return ecb_popcount32 (x) + ecb_popcount32 (x >> 32); |
|||
} |
|||
|
|||
ecb_inline uint8_t ecb_rotl8 (uint8_t x, unsigned int count) ecb_const; |
|||
ecb_inline uint8_t ecb_rotr8 (uint8_t x, unsigned int count) ecb_const; |
|||
ecb_inline uint16_t ecb_rotl16 (uint16_t x, unsigned int count) ecb_const; |
|||
ecb_inline uint16_t ecb_rotr16 (uint16_t x, unsigned int count) ecb_const; |
|||
ecb_inline uint32_t ecb_rotl32 (uint32_t x, unsigned int count) ecb_const; |
|||
ecb_inline uint32_t ecb_rotr32 (uint32_t x, unsigned int count) ecb_const; |
|||
ecb_inline uint64_t ecb_rotl64 (uint64_t x, unsigned int count) ecb_const; |
|||
ecb_inline uint64_t ecb_rotr64 (uint64_t x, unsigned int count) ecb_const; |
|||
|
|||
ecb_inline uint8_t ecb_rotl8 (uint8_t x, unsigned int count) { return (x >> ( 8 - count)) | (x << count); } |
|||
ecb_inline uint8_t ecb_rotr8 (uint8_t x, unsigned int count) { return (x << ( 8 - count)) | (x >> count); } |
|||
ecb_inline uint16_t ecb_rotl16 (uint16_t x, unsigned int count) { return (x >> (16 - count)) | (x << count); } |
|||
ecb_inline uint16_t ecb_rotr16 (uint16_t x, unsigned int count) { return (x << (16 - count)) | (x >> count); } |
|||
ecb_inline uint32_t ecb_rotl32 (uint32_t x, unsigned int count) { return (x >> (32 - count)) | (x << count); } |
|||
ecb_inline uint32_t ecb_rotr32 (uint32_t x, unsigned int count) { return (x << (32 - count)) | (x >> count); } |
|||
ecb_inline uint64_t ecb_rotl64 (uint64_t x, unsigned int count) { return (x >> (64 - count)) | (x << count); } |
|||
ecb_inline uint64_t ecb_rotr64 (uint64_t x, unsigned int count) { return (x << (64 - count)) | (x >> count); } |
|||
|
|||
#if ECB_GCC_VERSION(4,3) |
|||
#define ecb_bswap16(x) (__builtin_bswap32 (x) >> 16) |
|||
#define ecb_bswap32(x) __builtin_bswap32 (x) |
|||
#define ecb_bswap64(x) __builtin_bswap64 (x) |
|||
#else |
|||
ecb_function_ uint16_t ecb_bswap16 (uint16_t x) ecb_const; |
|||
ecb_function_ uint16_t |
|||
ecb_bswap16 (uint16_t x) |
|||
{ |
|||
return ecb_rotl16 (x, 8); |
|||
} |
|||
|
|||
ecb_function_ uint32_t ecb_bswap32 (uint32_t x) ecb_const; |
|||
ecb_function_ uint32_t |
|||
ecb_bswap32 (uint32_t x) |
|||
{ |
|||
return (((uint32_t)ecb_bswap16 (x)) << 16) | ecb_bswap16 (x >> 16); |
|||
} |
|||
|
|||
ecb_function_ uint64_t ecb_bswap64 (uint64_t x) ecb_const; |
|||
ecb_function_ uint64_t |
|||
ecb_bswap64 (uint64_t x) |
|||
{ |
|||
return (((uint64_t)ecb_bswap32 (x)) << 32) | ecb_bswap32 (x >> 32); |
|||
} |
|||
#endif |
|||
|
|||
#if ECB_GCC_VERSION(4,5) |
|||
#define ecb_unreachable() __builtin_unreachable () |
|||
#else |
|||
/* this seems to work fine, but gcc always emits a warning for it :/ */ |
|||
ecb_function_ void ecb_unreachable (void) ecb_noreturn; |
|||
ecb_function_ void ecb_unreachable (void) { } |
|||
#endif |
|||
|
|||
/* try to tell the compiler that some condition is definitely true */ |
|||
#define ecb_assume(cond) do { if (!(cond)) ecb_unreachable (); } while (0) |
|||
|
|||
ecb_function_ unsigned char ecb_byteorder_helper (void) ecb_const; |
|||
ecb_function_ unsigned char |
|||
ecb_byteorder_helper (void) |
|||
{ |
|||
const uint32_t u = 0x11223344; |
|||
return *(unsigned char *)&u; |
|||
} |
|||
|
|||
ecb_function_ ecb_bool ecb_big_endian (void) ecb_const; |
|||
ecb_function_ ecb_bool ecb_big_endian (void) { return ecb_byteorder_helper () == 0x11; } |
|||
ecb_function_ ecb_bool ecb_little_endian (void) ecb_const; |
|||
ecb_function_ ecb_bool ecb_little_endian (void) { return ecb_byteorder_helper () == 0x44; } |
|||
|
|||
#if ECB_GCC_VERSION(3,0) || ECB_C99 |
|||
#define ecb_mod(m,n) ((m) % (n) + ((m) % (n) < 0 ? (n) : 0)) |
|||
#else |
|||
#define ecb_mod(m,n) ((m) < 0 ? ((n) - 1 - ((-1 - (m)) % (n))) : ((m) % (n))) |
|||
#endif |
|||
|
|||
#if ecb_cplusplus_does_not_suck |
|||
/* does not work for local types (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2657.htm) */ |
|||
template<typename T, int N> |
|||
static inline int ecb_array_length (const T (&arr)[N]) |
|||
{ |
|||
return N; |
|||
} |
|||
#else |
|||
#define ecb_array_length(name) (sizeof (name) / sizeof (name [0])) |
|||
#endif |
|||
|
|||
#endif |
|||
|
File diff suppressed because it is too large
File diff suppressed because it is too large
@ -1,969 +0,0 @@ |
|||
=head1 NAME |
|||
|
|||
libeio - truly asynchronous POSIX I/O |
|||
|
|||
=head1 SYNOPSIS |
|||
|
|||
#include <eio.h> |
|||
|
|||
=head1 DESCRIPTION |
|||
|
|||
The newest version of this document is also available as an html-formatted |
|||
web page you might find easier to navigate when reading it for the first |
|||
time: L<http://pod.tst.eu/http://cvs.schmorp.de/libeio/eio.pod>. |
|||
|
|||
Note that this library is a by-product of the C<IO::AIO> perl |
|||
module, and many of the subtler points regarding requests lifetime |
|||
and so on are only documented in its documentation at the |
|||
moment: L<http://pod.tst.eu/http://cvs.schmorp.de/IO-AIO/AIO.pm>. |
|||
|
|||
=head2 FEATURES |
|||
|
|||
This library provides fully asynchronous versions of most POSIX functions |
|||
dealing with I/O. Unlike most asynchronous libraries, this not only |
|||
includes C<read> and C<write>, but also C<open>, C<stat>, C<unlink> and |
|||
similar functions, as well as less rarely ones such as C<mknod>, C<futime> |
|||
or C<readlink>. |
|||
|
|||
It also offers wrappers around C<sendfile> (Solaris, Linux, HP-UX and |
|||
FreeBSD, with emulation on other platforms) and C<readahead> (Linux, with |
|||
emulation elsewhere>). |
|||
|
|||
The goal is to enable you to write fully non-blocking programs. For |
|||
example, in a game server, you would not want to freeze for a few seconds |
|||
just because the server is running a backup and you happen to call |
|||
C<readdir>. |
|||
|
|||
=head2 TIME REPRESENTATION |
|||
|
|||
Libeio represents time as a single floating point number, representing the |
|||
(fractional) number of seconds since the (POSIX) epoch (somewhere near |
|||
the beginning of 1970, details are complicated, don't ask). This type is |
|||
called C<eio_tstamp>, but it is guaranteed to be of type C<double> (or |
|||
better), so you can freely use C<double> yourself. |
|||
|
|||
Unlike the name component C<stamp> might indicate, it is also used for |
|||
time differences throughout libeio. |
|||
|
|||
=head2 FORK SUPPORT |
|||
|
|||
Usage of pthreads in a program changes the semantics of fork |
|||
considerably. Specifically, only async-safe functions can be called after |
|||
fork. Libeio uses pthreads, so this applies, and makes using fork hard for |
|||
anything but relatively fork + exec uses. |
|||
|
|||
This library only works in the process that initialised it: Forking is |
|||
fully supported, but using libeio in any other process than the one that |
|||
called C<eio_init> is not. |
|||
|
|||
You might get around by not I<using> libeio before (or after) forking in |
|||
the parent, and using it in the child afterwards. You could also try to |
|||
call the L<eio_init> function again in the child, which will brutally |
|||
reinitialise all data structures, which isn't POSIX conformant, but |
|||
typically works. |
|||
|
|||
Otherwise, the only recommendation you should follow is: treat fork code |
|||
the same way you treat signal handlers, and only ever call C<eio_init> in |
|||
the process that uses it, and only once ever. |
|||
|
|||
=head1 INITIALISATION/INTEGRATION |
|||
|
|||
Before you can call any eio functions you first have to initialise the |
|||
library. The library integrates into any event loop, but can also be used |
|||
without one, including in polling mode. |
|||
|
|||
You have to provide the necessary glue yourself, however. |
|||
|
|||
=over 4 |
|||
|
|||
=item int eio_init (void (*want_poll)(void), void (*done_poll)(void)) |
|||
|
|||
This function initialises the library. On success it returns C<0>, on |
|||
failure it returns C<-1> and sets C<errno> appropriately. |
|||
|
|||
It accepts two function pointers specifying callbacks as argument, both of |
|||
which can be C<0>, in which case the callback isn't called. |
|||
|
|||
There is currently no way to change these callbacks later, or to |
|||
"uninitialise" the library again. |
|||
|
|||
=item want_poll callback |
|||
|
|||
The C<want_poll> callback is invoked whenever libeio wants attention (i.e. |
|||
it wants to be polled by calling C<eio_poll>). It is "edge-triggered", |
|||
that is, it will only be called once when eio wants attention, until all |
|||
pending requests have been handled. |
|||
|
|||
This callback is called while locks are being held, so I<you must |
|||
not call any libeio functions inside this callback>. That includes |
|||
C<eio_poll>. What you should do is notify some other thread, or wake up |
|||
your event loop, and then call C<eio_poll>. |
|||
|
|||
=item done_poll callback |
|||
|
|||
This callback is invoked when libeio detects that all pending requests |
|||
have been handled. It is "edge-triggered", that is, it will only be |
|||
called once after C<want_poll>. To put it differently, C<want_poll> and |
|||
C<done_poll> are invoked in pairs: after C<want_poll> you have to call |
|||
C<eio_poll ()> until either C<eio_poll> indicates that everything has been |
|||
handled or C<done_poll> has been called, which signals the same. |
|||
|
|||
Note that C<eio_poll> might return after C<done_poll> and C<want_poll> |
|||
have been called again, so watch out for races in your code. |
|||
|
|||
As with C<want_poll>, this callback is called while locks are being held, |
|||
so you I<must not call any libeio functions form within this callback>. |
|||
|
|||
=item int eio_poll () |
|||
|
|||
This function has to be called whenever there are pending requests that |
|||
need finishing. You usually call this after C<want_poll> has indicated |
|||
that you should do so, but you can also call this function regularly to |
|||
poll for new results. |
|||
|
|||
If any request invocation returns a non-zero value, then C<eio_poll ()> |
|||
immediately returns with that value as return value. |
|||
|
|||
Otherwise, if all requests could be handled, it returns C<0>. If for some |
|||
reason not all requests have been handled, i.e. some are still pending, it |
|||
returns C<-1>. |
|||
|
|||
=back |
|||
|
|||
For libev, you would typically use an C<ev_async> watcher: the |
|||
C<want_poll> callback would invoke C<ev_async_send> to wake up the event |
|||
loop. Inside the callback set for the watcher, one would call C<eio_poll |
|||
()>. |
|||
|
|||
If C<eio_poll ()> is configured to not handle all results in one go |
|||
(i.e. it returns C<-1>) then you should start an idle watcher that calls |
|||
C<eio_poll> until it returns something C<!= -1>. |
|||
|
|||
A full-featured connector between libeio and libev would look as follows |
|||
(if C<eio_poll> is handling all requests, it can of course be simplified a |
|||
lot by removing the idle watcher logic): |
|||
|
|||
static struct ev_loop *loop; |
|||
static ev_idle repeat_watcher; |
|||
static ev_async ready_watcher; |
|||
|
|||
/* idle watcher callback, only used when eio_poll */ |
|||
/* didn't handle all results in one call */ |
|||
static void |
|||
repeat (EV_P_ ev_idle *w, int revents) |
|||
{ |
|||
if (eio_poll () != -1) |
|||
ev_idle_stop (EV_A_ w); |
|||
} |
|||
|
|||
/* eio has some results, process them */ |
|||
static void |
|||
ready (EV_P_ ev_async *w, int revents) |
|||
{ |
|||
if (eio_poll () == -1) |
|||
ev_idle_start (EV_A_ &repeat_watcher); |
|||
} |
|||
|
|||
/* wake up the event loop */ |
|||
static void |
|||
want_poll (void) |
|||
{ |
|||
ev_async_send (loop, &ready_watcher) |
|||
} |
|||
|
|||
void |
|||
my_init_eio () |
|||
{ |
|||
loop = EV_DEFAULT; |
|||
|
|||
ev_idle_init (&repeat_watcher, repeat); |
|||
ev_async_init (&ready_watcher, ready); |
|||
ev_async_start (loop &watcher); |
|||
|
|||
eio_init (want_poll, 0); |
|||
} |
|||
|
|||
For most other event loops, you would typically use a pipe - the event |
|||
loop should be told to wait for read readiness on the read end. In |
|||
C<want_poll> you would write a single byte, in C<done_poll> you would try |
|||
to read that byte, and in the callback for the read end, you would call |
|||
C<eio_poll>. |
|||
|
|||
You don't have to take special care in the case C<eio_poll> doesn't handle |
|||
all requests, as the done callback will not be invoked, so the event loop |
|||
will still signal readiness for the pipe until I<all> results have been |
|||
processed. |
|||
|
|||
|
|||
=head1 HIGH LEVEL REQUEST API |
|||
|
|||
Libeio has both a high-level API, which consists of calling a request |
|||
function with a callback to be called on completion, and a low-level API |
|||
where you fill out request structures and submit them. |
|||
|
|||
This section describes the high-level API. |
|||
|
|||
=head2 REQUEST SUBMISSION AND RESULT PROCESSING |
|||
|
|||
You submit a request by calling the relevant C<eio_TYPE> function with the |
|||
required parameters, a callback of type C<int (*eio_cb)(eio_req *req)> |
|||
(called C<eio_cb> below) and a freely usable C<void *data> argument. |
|||
|
|||
The return value will either be 0, in case something went really wrong |
|||
(which can basically only happen on very fatal errors, such as C<malloc> |
|||
returning 0, which is rather unlikely), or a pointer to the newly-created |
|||
and submitted C<eio_req *>. |
|||
|
|||
The callback will be called with an C<eio_req *> which contains the |
|||
results of the request. The members you can access inside that structure |
|||
vary from request to request, except for: |
|||
|
|||
=over 4 |
|||
|
|||
=item C<ssize_t result> |
|||
|
|||
This contains the result value from the call (usually the same as the |
|||
syscall of the same name). |
|||
|
|||
=item C<int errorno> |
|||
|
|||
This contains the value of C<errno> after the call. |
|||
|
|||
=item C<void *data> |
|||
|
|||
The C<void *data> member simply stores the value of the C<data> argument. |
|||
|
|||
=back |
|||
|
|||
The return value of the callback is normally C<0>, which tells libeio to |
|||
continue normally. If a callback returns a nonzero value, libeio will |
|||
stop processing results (in C<eio_poll>) and will return the value to its |
|||
caller. |
|||
|
|||
Memory areas passed to libeio must stay valid as long as a request |
|||
executes, with the exception of paths, which are being copied |
|||
internally. Any memory libeio itself allocates will be freed after the |
|||
finish callback has been called. If you want to manage all memory passed |
|||
to libeio yourself you can use the low-level API. |
|||
|
|||
For example, to open a file, you could do this: |
|||
|
|||
static int |
|||
file_open_done (eio_req *req) |
|||
{ |
|||
if (req->result < 0) |
|||
{ |
|||
/* open() returned -1 */ |
|||
errno = req->errorno; |
|||
perror ("open"); |
|||
} |
|||
else |
|||
{ |
|||
int fd = req->result; |
|||
/* now we have the new fd in fd */ |
|||
} |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
/* the first three arguments are passed to open(2) */ |
|||
/* the remaining are priority, callback and data */ |
|||
if (!eio_open ("/etc/passwd", O_RDONLY, 0, 0, file_open_done, 0)) |
|||
abort (); /* something went wrong, we will all die!!! */ |
|||
|
|||
Note that you additionally need to call C<eio_poll> when the C<want_cb> |
|||
indicates that requests are ready to be processed. |
|||
|
|||
=head2 CANCELLING REQUESTS |
|||
|
|||
Sometimes the need for a request goes away before the request is |
|||
finished. In that case, one can cancel the request by a call to |
|||
C<eio_cancel>: |
|||
|
|||
=over 4 |
|||
|
|||
=item eio_cancel (eio_req *req) |
|||
|
|||
Cancel the request (and all its subrequests). If the request is currently |
|||
executing it might still continue to execute, and in other cases it might |
|||
still take a while till the request is cancelled. |
|||
|
|||
Even if cancelled, the finish callback will still be invoked - the |
|||
callbacks of all cancellable requests need to check whether the request |
|||
has been cancelled by calling C<EIO_CANCELLED (req)>: |
|||
|
|||
static int |
|||
my_eio_cb (eio_req *req) |
|||
{ |
|||
if (EIO_CANCELLED (req)) |
|||
return 0; |
|||
} |
|||
|
|||
In addition, cancelled requests will I<either> have C<< req->result >> |
|||
set to C<-1> and C<errno> to C<ECANCELED>, or I<otherwise> they were |
|||
successfully executed, despite being cancelled (e.g. when they have |
|||
already been executed at the time they were cancelled). |
|||
|
|||
C<EIO_CANCELLED> is still true for requests that have successfully |
|||
executed, as long as C<eio_cancel> was called on them at some point. |
|||
|
|||
=back |
|||
|
|||
=head2 AVAILABLE REQUESTS |
|||
|
|||
The following request functions are available. I<All> of them return the |
|||
C<eio_req *> on success and C<0> on failure, and I<all> of them have the |
|||
same three trailing arguments: C<pri>, C<cb> and C<data>. The C<cb> is |
|||
mandatory, but in most cases, you pass in C<0> as C<pri> and C<0> or some |
|||
custom data value as C<data>. |
|||
|
|||
=head3 POSIX API WRAPPERS |
|||
|
|||
These requests simply wrap the POSIX call of the same name, with the same |
|||
arguments. If a function is not implemented by the OS and cannot be emulated |
|||
in some way, then all of these return C<-1> and set C<errorno> to C<ENOSYS>. |
|||
|
|||
=over 4 |
|||
|
|||
=item eio_open (const char *path, int flags, mode_t mode, int pri, eio_cb cb, void *data) |
|||
|
|||
=item eio_truncate (const char *path, off_t offset, int pri, eio_cb cb, void *data) |
|||
|
|||
=item eio_chown (const char *path, uid_t uid, gid_t gid, int pri, eio_cb cb, void *data) |
|||
|
|||
=item eio_chmod (const char *path, mode_t mode, int pri, eio_cb cb, void *data) |
|||
|
|||
=item eio_mkdir (const char *path, mode_t mode, int pri, eio_cb cb, void *data) |
|||
|
|||
=item eio_rmdir (const char *path, int pri, eio_cb cb, void *data) |
|||
|
|||
=item eio_unlink (const char *path, int pri, eio_cb cb, void *data) |
|||
|
|||
=item eio_utime (const char *path, eio_tstamp atime, eio_tstamp mtime, int pri, eio_cb cb, void *data) |
|||
|
|||
=item eio_mknod (const char *path, mode_t mode, dev_t dev, int pri, eio_cb cb, void *data) |
|||
|
|||
=item eio_link (const char *path, const char *new_path, int pri, eio_cb cb, void *data) |
|||
|
|||
=item eio_symlink (const char *path, const char *new_path, int pri, eio_cb cb, void *data) |
|||
|
|||
=item eio_rename (const char *path, const char *new_path, int pri, eio_cb cb, void *data) |
|||
|
|||
=item eio_mlock (void *addr, size_t length, int pri, eio_cb cb, void *data) |
|||
|
|||
=item eio_close (int fd, int pri, eio_cb cb, void *data) |
|||
|
|||
=item eio_sync (int pri, eio_cb cb, void *data) |
|||
|
|||
=item eio_fsync (int fd, int pri, eio_cb cb, void *data) |
|||
|
|||
=item eio_fdatasync (int fd, int pri, eio_cb cb, void *data) |
|||
|
|||
=item eio_futime (int fd, eio_tstamp atime, eio_tstamp mtime, int pri, eio_cb cb, void *data) |
|||
|
|||
=item eio_ftruncate (int fd, off_t offset, int pri, eio_cb cb, void *data) |
|||
|
|||
=item eio_fchmod (int fd, mode_t mode, int pri, eio_cb cb, void *data) |
|||
|
|||
=item eio_fchown (int fd, uid_t uid, gid_t gid, int pri, eio_cb cb, void *data) |
|||
|
|||
=item eio_dup2 (int fd, int fd2, int pri, eio_cb cb, void *data) |
|||
|
|||
These have the same semantics as the syscall of the same name, their |
|||
return value is available as C<< req->result >> later. |
|||
|
|||
=item eio_read (int fd, void *buf, size_t length, off_t offset, int pri, eio_cb cb, void *data) |
|||
|
|||
=item eio_write (int fd, void *buf, size_t length, off_t offset, int pri, eio_cb cb, void *data) |
|||
|
|||
These two requests are called C<read> and C<write>, but actually wrap |
|||
C<pread> and C<pwrite>. On systems that lack these calls (such as cygwin), |
|||
libeio uses lseek/read_or_write/lseek and a mutex to serialise the |
|||
requests, so all these requests run serially and do not disturb each |
|||
other. However, they still disturb the file offset while they run, so it's |
|||
not safe to call these functions concurrently with non-libeio functions on |
|||
the same fd on these systems. |
|||
|
|||
Not surprisingly, pread and pwrite are not thread-safe on Darwin (OS/X), |
|||
so it is advised not to submit multiple requests on the same fd on this |
|||
horrible pile of garbage. |
|||
|
|||
=item eio_mlockall (int flags, int pri, eio_cb cb, void *data) |
|||
|
|||
Like C<mlockall>, but the flag value constants are called |
|||
C<EIO_MCL_CURRENT> and C<EIO_MCL_FUTURE>. |
|||
|
|||
=item eio_msync (void *addr, size_t length, int flags, int pri, eio_cb cb, void *data) |
|||
|
|||
Just like msync, except that the flag values are called C<EIO_MS_ASYNC>, |
|||
C<EIO_MS_INVALIDATE> and C<EIO_MS_SYNC>. |
|||
|
|||
=item eio_readlink (const char *path, int pri, eio_cb cb, void *data) |
|||
|
|||
If successful, the path read by C<readlink(2)> can be accessed via C<< |
|||
req->ptr2 >> and is I<NOT> null-terminated, with the length specified as |
|||
C<< req->result >>. |
|||
|
|||
if (req->result >= 0) |
|||
{ |
|||
char *target = strndup ((char *)req->ptr2, req->result); |
|||
|
|||
free (target); |
|||
} |
|||
|
|||
=item eio_realpath (const char *path, int pri, eio_cb cb, void *data) |
|||
|
|||
Similar to the realpath libc function, but unlike that one, C<< |
|||
req->result >> is C<-1> on failure. On success, the result is the length |
|||
of the returned path in C<ptr2> (which is I<NOT> 0-terminated) - this is |
|||
similar to readlink. |
|||
|
|||
=item eio_stat (const char *path, int pri, eio_cb cb, void *data) |
|||
|
|||
=item eio_lstat (const char *path, int pri, eio_cb cb, void *data) |
|||
|
|||
=item eio_fstat (int fd, int pri, eio_cb cb, void *data) |
|||
|
|||
Stats a file - if C<< req->result >> indicates success, then you can |
|||
access the C<struct stat>-like structure via C<< req->ptr2 >>: |
|||
|
|||
EIO_STRUCT_STAT *statdata = (EIO_STRUCT_STAT *)req->ptr2; |
|||
|
|||
=item eio_statvfs (const char *path, int pri, eio_cb cb, void *data) |
|||
|
|||
=item eio_fstatvfs (int fd, int pri, eio_cb cb, void *data) |
|||
|
|||
Stats a filesystem - if C<< req->result >> indicates success, then you can |
|||
access the C<struct statvfs>-like structure via C<< req->ptr2 >>: |
|||
|
|||
EIO_STRUCT_STATVFS *statdata = (EIO_STRUCT_STATVFS *)req->ptr2; |
|||
|
|||
=back |
|||
|
|||
=head3 READING DIRECTORIES |
|||
|
|||
Reading directories sounds simple, but can be rather demanding, especially |
|||
if you want to do stuff such as traversing a directory hierarchy or |
|||
processing all files in a directory. Libeio can assist these complex tasks |
|||
with it's C<eio_readdir> call. |
|||
|
|||
=over 4 |
|||
|
|||
=item eio_readdir (const char *path, int flags, int pri, eio_cb cb, void *data) |
|||
|
|||
This is a very complex call. It basically reads through a whole directory |
|||
(via the C<opendir>, C<readdir> and C<closedir> calls) and returns either |
|||
the names or an array of C<struct eio_dirent>, depending on the C<flags> |
|||
argument. |
|||
|
|||
The C<< req->result >> indicates either the number of files found, or |
|||
C<-1> on error. On success, null-terminated names can be found as C<< req->ptr2 >>, |
|||
and C<struct eio_dirents>, if requested by C<flags>, can be found via C<< |
|||
req->ptr1 >>. |
|||
|
|||
Here is an example that prints all the names: |
|||
|
|||
int i; |
|||
char *names = (char *)req->ptr2; |
|||
|
|||
for (i = 0; i < req->result; ++i) |
|||
{ |
|||
printf ("name #%d: %s\n", i, names); |
|||
|
|||
/* move to next name */ |
|||
names += strlen (names) + 1; |
|||
} |
|||
|
|||
Pseudo-entries such as F<.> and F<..> are never returned by C<eio_readdir>. |
|||
|
|||
C<flags> can be any combination of: |
|||
|
|||
=over 4 |
|||
|
|||
=item EIO_READDIR_DENTS |
|||
|
|||
If this flag is specified, then, in addition to the names in C<ptr2>, |
|||
also an array of C<struct eio_dirent> is returned, in C<ptr1>. A C<struct |
|||
eio_dirent> looks like this: |
|||
|
|||
struct eio_dirent |
|||
{ |
|||
int nameofs; /* offset of null-terminated name string in (char *)req->ptr2 */ |
|||
unsigned short namelen; /* size of filename without trailing 0 */ |
|||
unsigned char type; /* one of EIO_DT_* */ |
|||
signed char score; /* internal use */ |
|||
ino_t inode; /* the inode number, if available, otherwise unspecified */ |
|||
}; |
|||
|
|||
The only members you normally would access are C<nameofs>, which is the |
|||
byte-offset from C<ptr2> to the start of the name, C<namelen> and C<type>. |
|||
|
|||
C<type> can be one of: |
|||
|
|||
C<EIO_DT_UNKNOWN> - if the type is not known (very common) and you have to C<stat> |
|||
the name yourself if you need to know, |
|||
one of the "standard" POSIX file types (C<EIO_DT_REG>, C<EIO_DT_DIR>, C<EIO_DT_LNK>, |
|||
C<EIO_DT_FIFO>, C<EIO_DT_SOCK>, C<EIO_DT_CHR>, C<EIO_DT_BLK>) |
|||
or some OS-specific type (currently |
|||
C<EIO_DT_MPC> - multiplexed char device (v7+coherent), |
|||
C<EIO_DT_NAM> - xenix special named file, |
|||
C<EIO_DT_MPB> - multiplexed block device (v7+coherent), |
|||
C<EIO_DT_NWK> - HP-UX network special, |
|||
C<EIO_DT_CMP> - VxFS compressed, |
|||
C<EIO_DT_DOOR> - solaris door, or |
|||
C<EIO_DT_WHT>). |
|||
|
|||
This example prints all names and their type: |
|||
|
|||
int i; |
|||
struct eio_dirent *ents = (struct eio_dirent *)req->ptr1; |
|||
char *names = (char *)req->ptr2; |
|||
|
|||
for (i = 0; i < req->result; ++i) |
|||
{ |
|||
struct eio_dirent *ent = ents + i; |
|||
char *name = names + ent->nameofs; |
|||
|
|||
printf ("name #%d: %s (type %d)\n", i, name, ent->type); |
|||
} |
|||
|
|||
=item EIO_READDIR_DIRS_FIRST |
|||
|
|||
When this flag is specified, then the names will be returned in an order |
|||
where likely directories come first, in optimal C<stat> order. This is |
|||
useful when you need to quickly find directories, or you want to find all |
|||
directories while avoiding to stat() each entry. |
|||
|
|||
If the system returns type information in readdir, then this is used |
|||
to find directories directly. Otherwise, likely directories are names |
|||
beginning with ".", or otherwise names with no dots, of which names with |
|||
short names are tried first. |
|||
|
|||
=item EIO_READDIR_STAT_ORDER |
|||
|
|||
When this flag is specified, then the names will be returned in an order |
|||
suitable for stat()'ing each one. That is, when you plan to stat() |
|||
all files in the given directory, then the returned order will likely |
|||
be fastest. |
|||
|
|||
If both this flag and C<EIO_READDIR_DIRS_FIRST> are specified, then the |
|||
likely directories come first, resulting in a less optimal stat order. |
|||
|
|||
=item EIO_READDIR_FOUND_UNKNOWN |
|||
|
|||
This flag should not be specified when calling C<eio_readdir>. Instead, |
|||
it is being set by C<eio_readdir> (you can access the C<flags> via C<< |
|||
req->int1 >>, when any of the C<type>'s found were C<EIO_DT_UNKNOWN>. The |
|||
absence of this flag therefore indicates that all C<type>'s are known, |
|||
which can be used to speed up some algorithms. |
|||
|
|||
A typical use case would be to identify all subdirectories within a |
|||
directory - you would ask C<eio_readdir> for C<EIO_READDIR_DIRS_FIRST>. If |
|||
then this flag is I<NOT> set, then all the entries at the beginning of the |
|||
returned array of type C<EIO_DT_DIR> are the directories. Otherwise, you |
|||
should start C<stat()>'ing the entries starting at the beginning of the |
|||
array, stopping as soon as you found all directories (the count can be |
|||
deduced by the link count of the directory). |
|||
|
|||
=back |
|||
|
|||
=back |
|||
|
|||
=head3 OS-SPECIFIC CALL WRAPPERS |
|||
|
|||
These wrap OS-specific calls (usually Linux ones), and might or might not |
|||
be emulated on other operating systems. Calls that are not emulated will |
|||
return C<-1> and set C<errno> to C<ENOSYS>. |
|||
|
|||
=over 4 |
|||
|
|||
=item eio_sendfile (int out_fd, int in_fd, off_t in_offset, size_t length, int pri, eio_cb cb, void *data) |
|||
|
|||
Wraps the C<sendfile> syscall. The arguments follow the Linux version, but |
|||
libeio supports and will use similar calls on FreeBSD, HP/UX, Solaris and |
|||
Darwin. |
|||
|
|||
If the OS doesn't support some sendfile-like call, or the call fails, |
|||
indicating support for the given file descriptor type (for example, |
|||
Linux's sendfile might not support file to file copies), then libeio will |
|||
emulate the call in userspace, so there are almost no limitations on its |
|||
use. |
|||
|
|||
=item eio_readahead (int fd, off_t offset, size_t length, int pri, eio_cb cb, void *data) |
|||
|
|||
Calls C<readahead(2)>. If the syscall is missing, then the call is |
|||
emulated by simply reading the data (currently in 64kiB chunks). |
|||
|
|||
=item eio_syncfs (int fd, int pri, eio_cb cb, void *data) |
|||
|
|||
Calls Linux' C<syncfs> syscall, if available. Returns C<-1> and sets |
|||
C<errno> to C<ENOSYS> if the call is missing I<but still calls sync()>, |
|||
if the C<fd> is C<< >= 0 >>, so you can probe for the availability of the |
|||
syscall with a negative C<fd> argument and checking for C<-1/ENOSYS>. |
|||
|
|||
=item eio_sync_file_range (int fd, off_t offset, size_t nbytes, unsigned int flags, int pri, eio_cb cb, void *data) |
|||
|
|||
Calls C<sync_file_range>. If the syscall is missing, then this is the same |
|||
as calling C<fdatasync>. |
|||
|
|||
Flags can be any combination of C<EIO_SYNC_FILE_RANGE_WAIT_BEFORE>, |
|||
C<EIO_SYNC_FILE_RANGE_WRITE> and C<EIO_SYNC_FILE_RANGE_WAIT_AFTER>. |
|||
|
|||
=item eio_fallocate (int fd, int mode, off_t offset, off_t len, int pri, eio_cb cb, void *data) |
|||
|
|||
Calls C<fallocate> (note: I<NOT> C<posix_fallocate>!). If the syscall is |
|||
missing, then it returns failure and sets C<errno> to C<ENOSYS>. |
|||
|
|||
The C<mode> argument can be C<0> (for behaviour similar to |
|||
C<posix_fallocate>), or C<EIO_FALLOC_FL_KEEP_SIZE>, which keeps the size |
|||
of the file unchanged (but still preallocates space beyond end of file). |
|||
|
|||
=back |
|||
|
|||
=head3 LIBEIO-SPECIFIC REQUESTS |
|||
|
|||
These requests are specific to libeio and do not correspond to any OS call. |
|||
|
|||
=over 4 |
|||
|
|||
=item eio_mtouch (void *addr, size_t length, int flags, int pri, eio_cb cb, void *data) |
|||
|
|||
Reads (C<flags == 0>) or modifies (C<flags == EIO_MT_MODIFY) the given |
|||
memory area, page-wise, that is, it reads (or reads and writes back) the |
|||
first octet of every page that spans the memory area. |
|||
|
|||
This can be used to page in some mmapped file, or dirty some pages. Note |
|||
that dirtying is an unlocked read-write access, so races can ensue when |
|||
the some other thread modifies the data stored in that memory area. |
|||
|
|||
=item eio_custom (void (*)(eio_req *) execute, int pri, eio_cb cb, void *data) |
|||
|
|||
Executes a custom request, i.e., a user-specified callback. |
|||
|
|||
The callback gets the C<eio_req *> as parameter and is expected to read |
|||
and modify any request-specific members. Specifically, it should set C<< |
|||
req->result >> to the result value, just like other requests. |
|||
|
|||
Here is an example that simply calls C<open>, like C<eio_open>, but it |
|||
uses the C<data> member as filename and uses a hardcoded C<O_RDONLY>. If |
|||
you want to pass more/other parameters, you either need to pass some |
|||
struct or so via C<data> or provide your own wrapper using the low-level |
|||
API. |
|||
|
|||
static int |
|||
my_open_done (eio_req *req) |
|||
{ |
|||
int fd = req->result; |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
static void |
|||
my_open (eio_req *req) |
|||
{ |
|||
req->result = open (req->data, O_RDONLY); |
|||
} |
|||
|
|||
eio_custom (my_open, 0, my_open_done, "/etc/passwd"); |
|||
|
|||
=item eio_busy (eio_tstamp delay, int pri, eio_cb cb, void *data) |
|||
|
|||
This is a request that takes C<delay> seconds to execute, but otherwise |
|||
does nothing - it simply puts one of the worker threads to sleep for this |
|||
long. |
|||
|
|||
This request can be used to artificially increase load, e.g. for debugging |
|||
or benchmarking reasons. |
|||
|
|||
=item eio_nop (int pri, eio_cb cb, void *data) |
|||
|
|||
This request does nothing, except go through the whole request cycle. This |
|||
can be used to measure latency or in some cases to simplify code, but is |
|||
not really of much use. |
|||
|
|||
=back |
|||
|
|||
=head3 GROUPING AND LIMITING REQUESTS |
|||
|
|||
There is one more rather special request, C<eio_grp>. It is a very special |
|||
aio request: Instead of doing something, it is a container for other eio |
|||
requests. |
|||
|
|||
There are two primary use cases for this: a) bundle many requests into a |
|||
single, composite, request with a definite callback and the ability to |
|||
cancel the whole request with its subrequests and b) limiting the number |
|||
of "active" requests. |
|||
|
|||
Further below you will find more discussion of these topics - first |
|||
follows the reference section detailing the request generator and other |
|||
methods. |
|||
|
|||
=over 4 |
|||
|
|||
=item eio_req *grp = eio_grp (eio_cb cb, void *data) |
|||
|
|||
Creates, submits and returns a group request. Note that it doesn't have a |
|||
priority, unlike all other requests. |
|||
|
|||
=item eio_grp_add (eio_req *grp, eio_req *req) |
|||
|
|||
Adds a request to the request group. |
|||
|
|||
=item eio_grp_cancel (eio_req *grp) |
|||
|
|||
Cancels all requests I<in> the group, but I<not> the group request |
|||
itself. You can cancel the group request I<and> all subrequests via a |
|||
normal C<eio_cancel> call. |
|||
|
|||
=back |
|||
|
|||
=head4 GROUP REQUEST LIFETIME |
|||
|
|||
Left alone, a group request will instantly move to the pending state and |
|||
will be finished at the next call of C<eio_poll>. |
|||
|
|||
The usefulness stems from the fact that, if a subrequest is added to a |
|||
group I<before> a call to C<eio_poll>, via C<eio_grp_add>, then the group |
|||
will not finish until all the subrequests have finished. |
|||
|
|||
So the usage cycle of a group request is like this: after it is created, |
|||
you normally instantly add a subrequest. If none is added, the group |
|||
request will finish on it's own. As long as subrequests are added before |
|||
the group request is finished it will be kept from finishing, that is the |
|||
callbacks of any subrequests can, in turn, add more requests to the group, |
|||
and as long as any requests are active, the group request itself will not |
|||
finish. |
|||
|
|||
=head4 CREATING COMPOSITE REQUESTS |
|||
|
|||
Imagine you wanted to create an C<eio_load> request that opens a file, |
|||
reads it and closes it. This means it has to execute at least three eio |
|||
requests, but for various reasons it might be nice if that request looked |
|||
like any other eio request. |
|||
|
|||
This can be done with groups: |
|||
|
|||
=over 4 |
|||
|
|||
=item 1) create the request object |
|||
|
|||
Create a group that contains all further requests. This is the request you |
|||
can return as "the load request". |
|||
|
|||
=item 2) open the file, maybe |
|||
|
|||
Next, open the file with C<eio_open> and add the request to the group |
|||
request and you are finished setting up the request. |
|||
|
|||
If, for some reason, you cannot C<eio_open> (path is a null ptr?) you |
|||
can set C<< grp->result >> to C<-1> to signal an error and let the group |
|||
request finish on its own. |
|||
|
|||
=item 3) open callback adds more requests |
|||
|
|||
In the open callback, if the open was not successful, copy C<< |
|||
req->errorno >> to C<< grp->errorno >> and set C<< grp->errorno >> to |
|||
C<-1> to signal an error. |
|||
|
|||
Otherwise, malloc some memory or so and issue a read request, adding the |
|||
read request to the group. |
|||
|
|||
=item 4) continue issuing requests till finished |
|||
|
|||
In the real callback, check for errors and possibly continue with |
|||
C<eio_close> or any other eio request in the same way. |
|||
|
|||
As soon as no new requests are added the group request will finish. Make |
|||
sure you I<always> set C<< grp->result >> to some sensible value. |
|||
|
|||
=back |
|||
|
|||
=head4 REQUEST LIMITING |
|||
|
|||
|
|||
#TODO |
|||
|
|||
void eio_grp_limit (eio_req *grp, int limit); |
|||
|
|||
|
|||
=back |
|||
|
|||
|
|||
=head1 LOW LEVEL REQUEST API |
|||
|
|||
#TODO |
|||
|
|||
|
|||
=head1 ANATOMY AND LIFETIME OF AN EIO REQUEST |
|||
|
|||
A request is represented by a structure of type C<eio_req>. To initialise |
|||
it, clear it to all zero bytes: |
|||
|
|||
eio_req req; |
|||
|
|||
memset (&req, 0, sizeof (req)); |
|||
|
|||
A more common way to initialise a new C<eio_req> is to use C<calloc>: |
|||
|
|||
eio_req *req = calloc (1, sizeof (*req)); |
|||
|
|||
In either case, libeio neither allocates, initialises or frees the |
|||
C<eio_req> structure for you - it merely uses it. |
|||
|
|||
zero |
|||
|
|||
#TODO |
|||
|
|||
=head2 CONFIGURATION |
|||
|
|||
The functions in this section can sometimes be useful, but the default |
|||
configuration will do in most case, so you should skip this section on |
|||
first reading. |
|||
|
|||
=over 4 |
|||
|
|||
=item eio_set_max_poll_time (eio_tstamp nseconds) |
|||
|
|||
This causes C<eio_poll ()> to return after it has detected that it was |
|||
running for C<nsecond> seconds or longer (this number can be fractional). |
|||
|
|||
This can be used to limit the amount of time spent handling eio requests, |
|||
for example, in interactive programs, you might want to limit this time to |
|||
C<0.01> seconds or so. |
|||
|
|||
Note that: |
|||
|
|||
=over 4 |
|||
|
|||
=item a) libeio doesn't know how long your request callbacks take, so the |
|||
time spent in C<eio_poll> is up to one callback invocation longer then |
|||
this interval. |
|||
|
|||
=item b) this is implemented by calling C<gettimeofday> after each |
|||
request, which can be costly. |
|||
|
|||
=item c) at least one request will be handled. |
|||
|
|||
=back |
|||
|
|||
=item eio_set_max_poll_reqs (unsigned int nreqs) |
|||
|
|||
When C<nreqs> is non-zero, then C<eio_poll> will not handle more than |
|||
C<nreqs> requests per invocation. This is a less costly way to limit the |
|||
amount of work done by C<eio_poll> then setting a time limit. |
|||
|
|||
If you know your callbacks are generally fast, you could use this to |
|||
encourage interactiveness in your programs by setting it to C<10>, C<100> |
|||
or even C<1000>. |
|||
|
|||
=item eio_set_min_parallel (unsigned int nthreads) |
|||
|
|||
Make sure libeio can handle at least this many requests in parallel. It |
|||
might be able handle more. |
|||
|
|||
=item eio_set_max_parallel (unsigned int nthreads) |
|||
|
|||
Set the maximum number of threads that libeio will spawn. |
|||
|
|||
=item eio_set_max_idle (unsigned int nthreads) |
|||
|
|||
Libeio uses threads internally to handle most requests, and will start and stop threads on demand. |
|||
|
|||
This call can be used to limit the number of idle threads (threads without |
|||
work to do): libeio will keep some threads idle in preparation for more |
|||
requests, but never longer than C<nthreads> threads. |
|||
|
|||
In addition to this, libeio will also stop threads when they are idle for |
|||
a few seconds, regardless of this setting. |
|||
|
|||
=item unsigned int eio_nthreads () |
|||
|
|||
Return the number of worker threads currently running. |
|||
|
|||
=item unsigned int eio_nreqs () |
|||
|
|||
Return the number of requests currently handled by libeio. This is the |
|||
total number of requests that have been submitted to libeio, but not yet |
|||
destroyed. |
|||
|
|||
=item unsigned int eio_nready () |
|||
|
|||
Returns the number of ready requests, i.e. requests that have been |
|||
submitted but have not yet entered the execution phase. |
|||
|
|||
=item unsigned int eio_npending () |
|||
|
|||
Returns the number of pending requests, i.e. requests that have been |
|||
executed and have results, but have not been finished yet by a call to |
|||
C<eio_poll>). |
|||
|
|||
=back |
|||
|
|||
=head1 EMBEDDING |
|||
|
|||
Libeio can be embedded directly into programs. This functionality is not |
|||
documented and not (yet) officially supported. |
|||
|
|||
Note that, when including C<libeio.m4>, you are responsible for defining |
|||
the compilation environment (C<_LARGEFILE_SOURCE>, C<_GNU_SOURCE> etc.). |
|||
|
|||
If you need to know how, check the C<IO::AIO> perl module, which does |
|||
exactly that. |
|||
|
|||
|
|||
=head1 COMPILETIME CONFIGURATION |
|||
|
|||
These symbols, if used, must be defined when compiling F<eio.c>. |
|||
|
|||
=over 4 |
|||
|
|||
=item EIO_STACKSIZE |
|||
|
|||
This symbol governs the stack size for each eio thread. Libeio itself |
|||
was written to use very little stackspace, but when using C<EIO_CUSTOM> |
|||
requests, you might want to increase this. |
|||
|
|||
If this symbol is undefined (the default) then libeio will use its default |
|||
stack size (C<sizeof (void *) * 4096> currently). If it is defined, but |
|||
C<0>, then the default operating system stack size will be used. In all |
|||
other cases, the value must be an expression that evaluates to the desired |
|||
stack size. |
|||
|
|||
=back |
|||
|
|||
|
|||
=head1 PORTABILITY REQUIREMENTS |
|||
|
|||
In addition to a working ISO-C implementation, libeio relies on a few |
|||
additional extensions: |
|||
|
|||
=over 4 |
|||
|
|||
=item POSIX threads |
|||
|
|||
To be portable, this module uses threads, specifically, the POSIX threads |
|||
library must be available (and working, which partially excludes many xBSD |
|||
systems, where C<fork ()> is buggy). |
|||
|
|||
=item POSIX-compatible filesystem API |
|||
|
|||
This is actually a harder portability requirement: The libeio API is quite |
|||
demanding regarding POSIX API calls (symlinks, user/group management |
|||
etc.). |
|||
|
|||
=item C<double> must hold a time value in seconds with enough accuracy |
|||
|
|||
The type C<double> is used to represent timestamps. It is required to |
|||
have at least 51 bits of mantissa (and 9 bits of exponent), which is good |
|||
enough for at least into the year 4000. This requirement is fulfilled by |
|||
implementations implementing IEEE 754 (basically all existing ones). |
|||
|
|||
=back |
|||
|
|||
If you know of other additional requirements drop me a note. |
|||
|
|||
|
|||
=head1 AUTHOR |
|||
|
|||
Marc Lehmann <libeio@schmorp.de>. |
|||
|
@ -1,195 +0,0 @@ |
|||
dnl openbsd in it's neverending brokenness requires stdint.h for intptr_t, |
|||
dnl but that header isn't very portable... |
|||
AC_CHECK_HEADERS([stdint.h sys/syscall.h sys/prctl.h]) |
|||
|
|||
AC_SEARCH_LIBS( |
|||
pthread_create, |
|||
[pthread pthreads pthreadVC2], |
|||
, |
|||
[AC_MSG_ERROR(pthread functions not found)] |
|||
) |
|||
|
|||
AC_CACHE_CHECK(for utimes, ac_cv_utimes, [AC_LINK_IFELSE([[ |
|||
#include <sys/types.h> |
|||
#include <sys/time.h> |
|||
#include <utime.h> |
|||
struct timeval tv[2]; |
|||
int res; |
|||
int main (void) |
|||
{ |
|||
res = utimes ("/", tv); |
|||
return 0; |
|||
} |
|||
]],ac_cv_utimes=yes,ac_cv_utimes=no)]) |
|||
test $ac_cv_utimes = yes && AC_DEFINE(HAVE_UTIMES, 1, utimes(2) is available) |
|||
|
|||
AC_CACHE_CHECK(for futimes, ac_cv_futimes, [AC_LINK_IFELSE([[ |
|||
#include <sys/types.h> |
|||
#include <sys/time.h> |
|||
#include <utime.h> |
|||
struct timeval tv[2]; |
|||
int res; |
|||
int fd; |
|||
int main (void) |
|||
{ |
|||
res = futimes (fd, tv); |
|||
return 0; |
|||
} |
|||
]],ac_cv_futimes=yes,ac_cv_futimes=no)]) |
|||
test $ac_cv_futimes = yes && AC_DEFINE(HAVE_FUTIMES, 1, futimes(2) is available) |
|||
|
|||
AC_CACHE_CHECK(for readahead, ac_cv_readahead, [AC_LINK_IFELSE([ |
|||
#include <fcntl.h> |
|||
int main (void) |
|||
{ |
|||
int fd = 0; |
|||
size_t count = 2; |
|||
ssize_t res; |
|||
res = readahead (fd, 0, count); |
|||
return 0; |
|||
} |
|||
],ac_cv_readahead=yes,ac_cv_readahead=no)]) |
|||
test $ac_cv_readahead = yes && AC_DEFINE(HAVE_READAHEAD, 1, readahead(2) is available (linux)) |
|||
|
|||
AC_CACHE_CHECK(for fdatasync, ac_cv_fdatasync, [AC_LINK_IFELSE([ |
|||
#include <unistd.h> |
|||
int main (void) |
|||
{ |
|||
int fd = 0; |
|||
fdatasync (fd); |
|||
return 0; |
|||
} |
|||
],ac_cv_fdatasync=yes,ac_cv_fdatasync=no)]) |
|||
test $ac_cv_fdatasync = yes && AC_DEFINE(HAVE_FDATASYNC, 1, fdatasync(2) is available) |
|||
|
|||
AC_CACHE_CHECK(for pread and pwrite, ac_cv_preadwrite, [AC_LINK_IFELSE([ |
|||
#include <unistd.h> |
|||
int main (void) |
|||
{ |
|||
int fd = 0; |
|||
size_t count = 1; |
|||
char buf; |
|||
off_t offset = 1; |
|||
ssize_t res; |
|||
res = pread (fd, &buf, count, offset); |
|||
res = pwrite (fd, &buf, count, offset); |
|||
return 0; |
|||
} |
|||
],ac_cv_preadwrite=yes,ac_cv_preadwrite=no)]) |
|||
test $ac_cv_preadwrite = yes && AC_DEFINE(HAVE_PREADWRITE, 1, pread(2) and pwrite(2) are available) |
|||
|
|||
AC_CACHE_CHECK(for sendfile, ac_cv_sendfile, [AC_LINK_IFELSE([ |
|||
# include <sys/types.h> |
|||
#if __linux |
|||
# include <sys/sendfile.h> |
|||
#elif __FreeBSD__ || defined __APPLE__ |
|||
# include <sys/socket.h> |
|||
# include <sys/uio.h> |
|||
#elif __hpux |
|||
# include <sys/socket.h> |
|||
#else |
|||
# error unsupported architecture |
|||
#endif |
|||
int main (void) |
|||
{ |
|||
int fd = 0; |
|||
off_t offset = 1; |
|||
size_t count = 2; |
|||
ssize_t res; |
|||
#if __linux |
|||
res = sendfile (fd, fd, offset, count); |
|||
#elif __FreeBSD__ |
|||
res = sendfile (fd, fd, offset, count, 0, &offset, 0); |
|||
#elif __hpux |
|||
res = sendfile (fd, fd, offset, count, 0, 0); |
|||
#endif |
|||
return 0; |
|||
} |
|||
],ac_cv_sendfile=yes,ac_cv_sendfile=no)]) |
|||
test $ac_cv_sendfile = yes && AC_DEFINE(HAVE_SENDFILE, 1, sendfile(2) is available and supported) |
|||
|
|||
AC_CACHE_CHECK(for sync_file_range, ac_cv_sync_file_range, [AC_LINK_IFELSE([ |
|||
#include <fcntl.h> |
|||
int main (void) |
|||
{ |
|||
int fd = 0; |
|||
off64_t offset = 1; |
|||
off64_t nbytes = 1; |
|||
unsigned int flags = SYNC_FILE_RANGE_WAIT_BEFORE|SYNC_FILE_RANGE_WRITE|SYNC_FILE_RANGE_WAIT_AFTER; |
|||
ssize_t res; |
|||
res = sync_file_range (fd, offset, nbytes, flags); |
|||
return 0; |
|||
} |
|||
],ac_cv_sync_file_range=yes,ac_cv_sync_file_range=no)]) |
|||
test $ac_cv_sync_file_range = yes && AC_DEFINE(HAVE_SYNC_FILE_RANGE, 1, sync_file_range(2) is available) |
|||
|
|||
AC_CACHE_CHECK(for fallocate, ac_cv_fallocate, [AC_LINK_IFELSE([ |
|||
#include <fcntl.h> |
|||
int main (void) |
|||
{ |
|||
int fd = 0; |
|||
int mode = 0; |
|||
off_t offset = 1; |
|||
off_t len = 1; |
|||
int res; |
|||
res = fallocate (fd, mode, offset, len); |
|||
return 0; |
|||
} |
|||
],ac_cv_fallocate=yes,ac_cv_fallocate=no)]) |
|||
test $ac_cv_fallocate = yes && AC_DEFINE(HAVE_FALLOCATE, 1, fallocate(2) is available) |
|||
|
|||
AC_CACHE_CHECK(for sys_syncfs, ac_cv_sys_syncfs, [AC_LINK_IFELSE([ |
|||
#include <unistd.h> |
|||
#include <sys/syscall.h> |
|||
int main (void) |
|||
{ |
|||
int res = syscall (__NR_syncfs, (int)0); |
|||
} |
|||
],ac_cv_sys_syncfs=yes,ac_cv_sys_syncfs=no)]) |
|||
test $ac_cv_sys_syncfs = yes && AC_DEFINE(HAVE_SYS_SYNCFS, 1, syscall(__NR_syncfs) is available) |
|||
|
|||
AC_CACHE_CHECK(for prctl_set_name, ac_cv_prctl_set_name, [AC_LINK_IFELSE([ |
|||
#include <sys/prctl.h> |
|||
int main (void) |
|||
{ |
|||
char name[] = "test123"; |
|||
int res = prctl (PR_SET_NAME, (unsigned long)name, 0, 0, 0); |
|||
} |
|||
],ac_cv_prctl_set_name=yes,ac_cv_prctl_set_name=no)]) |
|||
test $ac_cv_prctl_set_name = yes && AC_DEFINE(HAVE_PRCTL_SET_NAME, 1, prctl(PR_SET_NAME) is available) |
|||
|
|||
dnl ############################################################################# |
|||
dnl # these checks exist for the benefit of IO::AIO |
|||
|
|||
dnl at least uclibc defines _POSIX_ADVISORY_INFO without *any* of the required |
|||
dnl functionality actually being present. ugh. |
|||
AC_CACHE_CHECK(for posix_madvise, ac_cv_posix_madvise, [AC_LINK_IFELSE([ |
|||
#include <sys/mman.h> |
|||
int main (void) |
|||
{ |
|||
int res = posix_madvise ((void *)0, (size_t)0, POSIX_MADV_NORMAL); |
|||
int a = POSIX_MADV_SEQUENTIAL; |
|||
int b = POSIX_MADV_RANDOM; |
|||
int c = POSIX_MADV_WILLNEED; |
|||
int d = POSIX_MADV_DONTNEED; |
|||
return 0; |
|||
} |
|||
],ac_cv_posix_madvise=yes,ac_cv_posix_madvise=no)]) |
|||
test $ac_cv_posix_madvise = yes && AC_DEFINE(HAVE_POSIX_MADVISE, 1, posix_madvise(2) is available) |
|||
|
|||
AC_CACHE_CHECK(for posix_fadvise, ac_cv_posix_fadvise, [AC_LINK_IFELSE([ |
|||
#define _XOPEN_SOURCE 600 |
|||
#include <fcntl.h> |
|||
int main (void) |
|||
{ |
|||
int res = posix_fadvise ((int)0, (off_t)0, (off_t)0, POSIX_FADV_NORMAL); |
|||
int a = POSIX_FADV_SEQUENTIAL; |
|||
int b = POSIX_FADV_NOREUSE; |
|||
int c = POSIX_FADV_RANDOM; |
|||
int d = POSIX_FADV_WILLNEED; |
|||
int e = POSIX_FADV_DONTNEED; |
|||
return 0; |
|||
} |
|||
],ac_cv_posix_fadvise=yes,ac_cv_posix_fadvise=no)]) |
|||
test $ac_cv_posix_fadvise = yes && AC_DEFINE(HAVE_POSIX_FADVISE, 1, posix_fadvise(2) is available) |
|||
|
@ -1,164 +0,0 @@ |
|||
#ifndef XTHREAD_H_ |
|||
#define XTHREAD_H_ |
|||
|
|||
/* whether word reads are potentially non-atomic.
|
|||
* this is conservative, likely most arches this runs |
|||
* on have atomic word read/writes. |
|||
*/ |
|||
#ifndef WORDACCESS_UNSAFE |
|||
# if __i386 || __x86_64 |
|||
# define WORDACCESS_UNSAFE 0 |
|||
# else |
|||
# define WORDACCESS_UNSAFE 1 |
|||
# endif |
|||
#endif |
|||
|
|||
/////////////////////////////////////////////////////////////////////////////
|
|||
|
|||
#ifdef _WIN32 |
|||
|
|||
#include <stdio.h>//D |
|||
#include <fcntl.h> |
|||
#include <io.h> |
|||
#include <time.h> |
|||
#include <winsock2.h> |
|||
#include <process.h> |
|||
#include <windows.h> |
|||
#include <pthread.h> |
|||
#define sigset_t int |
|||
#define sigfillset(a) |
|||
#define pthread_sigmask(a,b,c) |
|||
#define sigaddset(a,b) |
|||
#define sigemptyset(s) |
|||
|
|||
typedef pthread_mutex_t xmutex_t; |
|||
#define X_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER |
|||
#define X_MUTEX_CREATE(mutex) pthread_mutex_init (&(mutex), 0) |
|||
#define X_LOCK(mutex) pthread_mutex_lock (&(mutex)) |
|||
#define X_UNLOCK(mutex) pthread_mutex_unlock (&(mutex)) |
|||
|
|||
typedef pthread_cond_t xcond_t; |
|||
#define X_COND_INIT PTHREAD_COND_INITIALIZER |
|||
#define X_COND_CREATE(cond) pthread_cond_init (&(cond), 0) |
|||
#define X_COND_SIGNAL(cond) pthread_cond_signal (&(cond)) |
|||
#define X_COND_WAIT(cond,mutex) pthread_cond_wait (&(cond), &(mutex)) |
|||
#define X_COND_TIMEDWAIT(cond,mutex,to) pthread_cond_timedwait (&(cond), &(mutex), &(to)) |
|||
|
|||
typedef pthread_t xthread_t; |
|||
#define X_THREAD_PROC(name) void *name (void *thr_arg) |
|||
#define X_THREAD_ATFORK(a,b,c) |
|||
|
|||
static int |
|||
xthread_create (xthread_t *tid, void *(*proc)(void *), void *arg) |
|||
{ |
|||
int retval; |
|||
pthread_attr_t attr; |
|||
|
|||
pthread_attr_init (&attr); |
|||
pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); |
|||
|
|||
retval = pthread_create (tid, &attr, proc, arg) == 0; |
|||
|
|||
pthread_attr_destroy (&attr); |
|||
|
|||
return retval; |
|||
} |
|||
|
|||
#define respipe_read(a,b,c) PerlSock_recv ((a), (b), (c), 0) |
|||
#define respipe_write(a,b,c) send ((a), (b), (c), 0) |
|||
#define respipe_close(a) PerlSock_closesocket ((a)) |
|||
|
|||
#else |
|||
/////////////////////////////////////////////////////////////////////////////
|
|||
|
|||
#if __linux && !defined(_GNU_SOURCE) |
|||
# define _GNU_SOURCE |
|||
#endif |
|||
|
|||
/* just in case */ |
|||
#define _REENTRANT 1 |
|||
|
|||
#if __solaris |
|||
# define _POSIX_PTHREAD_SEMANTICS 1 |
|||
/* try to bribe solaris headers into providing a current pthread API
|
|||
* despite environment being configured for an older version. |
|||
*/ |
|||
# define __EXTENSIONS__ 1 |
|||
#endif |
|||
|
|||
#include <unistd.h> |
|||
#include <fcntl.h> |
|||
#include <signal.h> |
|||
#include <limits.h> |
|||
#include <pthread.h> |
|||
|
|||
typedef pthread_mutex_t xmutex_t; |
|||
#if __linux && defined (PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP) |
|||
# define X_MUTEX_INIT PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP |
|||
# define X_MUTEX_CREATE(mutex) \ |
|||
do { \ |
|||
pthread_mutexattr_t attr; \ |
|||
pthread_mutexattr_init (&attr); \ |
|||
pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_ADAPTIVE_NP); \ |
|||
pthread_mutex_init (&(mutex), &attr); \ |
|||
} while (0) |
|||
#else |
|||
# define X_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER |
|||
# define X_MUTEX_CREATE(mutex) pthread_mutex_init (&(mutex), 0) |
|||
#endif |
|||
#define X_LOCK(mutex) pthread_mutex_lock (&(mutex)) |
|||
#define X_UNLOCK(mutex) pthread_mutex_unlock (&(mutex)) |
|||
|
|||
typedef pthread_cond_t xcond_t; |
|||
#define X_COND_INIT PTHREAD_COND_INITIALIZER |
|||
#define X_COND_CREATE(cond) pthread_cond_init (&(cond), 0) |
|||
#define X_COND_SIGNAL(cond) pthread_cond_signal (&(cond)) |
|||
#define X_COND_WAIT(cond,mutex) pthread_cond_wait (&(cond), &(mutex)) |
|||
#define X_COND_TIMEDWAIT(cond,mutex,to) pthread_cond_timedwait (&(cond), &(mutex), &(to)) |
|||
|
|||
typedef pthread_t xthread_t; |
|||
#define X_THREAD_PROC(name) static void *name (void *thr_arg) |
|||
#define X_THREAD_ATFORK(prepare,parent,child) pthread_atfork (prepare, parent, child) |
|||
|
|||
// the broken bsd's once more
|
|||
#ifndef PTHREAD_STACK_MIN |
|||
# define PTHREAD_STACK_MIN 0 |
|||
#endif |
|||
|
|||
#ifndef XTHREAD_STACKSIZE |
|||
# define XTHREAD_STACKSIZE sizeof (void *) * 4096 |
|||
#endif |
|||
|
|||
static int |
|||
xthread_create (xthread_t *tid, void *(*proc)(void *), void *arg) |
|||
{ |
|||
int retval; |
|||
sigset_t fullsigset, oldsigset; |
|||
pthread_attr_t attr; |
|||
|
|||
pthread_attr_init (&attr); |
|||
pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); |
|||
pthread_attr_setstacksize (&attr, PTHREAD_STACK_MIN < X_STACKSIZE ? X_STACKSIZE : PTHREAD_STACK_MIN); |
|||
#ifdef PTHREAD_SCOPE_PROCESS |
|||
pthread_attr_setscope (&attr, PTHREAD_SCOPE_PROCESS); |
|||
#endif |
|||
|
|||
sigfillset (&fullsigset); |
|||
|
|||
pthread_sigmask (SIG_SETMASK, &fullsigset, &oldsigset); |
|||
retval = pthread_create (tid, &attr, proc, arg) == 0; |
|||
pthread_sigmask (SIG_SETMASK, &oldsigset, 0); |
|||
|
|||
pthread_attr_destroy (&attr); |
|||
|
|||
return retval; |
|||
} |
|||
|
|||
#define respipe_read(a,b,c) read ((a), (b), (c)) |
|||
#define respipe_write(a,b,c) write ((a), (b), (c)) |
|||
#define respipe_close(a) close ((a)) |
|||
|
|||
#endif |
|||
|
|||
#endif |
|||
|
File diff suppressed because it is too large
@ -0,0 +1,144 @@ |
|||
/* 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 <errno.h> |
|||
#include <stddef.h> /* NULL */ |
|||
#include <stdlib.h> |
|||
#include <string.h> |
|||
|
|||
|
|||
static void uv__getaddrinfo_work(struct uv__work* w) { |
|||
uv_getaddrinfo_t* req = container_of(w, uv_getaddrinfo_t, work_req); |
|||
|
|||
req->retcode = getaddrinfo(req->hostname, |
|||
req->service, |
|||
req->hints, |
|||
&req->res); |
|||
} |
|||
|
|||
|
|||
static void uv__getaddrinfo_done(struct uv__work* w) { |
|||
uv_getaddrinfo_t* req = container_of(w, uv_getaddrinfo_t, work_req); |
|||
struct addrinfo *res = req->res; |
|||
#if __sun |
|||
size_t hostlen = strlen(req->hostname); |
|||
#endif |
|||
|
|||
req->res = NULL; |
|||
|
|||
uv__req_unregister(req->loop, req); |
|||
|
|||
/* see initialization in uv_getaddrinfo() */ |
|||
if (req->hints) |
|||
free(req->hints); |
|||
else if (req->service) |
|||
free(req->service); |
|||
else if (req->hostname) |
|||
free(req->hostname); |
|||
else |
|||
assert(0); |
|||
|
|||
if (req->retcode == 0) { |
|||
/* OK */ |
|||
#if EAI_NODATA /* FreeBSD deprecated EAI_NODATA */ |
|||
} else if (req->retcode == EAI_NONAME || req->retcode == EAI_NODATA) { |
|||
#else |
|||
} else if (req->retcode == EAI_NONAME) { |
|||
#endif |
|||
uv__set_sys_error(req->loop, ENOENT); /* FIXME compatibility hack */ |
|||
#if __sun |
|||
} else if (req->retcode == EAI_MEMORY && hostlen >= MAXHOSTNAMELEN) { |
|||
uv__set_sys_error(req->loop, ENOENT); |
|||
#endif |
|||
} else { |
|||
req->loop->last_err.code = UV_EADDRINFO; |
|||
req->loop->last_err.sys_errno_ = req->retcode; |
|||
} |
|||
|
|||
req->cb(req, req->retcode, res); |
|||
} |
|||
|
|||
|
|||
int uv_getaddrinfo(uv_loop_t* loop, |
|||
uv_getaddrinfo_t* req, |
|||
uv_getaddrinfo_cb cb, |
|||
const char* hostname, |
|||
const char* service, |
|||
const struct addrinfo* hints) { |
|||
size_t hostname_len; |
|||
size_t service_len; |
|||
size_t hints_len; |
|||
size_t len; |
|||
char* buf; |
|||
|
|||
if (req == NULL || cb == NULL || (hostname == NULL && service == NULL)) |
|||
return uv__set_artificial_error(loop, UV_EINVAL); |
|||
|
|||
hostname_len = hostname ? strlen(hostname) + 1 : 0; |
|||
service_len = service ? strlen(service) + 1 : 0; |
|||
hints_len = hints ? sizeof(*hints) : 0; |
|||
buf = malloc(hostname_len + service_len + hints_len); |
|||
|
|||
if (buf == NULL) |
|||
return uv__set_artificial_error(loop, UV_ENOMEM); |
|||
|
|||
uv__req_init(loop, req, UV_GETADDRINFO); |
|||
req->loop = loop; |
|||
req->cb = cb; |
|||
req->res = NULL; |
|||
req->hints = NULL; |
|||
req->service = NULL; |
|||
req->hostname = NULL; |
|||
req->retcode = 0; |
|||
|
|||
/* order matters, see uv_getaddrinfo_done() */ |
|||
len = 0; |
|||
|
|||
if (hints) { |
|||
req->hints = memcpy(buf + len, hints, sizeof(*hints)); |
|||
len += sizeof(*hints); |
|||
} |
|||
|
|||
if (service) { |
|||
req->service = memcpy(buf + len, service, service_len); |
|||
len += service_len; |
|||
} |
|||
|
|||
if (hostname) { |
|||
req->hostname = memcpy(buf + len, hostname, hostname_len); |
|||
len += hostname_len; |
|||
} |
|||
|
|||
uv__work_submit(loop, |
|||
&req->work_req, |
|||
uv__getaddrinfo_work, |
|||
uv__getaddrinfo_done); |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
|
|||
void uv_freeaddrinfo(struct addrinfo* ai) { |
|||
if (ai) |
|||
freeaddrinfo(ai); |
|||
} |
@ -0,0 +1,176 @@ |
|||
/* 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 "internal.h" |
|||
|
|||
#include <errno.h> |
|||
#include <pthread.h> |
|||
|
|||
/* TODO add condvar support to libuv */ |
|||
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; |
|||
static pthread_cond_t cond = PTHREAD_COND_INITIALIZER; |
|||
static pthread_once_t once = PTHREAD_ONCE_INIT; |
|||
static pthread_t threads[4]; |
|||
static ngx_queue_t exit_message; |
|||
static ngx_queue_t wq = { &wq, &wq }; |
|||
|
|||
|
|||
static void* worker(void* arg) { |
|||
struct uv__work* w; |
|||
ngx_queue_t* q; |
|||
|
|||
(void) arg; |
|||
|
|||
for (;;) { |
|||
if (pthread_mutex_lock(&mutex)) |
|||
abort(); |
|||
|
|||
while (ngx_queue_empty(&wq)) |
|||
if (pthread_cond_wait(&cond, &mutex)) |
|||
abort(); |
|||
|
|||
q = ngx_queue_head(&wq); |
|||
|
|||
if (q == &exit_message) |
|||
pthread_cond_signal(&cond); |
|||
else |
|||
ngx_queue_remove(q); |
|||
|
|||
if (pthread_mutex_unlock(&mutex)) |
|||
abort(); |
|||
|
|||
if (q == &exit_message) |
|||
break; |
|||
|
|||
w = ngx_queue_data(q, struct uv__work, wq); |
|||
w->work(w); |
|||
|
|||
uv_mutex_lock(&w->loop->wq_mutex); |
|||
ngx_queue_insert_tail(&w->loop->wq, &w->wq); |
|||
uv_mutex_unlock(&w->loop->wq_mutex); |
|||
uv_async_send(&w->loop->wq_async); |
|||
} |
|||
|
|||
return NULL; |
|||
} |
|||
|
|||
|
|||
static void post(ngx_queue_t* q) { |
|||
pthread_mutex_lock(&mutex); |
|||
ngx_queue_insert_tail(&wq, q); |
|||
pthread_cond_signal(&cond); |
|||
pthread_mutex_unlock(&mutex); |
|||
} |
|||
|
|||
|
|||
static void init_once(void) { |
|||
unsigned int i; |
|||
|
|||
ngx_queue_init(&wq); |
|||
|
|||
for (i = 0; i < ARRAY_SIZE(threads); i++) |
|||
if (pthread_create(threads + i, NULL, worker, NULL)) |
|||
abort(); |
|||
} |
|||
|
|||
|
|||
__attribute__((destructor)) |
|||
static void cleanup(void) { |
|||
unsigned int i; |
|||
int err; |
|||
|
|||
post(&exit_message); |
|||
|
|||
for (i = 0; i < ARRAY_SIZE(threads); i++) { |
|||
err = pthread_join(threads[i], NULL); |
|||
assert(err == 0 || err == EINVAL || err == ESRCH); |
|||
(void) err; /* Silence compiler warning in release builds. */ |
|||
} |
|||
} |
|||
|
|||
|
|||
void uv__work_submit(uv_loop_t* loop, |
|||
struct uv__work* w, |
|||
void (*work)(struct uv__work* w), |
|||
void (*done)(struct uv__work* w)) { |
|||
pthread_once(&once, init_once); |
|||
w->loop = loop; |
|||
w->work = work; |
|||
w->done = done; |
|||
post(&w->wq); |
|||
} |
|||
|
|||
|
|||
void uv__work_done(uv_async_t* handle, int status) { |
|||
struct uv__work* w; |
|||
uv_loop_t* loop; |
|||
ngx_queue_t* q; |
|||
ngx_queue_t wq; |
|||
|
|||
loop = container_of(handle, uv_loop_t, wq_async); |
|||
ngx_queue_init(&wq); |
|||
|
|||
uv_mutex_lock(&loop->wq_mutex); |
|||
if (!ngx_queue_empty(&loop->wq)) { |
|||
q = ngx_queue_head(&loop->wq); |
|||
ngx_queue_split(&loop->wq, q, &wq); |
|||
} |
|||
uv_mutex_unlock(&loop->wq_mutex); |
|||
|
|||
while (!ngx_queue_empty(&wq)) { |
|||
q = ngx_queue_head(&wq); |
|||
ngx_queue_remove(q); |
|||
|
|||
w = container_of(q, struct uv__work, wq); |
|||
w->done(w); |
|||
} |
|||
} |
|||
|
|||
|
|||
static void uv__queue_work(struct uv__work* w) { |
|||
uv_work_t* req = container_of(w, uv_work_t, work_req); |
|||
|
|||
if (req->work_cb) |
|||
req->work_cb(req); |
|||
} |
|||
|
|||
|
|||
static void uv__queue_done(struct uv__work* w) { |
|||
uv_work_t* req = container_of(w, uv_work_t, work_req); |
|||
|
|||
uv__req_unregister(req->loop, req); |
|||
|
|||
if (req->after_work_cb) |
|||
req->after_work_cb(req); |
|||
} |
|||
|
|||
|
|||
int uv_queue_work(uv_loop_t* loop, |
|||
uv_work_t* req, |
|||
uv_work_cb work_cb, |
|||
uv_after_work_cb after_work_cb) { |
|||
uv__req_init(loop, req, UV_WORK); |
|||
req->loop = loop; |
|||
req->work_cb = work_cb; |
|||
req->after_work_cb = after_work_cb; |
|||
uv__work_submit(loop, &req->work_req, uv__queue_work, uv__queue_done); |
|||
return 0; |
|||
} |
@ -1,107 +0,0 @@ |
|||
/* 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. |
|||
*/ |
|||
|
|||
/* This file integrates the libuv event loop with the libeio thread pool */ |
|||
|
|||
#include "uv.h" |
|||
#include "eio.h" |
|||
#include "internal.h" |
|||
|
|||
#include <assert.h> |
|||
#include <stdio.h> |
|||
|
|||
|
|||
static uv_once_t uv__eio_init_once_guard = UV_ONCE_INIT; |
|||
|
|||
|
|||
static void uv_eio_do_poll(uv_idle_t* watcher, int status) { |
|||
uv_loop_t* loop = watcher->loop; |
|||
assert(watcher == &loop->uv_eio_poller); |
|||
if (eio_poll(&loop->uv_eio_channel) != -1) |
|||
uv_idle_stop(watcher); |
|||
} |
|||
|
|||
|
|||
/* Called from the main thread. */ |
|||
static void uv_eio_want_poll_notifier_cb(uv_async_t* watcher, int status) { |
|||
uv_loop_t* loop = watcher->loop; |
|||
assert(watcher == &loop->uv_eio_want_poll_notifier); |
|||
if (eio_poll(&loop->uv_eio_channel) == -1) |
|||
uv_idle_start(&loop->uv_eio_poller, uv_eio_do_poll); |
|||
} |
|||
|
|||
|
|||
static void uv_eio_done_poll_notifier_cb(uv_async_t* watcher, int revents) { |
|||
uv_loop_t* loop = watcher->loop; |
|||
assert(watcher == &loop->uv_eio_done_poll_notifier); |
|||
if (eio_poll(&loop->uv_eio_channel) != -1) |
|||
uv_idle_stop(&loop->uv_eio_poller); |
|||
} |
|||
|
|||
|
|||
/*
|
|||
* uv_eio_want_poll() is called from the EIO thread pool each time an EIO |
|||
* request (that is, one of the node.fs.* functions) has completed. |
|||
*/ |
|||
static void uv_eio_want_poll(eio_channel *channel) { |
|||
/* Signal the main thread that eio_poll need to be processed. */ |
|||
uv_loop_t* loop = channel->data; |
|||
uv_async_send(&loop->uv_eio_want_poll_notifier); |
|||
} |
|||
|
|||
|
|||
static void uv_eio_done_poll(eio_channel *channel) { |
|||
/*
|
|||
* Signal the main thread that we should stop calling eio_poll(). |
|||
* from the idle watcher. |
|||
*/ |
|||
uv_loop_t* loop = channel->data; |
|||
uv_async_send(&loop->uv_eio_done_poll_notifier); |
|||
} |
|||
|
|||
|
|||
static void uv__eio_init(void) { |
|||
eio_init(uv_eio_want_poll, uv_eio_done_poll); |
|||
} |
|||
|
|||
|
|||
void uv_eio_init(uv_loop_t* loop) { |
|||
if (loop->flags & UV_LOOP_EIO_INITIALIZED) return; |
|||
loop->flags |= UV_LOOP_EIO_INITIALIZED; |
|||
|
|||
uv_idle_init(loop, &loop->uv_eio_poller); |
|||
uv_idle_start(&loop->uv_eio_poller, uv_eio_do_poll); |
|||
loop->uv_eio_poller.flags |= UV__HANDLE_INTERNAL; |
|||
|
|||
loop->uv_eio_want_poll_notifier.data = loop; |
|||
uv_async_init(loop, |
|||
&loop->uv_eio_want_poll_notifier, |
|||
uv_eio_want_poll_notifier_cb); |
|||
loop->uv_eio_want_poll_notifier.flags |= UV__HANDLE_INTERNAL; |
|||
uv__handle_unref(&loop->uv_eio_want_poll_notifier); |
|||
|
|||
uv_async_init(loop, |
|||
&loop->uv_eio_done_poll_notifier, |
|||
uv_eio_done_poll_notifier_cb); |
|||
loop->uv_eio_done_poll_notifier.flags |= UV__HANDLE_INTERNAL; |
|||
uv__handle_unref(&loop->uv_eio_done_poll_notifier); |
|||
|
|||
uv_once(&uv__eio_init_once_guard, uv__eio_init); |
|||
} |
@ -1,13 +0,0 @@ |
|||
/* This header is private to libuv */ |
|||
#ifndef UV_EIO_H_ |
|||
#define UV_EIO_H_ |
|||
|
|||
#include "eio.h" |
|||
|
|||
/*
|
|||
* Call this function to integrate libeio into the libuv event loop. It is |
|||
* safe to call more than once. |
|||
* TODO: uv_eio_deinit |
|||
*/ |
|||
void uv_eio_init(uv_loop_t*); |
|||
#endif |
@ -0,0 +1,173 @@ |
|||
/* 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 "task.h" |
|||
|
|||
#include <string.h> |
|||
#include <errno.h> |
|||
|
|||
typedef struct { |
|||
uv_mutex_t mutex; |
|||
uv_cond_t cond; |
|||
int delay; |
|||
int use_broadcast; |
|||
volatile int posted; |
|||
} worker_config; |
|||
|
|||
|
|||
static void worker(void* arg) { |
|||
worker_config* c = arg; |
|||
|
|||
if (c->delay) |
|||
uv_sleep(c->delay); |
|||
|
|||
uv_mutex_lock(&c->mutex); |
|||
ASSERT(c->posted == 0); |
|||
c->posted = 1; |
|||
if (c->use_broadcast) |
|||
uv_cond_broadcast(&c->cond); |
|||
else |
|||
uv_cond_signal(&c->cond); |
|||
uv_mutex_unlock(&c->mutex); |
|||
} |
|||
|
|||
|
|||
TEST_IMPL(condvar_1) { |
|||
uv_thread_t thread; |
|||
worker_config wc; |
|||
|
|||
memset(&wc, 0, sizeof(wc)); |
|||
|
|||
ASSERT(0 == uv_cond_init(&wc.cond)); |
|||
ASSERT(0 == uv_mutex_init(&wc.mutex)); |
|||
ASSERT(0 == uv_thread_create(&thread, worker, &wc)); |
|||
|
|||
uv_mutex_lock(&wc.mutex); |
|||
uv_sleep(100); |
|||
uv_cond_wait(&wc.cond, &wc.mutex); |
|||
ASSERT(wc.posted == 1); |
|||
uv_mutex_unlock(&wc.mutex); |
|||
|
|||
ASSERT(0 == uv_thread_join(&thread)); |
|||
uv_mutex_destroy(&wc.mutex); |
|||
uv_cond_destroy(&wc.cond); |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
|
|||
TEST_IMPL(condvar_2) { |
|||
uv_thread_t thread; |
|||
worker_config wc; |
|||
|
|||
memset(&wc, 0, sizeof(wc)); |
|||
wc.delay = 100; |
|||
|
|||
ASSERT(0 == uv_cond_init(&wc.cond)); |
|||
ASSERT(0 == uv_mutex_init(&wc.mutex)); |
|||
ASSERT(0 == uv_thread_create(&thread, worker, &wc)); |
|||
|
|||
uv_mutex_lock(&wc.mutex); |
|||
uv_cond_wait(&wc.cond, &wc.mutex); |
|||
uv_mutex_unlock(&wc.mutex); |
|||
|
|||
ASSERT(0 == uv_thread_join(&thread)); |
|||
uv_mutex_destroy(&wc.mutex); |
|||
uv_cond_destroy(&wc.cond); |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
|
|||
TEST_IMPL(condvar_3) { |
|||
uv_thread_t thread; |
|||
worker_config wc; |
|||
int r; |
|||
|
|||
memset(&wc, 0, sizeof(wc)); |
|||
wc.delay = 100; |
|||
|
|||
ASSERT(0 == uv_cond_init(&wc.cond)); |
|||
ASSERT(0 == uv_mutex_init(&wc.mutex)); |
|||
ASSERT(0 == uv_thread_create(&thread, worker, &wc)); |
|||
|
|||
uv_mutex_lock(&wc.mutex); |
|||
r = uv_cond_timedwait(&wc.cond, &wc.mutex, (uint64_t)(50 * 1e6)); |
|||
ASSERT(r == -1); |
|||
uv_mutex_unlock(&wc.mutex); |
|||
|
|||
ASSERT(0 == uv_thread_join(&thread)); |
|||
uv_mutex_destroy(&wc.mutex); |
|||
uv_cond_destroy(&wc.cond); |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
|
|||
TEST_IMPL(condvar_4) { |
|||
uv_thread_t thread; |
|||
worker_config wc; |
|||
int r; |
|||
|
|||
memset(&wc, 0, sizeof(wc)); |
|||
wc.delay = 100; |
|||
|
|||
ASSERT(0 == uv_cond_init(&wc.cond)); |
|||
ASSERT(0 == uv_mutex_init(&wc.mutex)); |
|||
ASSERT(0 == uv_thread_create(&thread, worker, &wc)); |
|||
|
|||
uv_mutex_lock(&wc.mutex); |
|||
r = uv_cond_timedwait(&wc.cond, &wc.mutex, (uint64_t)(150 * 1e6)); |
|||
ASSERT(r == 0); |
|||
uv_mutex_unlock(&wc.mutex); |
|||
|
|||
ASSERT(0 == uv_thread_join(&thread)); |
|||
uv_mutex_destroy(&wc.mutex); |
|||
uv_cond_destroy(&wc.cond); |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
|
|||
TEST_IMPL(condvar_5) { |
|||
uv_thread_t thread; |
|||
worker_config wc; |
|||
|
|||
memset(&wc, 0, sizeof(wc)); |
|||
wc.use_broadcast = 1; |
|||
|
|||
ASSERT(0 == uv_cond_init(&wc.cond)); |
|||
ASSERT(0 == uv_mutex_init(&wc.mutex)); |
|||
ASSERT(0 == uv_thread_create(&thread, worker, &wc)); |
|||
|
|||
uv_mutex_lock(&wc.mutex); |
|||
uv_sleep(100); |
|||
uv_cond_wait(&wc.cond, &wc.mutex); |
|||
ASSERT(wc.posted == 1); |
|||
uv_mutex_unlock(&wc.mutex); |
|||
|
|||
ASSERT(0 == uv_thread_join(&thread)); |
|||
uv_mutex_destroy(&wc.mutex); |
|||
uv_cond_destroy(&wc.cond); |
|||
|
|||
return 0; |
|||
} |
Loading…
Reference in new issue