Merge remote-tracking branch 'origin/v0.6'
This commit is contained in:
commit
4e1f2b1f64
11
include/uv.h
11
include/uv.h
@ -118,7 +118,9 @@ typedef intptr_t ssize_t;
|
||||
XX( 47, EEXIST, "file already exists") \
|
||||
XX( 48, ESRCH, "no such process") \
|
||||
XX( 49, ENAMETOOLONG, "name too long") \
|
||||
XX( 50, EPERM, "operation not permitted")
|
||||
XX( 50, EPERM, "operation not permitted") \
|
||||
XX( 51, ELOOP, "too many symbolic links encountered") \
|
||||
XX( 52, EXDEV, "cross-device link not permitted")
|
||||
|
||||
|
||||
#define UV_ERRNO_GEN(val, name, s) UV_##name = val,
|
||||
@ -504,6 +506,13 @@ struct uv_write_s {
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Used to determine whether a stream is readable or writable.
|
||||
* TODO: export in v0.8.
|
||||
*/
|
||||
/* UV_EXTERN */ int uv_is_readable(uv_stream_t* handle);
|
||||
/* UV_EXTERN */ int uv_is_writable(uv_stream_t* handle);
|
||||
|
||||
|
||||
/*
|
||||
* uv_tcp_t is a subclass of uv_stream_t
|
||||
|
||||
@ -74,6 +74,8 @@ uv_err_code uv_translate_sys_error(int sys_errno) {
|
||||
case EMSGSIZE: return UV_EMSGSIZE;
|
||||
case ENAMETOOLONG: return UV_ENAMETOOLONG;
|
||||
case EINVAL: return UV_EINVAL;
|
||||
case ECONNABORTED: return UV_ECONNABORTED;
|
||||
case ELOOP: return UV_ELOOP;
|
||||
case ECONNREFUSED: return UV_ECONNREFUSED;
|
||||
case EADDRINUSE: return UV_EADDRINUSE;
|
||||
case EADDRNOTAVAIL: return UV_EADDRNOTAVAIL;
|
||||
@ -85,6 +87,7 @@ uv_err_code uv_translate_sys_error(int sys_errno) {
|
||||
case EAI_NONAME: return UV_ENOENT;
|
||||
case ESRCH: return UV_ESRCH;
|
||||
case ETIMEDOUT: return UV_ETIMEDOUT;
|
||||
case EXDEV: return UV_EXDEV;
|
||||
default: return UV_UNKNOWN;
|
||||
}
|
||||
UNREACHABLE();
|
||||
|
||||
@ -802,6 +802,8 @@ int uv__connect(uv_connect_t* req, uv_stream_t* stream, struct sockaddr* addr,
|
||||
/* If we get a ECONNREFUSED wait until the next tick to report the
|
||||
* error. Solaris wants to report immediately--other unixes want to
|
||||
* wait.
|
||||
*
|
||||
* XXX: do the same for ECONNABORTED?
|
||||
*/
|
||||
case ECONNREFUSED:
|
||||
stream->delayed_error = errno;
|
||||
@ -966,3 +968,11 @@ int uv_read_stop(uv_stream_t* stream) {
|
||||
}
|
||||
|
||||
|
||||
int uv_is_readable(uv_stream_t* stream) {
|
||||
return stream->flags & UV_READABLE;
|
||||
}
|
||||
|
||||
|
||||
int uv_is_writable(uv_stream_t* stream) {
|
||||
return stream->flags & UV_WRITABLE;
|
||||
}
|
||||
|
||||
@ -69,7 +69,7 @@ uv_err_code uv_translate_sys_error(int sys_errno) {
|
||||
case ERROR_SUCCESS: return UV_OK;
|
||||
case ERROR_FILE_NOT_FOUND: return UV_ENOENT;
|
||||
case ERROR_PATH_NOT_FOUND: return UV_ENOENT;
|
||||
case ERROR_ACCESS_DENIED: return UV_EACCES;
|
||||
case ERROR_ACCESS_DENIED: return UV_EPERM;
|
||||
case ERROR_NOACCESS: return UV_EACCES;
|
||||
case WSAEACCES: return UV_EACCES;
|
||||
case ERROR_ADDRESS_ALREADY_ASSOCIATED: return UV_EADDRINUSE;
|
||||
@ -89,6 +89,7 @@ uv_err_code uv_translate_sys_error(int sys_errno) {
|
||||
case WSAEHOSTUNREACH: return UV_EHOSTUNREACH;
|
||||
case ERROR_INVALID_DATA: return UV_EINVAL;
|
||||
case WSAEINVAL: return UV_EINVAL;
|
||||
case ERROR_CANT_RESOLVE_FILENAME: return UV_ELOOP;
|
||||
case ERROR_TOO_MANY_OPEN_FILES: return UV_EMFILE;
|
||||
case WSAEMFILE: return UV_EMFILE;
|
||||
case WSAEMSGSIZE: return UV_EMSGSIZE;
|
||||
|
||||
186
src/win/fs.c
186
src/win/fs.c
@ -489,191 +489,61 @@ void fs__readdir(uv_fs_t* req, const wchar_t* path, int flags) {
|
||||
}
|
||||
|
||||
|
||||
#define IS_SLASH(c) \
|
||||
((wchar_t) c == L'/' || (wchar_t) c == L'\\')
|
||||
#define IS_COLON(c) \
|
||||
((wchar_t) c == L':')
|
||||
#define IS_LETTER(c) \
|
||||
((((wchar_t) c >= L'a') && ((wchar_t) c <= L'z')) || \
|
||||
(((wchar_t) c >= L'A') && ((wchar_t) c <= L'Z')))
|
||||
#define IS_QUESTION(c) \
|
||||
((wchar_t) c == L'?')
|
||||
|
||||
|
||||
static int uv__count_slash_separated_words(const wchar_t* pos,
|
||||
const wchar_t* end,
|
||||
int limit) {
|
||||
char last_was_slash = 1, count = 0;
|
||||
|
||||
for (; pos < end; pos++) {
|
||||
if (IS_SLASH(*pos)) {
|
||||
/* Don't accept double slashes */
|
||||
if (last_was_slash) {
|
||||
return 0;
|
||||
} else {
|
||||
last_was_slash = 1;
|
||||
}
|
||||
} else {
|
||||
if (last_was_slash) {
|
||||
/* Found a new word */
|
||||
count++;
|
||||
if (count > limit) {
|
||||
return -1;
|
||||
}
|
||||
last_was_slash = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns true if the given path is a root directory. The following patterns
|
||||
* are recognized:
|
||||
* \
|
||||
* c:\ (must have trailing slash)
|
||||
* \\server\share (trailing slash optional)
|
||||
* \\?\c: (trailing slash optional)
|
||||
* \\?\UNC\server\share (trailing slash optional)
|
||||
*/
|
||||
static int uv__is_root(const wchar_t* path) {
|
||||
size_t len = wcslen(path);
|
||||
|
||||
/* Test for \ */
|
||||
if (len == 1 && IS_SLASH(path[0])) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (len < 3) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Test for c:\ */
|
||||
if (IS_LETTER(path[0]) && IS_COLON(path[1]) && IS_SLASH(path[2])) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!IS_SLASH(path[0]) || !IS_SLASH(path[1])) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Test for \\server\share */
|
||||
if (!IS_QUESTION(path[2])) {
|
||||
return uv__count_slash_separated_words(path + 2, path + len, 2) == 2;
|
||||
}
|
||||
|
||||
if (!IS_SLASH(path[3])) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((len == 6 || len == 7) &&
|
||||
IS_LETTER(path[4]) && IS_COLON(path[5]) &&
|
||||
(len == 6 || IS_SLASH(path[6]))) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Test for \\?\UNC\server\share */
|
||||
if (len >= 8 &&
|
||||
(path[4] == L'u' || path[4] == L'U') &&
|
||||
(path[5] == L'n' || path[5] == L'N') &&
|
||||
(path[6] == L'c' || path[6] == L'C') &&
|
||||
IS_SLASH(path[7])) {
|
||||
return uv__count_slash_separated_words(path + 8, path + len, 2) == 2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void fs__stat(uv_fs_t* req, const wchar_t* path) {
|
||||
HANDLE file;
|
||||
WIN32_FIND_DATAW ent;
|
||||
static void fs__stat(uv_fs_t* req, const wchar_t* path) {
|
||||
HANDLE handle;
|
||||
int result;
|
||||
BY_HANDLE_FILE_INFORMATION info;
|
||||
|
||||
req->ptr = NULL;
|
||||
|
||||
if (uv__is_root(path)) {
|
||||
/* We can't stat root directories like c:\. _wstati64 can't either, but */
|
||||
/* it will make up something reasonable. */
|
||||
DWORD drive_type = GetDriveTypeW(path);
|
||||
if (drive_type == DRIVE_UNKNOWN || drive_type == DRIVE_NO_ROOT_DIR) {
|
||||
req->last_error = ERROR_PATH_NOT_FOUND;
|
||||
req->errorno = UV_ENOENT;
|
||||
req->result = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
memset(&req->stat, 0, sizeof req->stat);
|
||||
|
||||
req->stat.st_nlink = 1;
|
||||
req->stat.st_mode = ((_S_IREAD|_S_IWRITE) + ((_S_IREAD|_S_IWRITE) >> 3) +
|
||||
((_S_IREAD|_S_IWRITE) >> 6)) | S_IFDIR;
|
||||
|
||||
req->last_error = ERROR_SUCCESS;
|
||||
req->errorno = UV_OK;
|
||||
req->result = 0;
|
||||
req->ptr = &req->stat;
|
||||
return;
|
||||
}
|
||||
|
||||
file = FindFirstFileExW(path, FindExInfoStandard, &ent,
|
||||
FindExSearchNameMatch, NULL, 0);
|
||||
|
||||
if (file == INVALID_HANDLE_VALUE) {
|
||||
handle = CreateFileW(path,
|
||||
FILE_READ_ATTRIBUTES,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
|
||||
NULL,
|
||||
OPEN_EXISTING,
|
||||
FILE_FLAG_BACKUP_SEMANTICS,
|
||||
NULL);
|
||||
if (handle == INVALID_HANDLE_VALUE) {
|
||||
SET_REQ_RESULT_WIN32_ERROR(req, GetLastError());
|
||||
return;
|
||||
}
|
||||
|
||||
FindClose(file);
|
||||
|
||||
if (ent.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT &&
|
||||
ent.dwReserved0 == IO_REPARSE_TAG_SYMLINK) {
|
||||
fs__open(req, path, _O_RDONLY, 0);
|
||||
if (req->result != -1) {
|
||||
result = _fstati64(req->result, &req->stat);
|
||||
_close(req->result);
|
||||
|
||||
if (result != -1) {
|
||||
req->ptr = &req->stat;
|
||||
}
|
||||
|
||||
SET_REQ_RESULT(req, result);
|
||||
}
|
||||
|
||||
if (!GetFileInformationByHandle(handle, &info)) {
|
||||
SET_REQ_RESULT_WIN32_ERROR(req, GetLastError());
|
||||
CloseHandle(handle);
|
||||
return;
|
||||
}
|
||||
|
||||
req->stat.st_ino = 0;
|
||||
req->stat.st_uid = 0;
|
||||
req->stat.st_gid = 0;
|
||||
req->stat.st_mode = 0;
|
||||
req->stat.st_rdev = 0;
|
||||
req->stat.st_dev = 0;
|
||||
req->stat.st_nlink = 1;
|
||||
memset(&req->stat, 0, sizeof req->stat);
|
||||
|
||||
if (ent.dwFileAttributes & FILE_ATTRIBUTE_READONLY ) {
|
||||
/* TODO: set st_dev and st_ino? */
|
||||
|
||||
if (info.dwFileAttributes & FILE_ATTRIBUTE_READONLY) {
|
||||
req->stat.st_mode |= (_S_IREAD + (_S_IREAD >> 3) + (_S_IREAD >> 6));
|
||||
} else {
|
||||
req->stat.st_mode |= ((_S_IREAD|_S_IWRITE) + ((_S_IREAD|_S_IWRITE) >> 3) +
|
||||
((_S_IREAD|_S_IWRITE) >> 6));
|
||||
}
|
||||
|
||||
if (ent.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
|
||||
if (info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
|
||||
req->stat.st_mode |= _S_IFDIR;
|
||||
} else {
|
||||
req->stat.st_mode |= _S_IFREG;
|
||||
}
|
||||
|
||||
uv_filetime_to_time_t(&ent.ftLastWriteTime, &(req->stat.st_mtime));
|
||||
uv_filetime_to_time_t(&ent.ftLastAccessTime, &(req->stat.st_atime));
|
||||
uv_filetime_to_time_t(&ent.ftCreationTime, &(req->stat.st_ctime));
|
||||
uv_filetime_to_time_t(&info.ftLastWriteTime, &(req->stat.st_mtime));
|
||||
uv_filetime_to_time_t(&info.ftLastAccessTime, &(req->stat.st_atime));
|
||||
uv_filetime_to_time_t(&info.ftCreationTime, &(req->stat.st_ctime));
|
||||
|
||||
req->stat.st_size = ((int64_t)ent.nFileSizeHigh << 32) +
|
||||
(int64_t)ent.nFileSizeLow;
|
||||
req->stat.st_size = ((int64_t) info.nFileSizeHigh << 32) +
|
||||
(int64_t) info.nFileSizeLow;
|
||||
|
||||
req->stat.st_nlink = info.nNumberOfLinks;
|
||||
|
||||
req->ptr = &req->stat;
|
||||
req->result = 0;
|
||||
|
||||
CloseHandle(handle);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -98,6 +98,62 @@ static void uv_pipe_connection_init(uv_pipe_t* handle) {
|
||||
}
|
||||
|
||||
|
||||
static int open_named_pipe(uv_pipe_t* handle) {
|
||||
/*
|
||||
* Assume that we have a duplex pipe first, so attempt to
|
||||
* connect with GENERIC_READ | GENERIC_WRITE.
|
||||
*/
|
||||
handle->handle = CreateFileW(handle->name,
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
0,
|
||||
NULL,
|
||||
OPEN_EXISTING,
|
||||
FILE_FLAG_OVERLAPPED,
|
||||
NULL);
|
||||
|
||||
if (handle->handle != INVALID_HANDLE_VALUE) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* If the pipe is not duplex CreateFileW fails with
|
||||
* ERROR_ACCESS_DENIED. In that case try to connect
|
||||
* as a read-only or write-only.
|
||||
*/
|
||||
if (GetLastError() == ERROR_ACCESS_DENIED) {
|
||||
handle->handle = CreateFileW(handle->name,
|
||||
GENERIC_READ | FILE_WRITE_ATTRIBUTES,
|
||||
0,
|
||||
NULL,
|
||||
OPEN_EXISTING,
|
||||
FILE_FLAG_OVERLAPPED,
|
||||
NULL);
|
||||
|
||||
if (handle->handle != INVALID_HANDLE_VALUE) {
|
||||
handle->flags |= UV_HANDLE_SHUT;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (GetLastError() == ERROR_ACCESS_DENIED) {
|
||||
handle->handle = CreateFileW(handle->name,
|
||||
GENERIC_WRITE | FILE_READ_ATTRIBUTES,
|
||||
0,
|
||||
NULL,
|
||||
OPEN_EXISTING,
|
||||
FILE_FLAG_OVERLAPPED,
|
||||
NULL);
|
||||
|
||||
if (handle->handle != INVALID_HANDLE_VALUE) {
|
||||
handle->flags |= UV_HANDLE_EOF;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int uv_stdio_pipe_server(uv_loop_t* loop, uv_pipe_t* handle, DWORD access,
|
||||
char* name, size_t nameSize) {
|
||||
HANDLE pipeHandle;
|
||||
@ -437,15 +493,7 @@ static DWORD WINAPI pipe_connect_thread_proc(void* parameter) {
|
||||
/* We wait for the pipe to become available with WaitNamedPipe. */
|
||||
while (WaitNamedPipeW(handle->name, 30000)) {
|
||||
/* The pipe is now available, try to connect. */
|
||||
pipeHandle = CreateFileW(handle->name,
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
0,
|
||||
NULL,
|
||||
OPEN_EXISTING,
|
||||
FILE_FLAG_OVERLAPPED,
|
||||
NULL);
|
||||
|
||||
if (pipeHandle != INVALID_HANDLE_VALUE) {
|
||||
if (open_named_pipe(handle) == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
@ -471,7 +519,6 @@ void uv_pipe_connect(uv_connect_t* req, uv_pipe_t* handle,
|
||||
const char* name, uv_connect_cb cb) {
|
||||
uv_loop_t* loop = handle->loop;
|
||||
int errno, nameSize;
|
||||
HANDLE pipeHandle;
|
||||
|
||||
handle->handle = INVALID_HANDLE_VALUE;
|
||||
|
||||
@ -492,15 +539,7 @@ void uv_pipe_connect(uv_connect_t* req, uv_pipe_t* handle,
|
||||
goto error;
|
||||
}
|
||||
|
||||
pipeHandle = CreateFileW(handle->name,
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
0,
|
||||
NULL,
|
||||
OPEN_EXISTING,
|
||||
FILE_FLAG_OVERLAPPED,
|
||||
NULL);
|
||||
|
||||
if (pipeHandle == INVALID_HANDLE_VALUE) {
|
||||
if (open_named_pipe(handle) != 0) {
|
||||
if (GetLastError() == ERROR_PIPE_BUSY) {
|
||||
/* Wait for the server to make a pipe instance available. */
|
||||
if (!QueueUserWorkItem(&pipe_connect_thread_proc,
|
||||
@ -519,13 +558,13 @@ void uv_pipe_connect(uv_connect_t* req, uv_pipe_t* handle,
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (uv_set_pipe_handle(loop, (uv_pipe_t*)req->handle, pipeHandle)) {
|
||||
assert(handle->handle != INVALID_HANDLE_VALUE);
|
||||
|
||||
if (uv_set_pipe_handle(loop, (uv_pipe_t*)req->handle, handle->handle)) {
|
||||
errno = GetLastError();
|
||||
goto error;
|
||||
}
|
||||
|
||||
handle->handle = pipeHandle;
|
||||
|
||||
SET_REQ_SUCCESS(req);
|
||||
uv_insert_pending_req(loop, (uv_req_t*) req);
|
||||
handle->reqs_pending++;
|
||||
@ -537,8 +576,9 @@ error:
|
||||
handle->name = NULL;
|
||||
}
|
||||
|
||||
if (pipeHandle != INVALID_HANDLE_VALUE) {
|
||||
CloseHandle(pipeHandle);
|
||||
if (handle->handle != INVALID_HANDLE_VALUE) {
|
||||
CloseHandle(handle->handle);
|
||||
handle->handle = INVALID_HANDLE_VALUE;
|
||||
}
|
||||
|
||||
/* Make this req pending reporting an error. */
|
||||
|
||||
@ -186,3 +186,13 @@ size_t uv_count_bufs(uv_buf_t bufs[], int count) {
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
|
||||
int uv_is_readable(uv_stream_t* handle) {
|
||||
return !(handle->flags & UV_HANDLE_EOF);
|
||||
}
|
||||
|
||||
|
||||
int uv_is_writable(uv_stream_t* handle) {
|
||||
return !(handle->flags & UV_HANDLE_SHUT);
|
||||
}
|
||||
|
||||
@ -1096,6 +1096,7 @@ static int uv_tty_set_style(uv_tty_t* handle, DWORD* error) {
|
||||
} else if (arg == 39) {
|
||||
/* Default text color */
|
||||
fg_color = 7;
|
||||
fg_bright = 0;
|
||||
|
||||
} else if (arg >= 40 && arg <= 47) {
|
||||
/* Set background color */
|
||||
|
||||
@ -46,6 +46,10 @@
|
||||
#define IPV6_V6ONLY 27
|
||||
#endif
|
||||
|
||||
#ifndef IPV6_HOPLIMIT
|
||||
#define IPV6_HOPLIMIT 21
|
||||
#endif
|
||||
|
||||
/*
|
||||
* TDI defines that are only in the DDK.
|
||||
* We only need receive flags so far.
|
||||
|
||||
@ -131,6 +131,9 @@ static int ipc_helper(int listen_after_write) {
|
||||
|
||||
uv_pipe_open(&channel, 0);
|
||||
|
||||
ASSERT(uv_is_readable(&channel));
|
||||
ASSERT(uv_is_writable(&channel));
|
||||
|
||||
r = uv_tcp_init(uv_default_loop(), &tcp_server);
|
||||
ASSERT(r == 0);
|
||||
|
||||
|
||||
@ -432,6 +432,14 @@ static void open_nametoolong_cb(uv_fs_t* req) {
|
||||
uv_fs_req_cleanup(req);
|
||||
}
|
||||
|
||||
static void open_loop_cb(uv_fs_t* req) {
|
||||
ASSERT(req->fs_type == UV_FS_OPEN);
|
||||
ASSERT(req->errorno == UV_ELOOP);
|
||||
ASSERT(req->result == -1);
|
||||
open_cb_count++;
|
||||
uv_fs_req_cleanup(req);
|
||||
}
|
||||
|
||||
|
||||
TEST_IMPL(fs_file_noent) {
|
||||
uv_fs_t req;
|
||||
@ -483,6 +491,34 @@ TEST_IMPL(fs_file_nametoolong) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
TEST_IMPL(fs_file_loop) {
|
||||
uv_fs_t req;
|
||||
int r;
|
||||
|
||||
loop = uv_default_loop();
|
||||
|
||||
unlink("test_symlink");
|
||||
uv_fs_symlink(loop, &req, "test_symlink", "test_symlink", 0, NULL);
|
||||
uv_fs_req_cleanup(&req);
|
||||
|
||||
r = uv_fs_open(loop, &req, "test_symlink", O_RDONLY, 0, NULL);
|
||||
ASSERT(r == -1);
|
||||
ASSERT(req.result == -1);
|
||||
ASSERT(uv_last_error(loop).code == UV_ELOOP);
|
||||
uv_fs_req_cleanup(&req);
|
||||
|
||||
r = uv_fs_open(loop, &req, "test_symlink", O_RDONLY, 0, open_loop_cb);
|
||||
ASSERT(r == 0);
|
||||
|
||||
ASSERT(open_cb_count == 0);
|
||||
uv_run(loop);
|
||||
ASSERT(open_cb_count == 1);
|
||||
|
||||
unlink("test_symlink");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void check_utime(const char* path, double atime, double mtime) {
|
||||
struct stat* s;
|
||||
uv_fs_t req;
|
||||
@ -1309,6 +1345,19 @@ TEST_IMPL(fs_stat_root) {
|
||||
r = uv_fs_stat(loop, &stat_req, "\\", NULL);
|
||||
ASSERT(r == 0);
|
||||
|
||||
r = uv_fs_stat(loop, &stat_req, "..\\..\\..\\..\\..\\..\\..", NULL);
|
||||
ASSERT(r == 0);
|
||||
|
||||
r = uv_fs_stat(loop, &stat_req, "..", NULL);
|
||||
ASSERT(r == 0);
|
||||
|
||||
r = uv_fs_stat(loop, &stat_req, "..\\", NULL);
|
||||
ASSERT(r == 0);
|
||||
|
||||
/* stats the current directory on c: */
|
||||
r = uv_fs_stat(loop, &stat_req, "c:", NULL);
|
||||
ASSERT(r == 0);
|
||||
|
||||
r = uv_fs_stat(loop, &stat_req, "c:\\", NULL);
|
||||
ASSERT(r == 0);
|
||||
|
||||
|
||||
@ -48,6 +48,7 @@ TEST_DECLARE (tcp_bind6_error_inval)
|
||||
TEST_DECLARE (tcp_bind6_localhost_ok)
|
||||
TEST_DECLARE (udp_send_and_recv)
|
||||
TEST_DECLARE (udp_multicast_join)
|
||||
TEST_DECLARE (udp_multicast_ttl)
|
||||
TEST_DECLARE (udp_dgram_too_big)
|
||||
TEST_DECLARE (udp_dual_stack)
|
||||
TEST_DECLARE (udp_ipv6_only)
|
||||
@ -108,6 +109,7 @@ TEST_DECLARE (spawn_and_ping)
|
||||
TEST_DECLARE (kill)
|
||||
TEST_DECLARE (fs_file_noent)
|
||||
TEST_DECLARE (fs_file_nametoolong)
|
||||
TEST_DECLARE (fs_file_loop)
|
||||
TEST_DECLARE (fs_file_async)
|
||||
TEST_DECLARE (fs_file_sync)
|
||||
TEST_DECLARE (fs_async_dir)
|
||||
@ -202,6 +204,7 @@ TASK_LIST_START
|
||||
TEST_ENTRY (udp_ipv6_only)
|
||||
TEST_ENTRY (udp_options)
|
||||
TEST_ENTRY (udp_multicast_join)
|
||||
TEST_ENTRY (udp_multicast_ttl)
|
||||
|
||||
TEST_ENTRY (pipe_bind_error_addrinuse)
|
||||
TEST_ENTRY (pipe_bind_error_addrnotavail)
|
||||
@ -290,6 +293,7 @@ TASK_LIST_START
|
||||
|
||||
TEST_ENTRY (fs_file_noent)
|
||||
TEST_ENTRY (fs_file_nametoolong)
|
||||
TEST_ENTRY (fs_file_loop)
|
||||
TEST_ENTRY (fs_file_async)
|
||||
TEST_ENTRY (fs_file_sync)
|
||||
TEST_ENTRY (fs_async_dir)
|
||||
|
||||
@ -138,6 +138,9 @@ static void pinger_on_connect(uv_connect_t *req, int status) {
|
||||
|
||||
ASSERT(status == 0);
|
||||
|
||||
ASSERT(uv_is_readable(req->handle));
|
||||
ASSERT(uv_is_writable(req->handle));
|
||||
|
||||
pinger_write_ping(pinger);
|
||||
|
||||
uv_read_start((uv_stream_t*)(req->handle), alloc_cb, pinger_read_cb);
|
||||
|
||||
89
test/test-udp-multicast-ttl.c
Normal file
89
test/test-udp-multicast-ttl.c
Normal file
@ -0,0 +1,89 @@
|
||||
/* 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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define CHECK_HANDLE(handle) \
|
||||
ASSERT((uv_udp_t*)(handle) == &server || (uv_udp_t*)(handle) == &client)
|
||||
|
||||
static uv_udp_t server;
|
||||
static uv_udp_t client;
|
||||
|
||||
static int cl_recv_cb_called;
|
||||
|
||||
static int sv_send_cb_called;
|
||||
|
||||
static int close_cb_called;
|
||||
|
||||
|
||||
static void close_cb(uv_handle_t* handle) {
|
||||
CHECK_HANDLE(handle);
|
||||
close_cb_called++;
|
||||
}
|
||||
|
||||
|
||||
static void sv_send_cb(uv_udp_send_t* req, int status) {
|
||||
ASSERT(req != NULL);
|
||||
ASSERT(status == 0);
|
||||
CHECK_HANDLE(req->handle);
|
||||
|
||||
sv_send_cb_called++;
|
||||
|
||||
uv_close((uv_handle_t*) req->handle, close_cb);
|
||||
}
|
||||
|
||||
|
||||
TEST_IMPL(udp_multicast_ttl) {
|
||||
int r;
|
||||
uv_udp_send_t req;
|
||||
uv_buf_t buf;
|
||||
struct sockaddr_in addr = uv_ip4_addr("239.255.0.1", TEST_PORT);
|
||||
|
||||
r = uv_udp_init(uv_default_loop(), &server);
|
||||
ASSERT(r == 0);
|
||||
|
||||
r = uv_udp_bind(&server, uv_ip4_addr("0.0.0.0", 0), 0);
|
||||
ASSERT(r == 0);
|
||||
|
||||
r = uv_udp_set_multicast_ttl(&server, 32);
|
||||
ASSERT(r == 0);
|
||||
|
||||
/* server sends "PING" */
|
||||
buf = uv_buf_init("PING", 4);
|
||||
r = uv_udp_send(&req, &server, &buf, 1, addr, sv_send_cb);
|
||||
ASSERT(r == 0);
|
||||
|
||||
ASSERT(close_cb_called == 0);
|
||||
ASSERT(sv_send_cb_called == 0);
|
||||
|
||||
/* run the loop till all events are processed */
|
||||
uv_run(uv_default_loop());
|
||||
|
||||
ASSERT(sv_send_cb_called == 1);
|
||||
ASSERT(close_cb_called == 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user