Commit Graph

125 Commits

Author SHA1 Message Date
Ben Noordhuis
fb2a6d4a15 openbsd: fix uv_fs_sendfile() unused variable warnings 2013-08-05 02:45:59 +02:00
Ben Noordhuis
0e7ba080b4 unix, windows: make buf arg to uv_fs_write const
Change the uv_fs_write() prototype so the 'buf' argument is now
`const void*` rather than `void*`.

The argument is stored in a non-const field in the uv_fs_t but that's
inconsequential because the memory it points to is not touched.
2013-07-29 05:27:45 +02:00
Ben Noordhuis
3d4099ebcb Merge remote-tracking branch 'origin/v0.10'
Conflicts:
	AUTHORS
	ChangeLog
	src/version.c
	src/win/fs.c
2013-07-25 20:01:31 +02:00
Ben Noordhuis
d779eb53d5 unix, windows: fix uv_fs_chown() function prototype
Before this commit, uv_fs_chown() and uv_fs_fchown() took the uid and
gid as signed integers which is wrong because uid_t and gid_t are
unsigned on most all platforms and IDs that don't fit in a signed
integer do exist.

This is not an ABI change because the size of the uid and gid arguments
do not change, only their sign.

On Windows, uv_uid_t and uv_gid_t are typedef'd as unsigned char for
reasons that are unclear. It doesn't matter: they get cast to ints when
used as function arguments. The arguments themselves are unused.

Partial fix for joyent/node#5890.
2013-07-23 13:24:37 +02:00
Ben Noordhuis
3ee4d3f183 unix, windows: return error codes directly
This commit changes the libuv API to return error codes directly rather
than storing them in a loop-global field.

A code snippet like this one:

    if (uv_foo(loop) < 0) {
      uv_err_t err = uv_last_error(loop);
      fprintf(stderr, "%s\n", uv_strerror(err));
    }

Should be rewritten like this:

    int err = uv_foo(loop);
    if (err < 0)
      fprintf(stderr, "%s\n", uv_strerror(err));

The rationale for this change is that it should make creating bindings
for other languages a lot easier: dealing with struct return values is
painful with most FFIs and often downright buggy.
2013-07-07 09:51:00 +02:00
Saúl Ibarra Corretgé
f9e6029b82 unix, windows: add extra fields to uv_stat_t 2013-06-28 00:42:37 +02:00
Wynn Wilkes
b4c658c3c0 darwin: make uv_fs_sendfile() respect length param
The darwin sendfile implementation uses the &len parameter as input
and output. The code was sending 0 (not using the value of req->len)
so the behavior wasn't what the caller was expecting.

This makes sure to initialize len with req->len to ensure that the
caller can send portions of a file (not always everything to the
end of the file).
2013-05-29 22:25:43 +02:00
Ben Noordhuis
8ef9592a95 Merge remote-tracking branch 'origin/v0.10'
Conflicts:
	ChangeLog
	src/unix/stream.c
	src/version.c
2013-05-29 23:32:07 +02:00
Sean Silva
c39648674c unix: appease warning about non-standard inline
Clang warns about using `inline`, which is not technically allowed in
C89 mode (libuv compiles with `-std=c89`). It's probably best to leave
it to the compiler to do the inlining anyway.
2013-05-25 13:08:05 +02:00
Timothy J Fontaine
499c7976c6 unix, windows: nanosecond resolution for uv_fs_[fl]stat
Closes #739.
2013-03-19 21:48:15 +01:00
Ben Noordhuis
39c8a90a91 unix: set errno in sendfile emulation
The sendfile emulation in src/unix/fs.c polls the file descriptor for
write readiness. If POLLERR or POLLHUP is set, it bails out but doesn't
set errno (hence it doesn't report a useful error code). Rectify that.

Fixes #620.
2013-02-25 03:22:11 +01:00
Ben Noordhuis
8d746ff72d unix: remove scandir prototype workaround in fs.c
It's not necessary for newer OS X releases and I don't care enough
about OpenBSD to squelch the warning.
2013-02-06 16:32:05 +01:00
Ben Noordhuis
372ac34d5f linux: translate futimes() fallback error codes
The fallback added in 9d4a16e uses the /proc filesystem to emulate
utimensat().

Translate error codes that indicate no procfs is mounted to ENOSYS.
Letting those error codes through unchecked will only confuse callers.
2013-01-17 18:43:07 +01:00
Ben Noordhuis
9d4a16eefe linux: add futimes() fallback
The utimensat() syscall was added in 2.6.22. Add a fallback mode for
older kernels that uses utimes("/proc/self/fd/<fd>").

Fixes #687.
2013-01-17 14:22:55 +01:00
Saúl Ibarra Corretgé
9614d51135 unix: reset errno when using sendfile emulation
A common way to check if a uv_fs_t request failed is to check that
req->errorno != 0.

With uv_fs_sendfile(), when the sendfile() syscall fails, req->errorno is set
to (for example) ENOTSOCK, even when the emulation code path succeeds.

Zero errno before the call to uv__fs_sendfile_emul() to prevent that from
happening.
2012-12-28 16:00:49 +01:00
Ben Noordhuis
92fb84b751 unix: rework uv_cancel() api
Bert Belder informs me the current approach where a request is immediately
cancelled, is impossible to implement on Windows.

Rework the API to always invoke the "done" callback with an UV_ECANCELED error
code.
2012-12-13 13:46:38 +01:00
Ben Noordhuis
52c8a8617d unix: add uv_cancel() 2012-12-09 15:12:42 +01:00
Ben Noordhuis
e997dd5981 dragonflybsd: fix uv_fs_futime() 2012-11-20 00:38:24 +01:00
Ben Noordhuis
be597ba625 unix: set req type to UV_FS 2012-11-02 14:23:23 +01:00
Ben Noordhuis
cb03e3bd26 darwin: work around concurrent write() kernel bug
Simultaneously writing from multiple threads to the same file descriptor is not
safe on OS X. We already serialized all pwrite() system calls, apply the same
workaround to the write() system call.

Fixes a node.js test, test/simple/test-fs-sir-writes-alot.js, that was failing
because parts of the output file got filled with nul bytes.
2012-10-10 02:15:54 +02:00
Ben Noordhuis
b152b12772 unix: fix scandir filter prototype again
The only platforms where the dirent argument is non-const are OS X, OpenBSD
and older versions of FreeBSD (but not FreeBSD 9). Accommodate the first two.
2012-10-06 22:25:58 +02:00
Ben Noordhuis
7833df14ba freebsd, openbsd: don't use fdatasync()
The fdatasync() system call does not exist on either FreeBSD or OpenBSD, fall
back to fsync().
2012-10-06 17:19:12 +02:00
Artur Adib
fed718c6cb unix: move queue stuff from fs.c to threadpool.c 2012-10-03 23:56:01 +02:00
Ben Noordhuis
b37a0f5bb3 unix: fix small race in fs.c
Don't return req->result after posting the work request. It's possible (if
unlikely) for a worker thread to process the request before the main thread
reaches the return statement.
2012-10-02 23:06:08 +02:00
Ben Noordhuis
3977d1b36c unix: emulate sendfile if necessary
Some platforms don't support sendfile() (netbsd, openbsd), others don't support
arbitrary file descriptors (freebsd, darwin) and yet others have quirks in their
implementation (sunos).

Work around the quirks. If all else fails, fall back to sendfile() emulation.
2012-10-02 22:50:42 +02:00
Ben Noordhuis
2d3760a17c unix: fix scandir filter prototype
The dirent argument is const on systems that conform to POSIX.2008 (Linux and
Solaris) but non-const on others.
2012-10-02 14:40:27 +02:00
Ben Noordhuis
d36e2f21cf unix: fix buffer overrun in fs.c 2012-10-01 23:50:58 +02:00
Ben Noordhuis
7320633c4b unix: remove uv_fs_stat windows compat hack
uv_fs_stat and uv_fs_lstat removed the trailing backslash (if any) from the path
in order to please a test case that was written for Windows. Remove the
compatibility hack and fix the test.
2012-10-01 22:53:59 +02:00
Ben Noordhuis
74999f8f99 unix: port fs and work api to new thread pool 2012-10-01 22:53:59 +02:00
Fedor Indutny
23dc564f3b darwin: emulate fdatasync() with fcntl(F_FULLFSYNC)
OS X has no public API for fdatasync. And as pointed out in `man fsync(2)`:

  For applications that require tighter guarantees about the integrity of
  their data, Mac OS X provides the F_FULLFSYNC fcntl. The F_FULLFSYNC
  fcntl asks the drive to flush all buffered data to permanent storage.
  Applications, such as databases, that require a strict ordering of writes
  should use F_FULLFSYNC to ensure that their data is written in the order
  they expect.  Please see fcntl(2) for more detail.
2012-08-11 23:43:51 +02:00
Ben Noordhuis
f97c80fa98 unix: fix const correctness compiler warning 2012-08-07 21:26:02 +02:00
Ben Noordhuis
9efa8b3571 unix, windows: rework reference counting scheme
This commit changes how the event loop determines if it needs to stay alive.

Previously, an internal counter was increased whenever a handle got created
and decreased again when the handle was closed.

While conceptually simple, it turned out hard to work with: you often want
to keep the event loop alive only if the handle is actually doing something.
Stopped or inactive handles were a frequent source of hanging event loops.

That's why this commit changes the reference counting scheme to a model where
a handle only references the event loop when it's active. 'Active' means
different things for different handle types, e.g.:

 * timers: ticking
 * sockets: reading, writing or listening
 * processes: always active (for now, subject to change)
 * idle, check, prepare: only active when started

This commit also changes how the uv_ref() and uv_unref() functions work: they
now operate on the level of individual handles, not the whole event loop.

The Windows implementation was done by Bert Belder.
2012-05-17 07:07:53 +02:00
Ben Noordhuis
ab3b307df3 unix: clean up uv__req_init() 2012-04-18 22:30:20 +02:00
Igor Zinkovsky
d5acfd0c05 64bit offsets for fs operations and cleanup uv_fs_* for uv-win 2012-04-18 11:05:27 -07:00
Ben Noordhuis
685b36ba66 linux: tidy up syscall code 2012-03-31 00:19:01 +00:00
Paddy Byers
abf9654a55 unix: create separate eio result queue per loop
Makes the eio "done" callback run in the thread that submitted it. Makes it safe
to use libeio from multiple event loops.
2011-12-20 20:47:33 +01:00
Shigeki Ohtsu
ba52023ef3 Fix missing increments of loop->counters 2011-12-12 18:01:26 +01:00
Ben Noordhuis
92c9e95721 unix: fix stray pointer free() when HAVE_FUTIMES=0
uv_fs_futime() failed to initialize req.path when HAVE_FUTIMES=0.
uv_fs_req_cleanup() later on tried to free the bogus pointer.
2011-11-22 00:00:52 +01:00
Ben Noordhuis
9757a43a57 unix: remove unused variable 2011-10-21 10:09:43 -07:00
Ben Noordhuis
721ad8c74f sunos: implement uv_fs_futime() 2011-10-12 02:05:52 +00:00
Ben Noordhuis
41e8574920 unix: don't alloc memory for readdir on empty dir 2011-10-10 16:27:55 +02:00
Erick Tryzelaar
23796d208c Fixes #76. Unify OS error reporting
As a nice fringe benefit, this also shaves a word
off of a windows TCP handle by replacing "uv_err_t
bind_error" with "int bind_error".
2011-09-27 19:05:33 -07:00
Ben Noordhuis
9673abeab5 unix: fix pointer ownership bug
libuv realloc'd a pointer that belonged to and was later freed by libev.
2011-09-27 01:02:44 +02:00
Ben Noordhuis
8f617b93bc unix: darwin < 10.6 does not have fdatasync, use fsync 2011-09-24 05:20:07 +02:00
Ben Noordhuis
c455f37803 unix: freebsd doesn't have fdatasync, do a full fsync instead 2011-08-17 06:40:39 +02:00
Erick Tryzelaar
905fe71341 unix: fix a compiler warning 2011-09-15 22:33:32 +02:00
Igor Zinkovsky
65c8a727a3 uv_fs_ functions to return result in sync mode 2011-09-14 11:47:49 -07:00
Ben Noordhuis
76216d8057 unix: handle readdir errors in uv__fs_after() 2011-09-14 17:59:44 +02:00
Ben Noordhuis
337ff16526 unix: revert "eio: fix memory leak in eio__scandir()"
This reverts commit b450d87719.

It turns out that libeio doesn't actually leak memory but it does do an
unnecessary (and confusing!) allocation that is not free'd until after
the user callback returns.
2011-09-14 17:59:41 +02:00
Ben Noordhuis
b450d87719 eio: fix memory leak in eio__scandir() 2011-09-12 18:01:43 +02:00
Ben Noordhuis
bd6066cb34 unix: fix readdir cleanup assertion 2011-09-10 00:14:42 +02:00
Ben Noordhuis
79d9f81881 unix: implement uv_fs_futime, add tests for uv_fs_utime and uv_fs_futime 2011-09-06 02:52:52 +02:00
Ben Noordhuis
efcd273d68 unix: translate fs errno codes to libuv error codes 2011-09-06 00:17:18 +02:00
Ben Noordhuis
bb0c6e6d53 unix: move linux feature detection macros to internal.h 2011-09-05 16:05:28 +02:00
Ben Noordhuis
a9ba756bfd unix: fix warning: comparison between signed and unsigned integer expressions 2011-09-05 15:04:16 +02:00
Ben Noordhuis
d9176108d2 unix: fix event loop not being unref'd on eio error 2011-09-05 15:03:52 +02:00
Ben Noordhuis
ed355d371e unix: fix const correctness warnings 2011-09-05 14:23:41 +02:00
Ryan Dahl
991f6ee044 unix: Set req->result to -1 on async uv_fs_readdir error
fixes test/simple/test-fs-error-messages.js in node.
2011-09-04 18:45:45 -07:00
Ryan Dahl
a18860aec6 Add uv_fs_t.path on unix and tests
Windows implementation missing https://github.com/joyent/libuv/issues/177
2011-09-04 18:05:11 -07:00
Ryan Dahl
b6ede6c724 unix: uv_fs_readdir sync skips . and ..
Fixes test fs_async_dir
2011-09-04 17:13:05 -07:00
Ben Noordhuis
d3f60da67c unix: implement uv_fs_readlink 2011-09-05 00:12:16 +02:00
Igor Zinkovsky
060026ced3 windows: uv_fs_link + uv_fs_symlink 2011-09-04 13:24:35 -07:00
Ryan Dahl
b89f4f34a4 implement uv_fs_utime 2011-09-01 17:40:57 -07:00
Ryan Dahl
b47fa77eb5 unix/fs.c: Apply macro magic, implement symlink, link, chown, fchown 2011-09-01 17:12:31 -07:00
Ryan Dahl
9f932f92cf add test fs_chmod, implement uv_fs_fchmod and uv_fs_chmod on unix 2011-09-01 15:36:01 -07:00
Ryan Dahl
2e6035895c Add test for uv_fs_fstat, implement on unix. 2011-09-01 14:15:06 -07:00
Ryan Dahl
ea4271fa90 submit error to correct loop 2011-08-31 01:43:09 -07:00
Ryan Dahl
e3f910d0a9 Multiplicity update on unix
Does not yet support multithreaded use of the thread pool.
2011-08-30 23:55:08 -07:00
Jeroen Janssen
2af955dbf4 Fix posix dirent usage
Fixes #161
2011-08-30 03:16:03 -07:00
Ryan Dahl
a6ed1757ab unix: implement uv_fs_lstat 2011-08-30 01:32:53 -07:00
Ryan Dahl
894c005c42 unix: fix fs_async_sendfile 2011-08-30 00:52:43 -07:00
Ryan Dahl
1a4ead53d6 unix: implement uv_queue_work 2011-08-29 22:57:34 -07:00
Ryan Dahl
0e81406bfb unix fs_async_dir works 2011-08-29 22:08:51 -07:00
Ryan Dahl
5d524fff1a unix passes test fs_file_async 2011-08-29 20:41:45 -07:00
Ryan Dahl
3be275bad7 Begin implementation of UNIX uv_fs_ functions
Adding this incomplete work now to ease rebase troubles later as it moves
the functions to src/unix/fs.c and introduces src/unix/internal.h.
2011-08-29 14:36:45 -07:00