mirror of https://github.com/lukechilds/node.git
Browse Source
PR-URL: https://github.com/nodejs/node/pull/2310 Reviewed-By: bnoordhuis - Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: cjihrig - Colin Ihrig <cjihrig@gmail.com>v4.0.0-rc
committed by
Rod Vagg
78 changed files with 2772 additions and 651 deletions
@ -0,0 +1,36 @@ |
|||||
|
|
||||
|
# Project Maintainers |
||||
|
|
||||
|
libuv is currently managed by the following individuals: |
||||
|
|
||||
|
* **Ben Noordhuis** ([@bnoordhuis](https://github.com/bnoordhuis)) |
||||
|
- GPG key: D77B 1E34 243F BAF0 5F8E 9CC3 4F55 C8C8 46AB 89B9 (pubkey-bnoordhuis) |
||||
|
* **Bert Belder** ([@piscisaureus](https://github.com/piscisaureus)) |
||||
|
* **Fedor Indutny** ([@indutny](https://github.com/indutny)) |
||||
|
- GPG key: AF2E EA41 EC34 47BF DD86 FED9 D706 3CCE 19B7 E890 (pubkey-indutny) |
||||
|
* **Saúl Ibarra Corretgé** ([@saghul](https://github.com/saghul)) |
||||
|
- GPG key: FDF5 1936 4458 319F A823 3DC9 410E 5553 AE9B C059 (pubkey-saghul) |
||||
|
|
||||
|
## Storing a maintainer key in Git |
||||
|
|
||||
|
It's quite handy to store a maintainer's signature as a git blob, and have |
||||
|
that object tagged and signed with such key. |
||||
|
|
||||
|
Export your public key: |
||||
|
|
||||
|
$ gpg --armor --export saghul@gmail.com > saghul.asc |
||||
|
|
||||
|
Store it as a blob on the repo: |
||||
|
|
||||
|
$ git hash-object -w saghul.asc |
||||
|
|
||||
|
The previous command returns a hash, copy it. For the sake of this explanation, |
||||
|
we'll assume it's 'abcd1234'. Storing the blob in git is not enough, it could |
||||
|
be garbage collected since nothing references it, so we'll create a tag for it: |
||||
|
|
||||
|
$ git tag -s pubkey-saghul abcd1234 |
||||
|
|
||||
|
Commit the changes and push: |
||||
|
|
||||
|
$ git push origin pubkey-saghul |
||||
|
|
@ -0,0 +1,36 @@ |
|||||
|
version: v1.7.3.build{build} |
||||
|
|
||||
|
install: |
||||
|
- cinst -y nsis |
||||
|
|
||||
|
matrix: |
||||
|
fast_finish: true |
||||
|
allow_failures: |
||||
|
- platform: x86 |
||||
|
configuration: Release |
||||
|
- platform: x64 |
||||
|
configuration: Release |
||||
|
|
||||
|
platform: |
||||
|
- x86 |
||||
|
- x64 |
||||
|
|
||||
|
configuration: |
||||
|
- Release |
||||
|
|
||||
|
build_script: |
||||
|
# Fixed tag version number if using a tag. |
||||
|
- cmd: if "%APPVEYOR_REPO_TAG%" == "true" set APPVEYOR_BUILD_VERSION=%APPVEYOR_REPO_TAG_NAME% |
||||
|
# vcbuild overwrites the platform variable. |
||||
|
- cmd: set ARCH=%platform% |
||||
|
- cmd: vcbuild.bat release %ARCH% shared |
||||
|
|
||||
|
after_build: |
||||
|
- '"%PROGRAMFILES(x86)%\NSIS\makensis" /DVERSION=%APPVEYOR_BUILD_VERSION% /DARCH=%ARCH% libuv.nsi' |
||||
|
|
||||
|
artifacts: |
||||
|
- name: Installer |
||||
|
path: 'libuv-*.exe' |
||||
|
|
||||
|
cache: |
||||
|
- C:\projects\libuv\build\gyp |
@ -0,0 +1,60 @@ |
|||||
|
|
||||
|
.. _version: |
||||
|
|
||||
|
Version-checking macros and functions |
||||
|
===================================== |
||||
|
|
||||
|
Starting with version 1.0.0 libuv follows the `semantic versioning`_ |
||||
|
scheme. This means that new APIs can be introduced throughout the lifetime of |
||||
|
a major release. In this section you'll find all macros and functions that |
||||
|
will allow you to write or compile code conditionally, in order to work with |
||||
|
multiple libuv versions. |
||||
|
|
||||
|
.. _semantic versioning: http://semver.org |
||||
|
|
||||
|
|
||||
|
Macros |
||||
|
------ |
||||
|
|
||||
|
.. c:macro:: UV_VERSION_MAJOR |
||||
|
|
||||
|
libuv version's major number. |
||||
|
|
||||
|
.. c:macro:: UV_VERSION_MINOR |
||||
|
|
||||
|
libuv version's minor number. |
||||
|
|
||||
|
.. c:macro:: UV_VERSION_PATCH |
||||
|
|
||||
|
libuv version's patch number. |
||||
|
|
||||
|
.. c:macro:: UV_VERSION_IS_RELEASE |
||||
|
|
||||
|
Set to 1 to indicate a release version of libuv, 0 for a development |
||||
|
snapshot. |
||||
|
|
||||
|
.. c:macro:: UV_VERSION_SUFFIX |
||||
|
|
||||
|
libuv version suffix. Certain development releases such as Release Candidates |
||||
|
might have a suffix such as "rc". |
||||
|
|
||||
|
.. c:macro:: UV_VERSION_HEX |
||||
|
|
||||
|
Returns the libuv version packed into a single integer. 8 bits are used for |
||||
|
each component, with the patch number stored in the 8 least significant |
||||
|
bits. E.g. for libuv 1.2.3 this would be 0x010203. |
||||
|
|
||||
|
.. versionadded:: 1.7.0 |
||||
|
|
||||
|
|
||||
|
Functions |
||||
|
--------- |
||||
|
|
||||
|
.. c:function:: unsigned int uv_version(void) |
||||
|
|
||||
|
Returns :c:macro:`UV_VERSION_HEX`. |
||||
|
|
||||
|
.. c:function:: const char* uv_version_string(void) |
||||
|
|
||||
|
Returns the libuv version number as a string. For non-release versions the |
||||
|
version suffix is included. |
@ -0,0 +1,86 @@ |
|||||
|
; NSIS installer script for libuv |
||||
|
|
||||
|
!include "MUI2.nsh" |
||||
|
|
||||
|
Name "libuv" |
||||
|
OutFile "libuv-${ARCH}-${VERSION}.exe" |
||||
|
|
||||
|
!include "x64.nsh" |
||||
|
# Default install location, for 32-bit files |
||||
|
InstallDir "$PROGRAMFILES\libuv" |
||||
|
|
||||
|
# Override install and registry locations if this is a 64-bit install. |
||||
|
function .onInit |
||||
|
${If} ${ARCH} == "x64" |
||||
|
SetRegView 64 |
||||
|
StrCpy $INSTDIR "$PROGRAMFILES64\libuv" |
||||
|
${EndIf} |
||||
|
functionEnd |
||||
|
|
||||
|
;-------------------------------- |
||||
|
; Installer pages |
||||
|
!insertmacro MUI_PAGE_WELCOME |
||||
|
!insertmacro MUI_PAGE_DIRECTORY |
||||
|
!insertmacro MUI_PAGE_INSTFILES |
||||
|
!insertmacro MUI_PAGE_FINISH |
||||
|
|
||||
|
|
||||
|
;-------------------------------- |
||||
|
; Uninstaller pages |
||||
|
!insertmacro MUI_UNPAGE_WELCOME |
||||
|
!insertmacro MUI_UNPAGE_CONFIRM |
||||
|
!insertmacro MUI_UNPAGE_INSTFILES |
||||
|
!insertmacro MUI_UNPAGE_FINISH |
||||
|
|
||||
|
;-------------------------------- |
||||
|
; Languages |
||||
|
!insertmacro MUI_LANGUAGE "English" |
||||
|
|
||||
|
;-------------------------------- |
||||
|
; Installer sections |
||||
|
|
||||
|
Section "Files" SecInstall |
||||
|
SectionIn RO |
||||
|
SetOutPath "$INSTDIR" |
||||
|
File "Release\*.dll" |
||||
|
File "Release\*.lib" |
||||
|
File "LICENSE" |
||||
|
File "README.md" |
||||
|
|
||||
|
SetOutPath "$INSTDIR\include" |
||||
|
File "include\uv.h" |
||||
|
File "include\uv-errno.h" |
||||
|
File "include\uv-threadpool.h" |
||||
|
File "include\uv-version.h" |
||||
|
File "include\uv-win.h" |
||||
|
File "include\tree.h" |
||||
|
|
||||
|
WriteUninstaller "$INSTDIR\Uninstall.exe" |
||||
|
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\libuv-${ARCH}-${VERSION}" "DisplayName" "libuv-${ARCH}-${VERSION}" |
||||
|
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\libuv-${ARCH}-${VERSION}" "UninstallString" "$\"$INSTDIR\Uninstall.exe$\"" |
||||
|
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\libuv-${ARCH}-${VERSION}" "QuietUninstallString" "$\"$INSTDIR\Uninstall.exe$\" /S" |
||||
|
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\libuv-${ARCH}-${VERSION}" "HelpLink" "http://libuv.org/" |
||||
|
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\libuv-${ARCH}-${VERSION}" "URLInfoAbout" "http://libuv.org/" |
||||
|
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\libuv-${ARCH}-${VERSION}" "DisplayVersion" "${VERSION}" |
||||
|
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\libuv-${ARCH}-${VERSION}" "NoModify" "1" |
||||
|
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\libuv-${ARCH}-${VERSION}" "NoRepair" "1" |
||||
|
SectionEnd |
||||
|
|
||||
|
Section "Uninstall" |
||||
|
Delete "$INSTDIR\libuv.dll" |
||||
|
Delete "$INSTDIR\libuv.lib" |
||||
|
Delete "$INSTDIR\LICENSE" |
||||
|
Delete "$INSTDIR\README.md" |
||||
|
|
||||
|
Delete "$INSTDIR\include\uv.h" |
||||
|
Delete "$INSTDIR\include\uv-errno.h" |
||||
|
Delete "$INSTDIR\include\uv-threadpool.h" |
||||
|
Delete "$INSTDIR\include\uv-version.h" |
||||
|
Delete "$INSTDIR\include\uv-win.h" |
||||
|
Delete "$INSTDIR\include\tree.h" |
||||
|
|
||||
|
Delete "$INSTDIR\Uninstall.exe" |
||||
|
RMDir "$INSTDIR" |
||||
|
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\libuv-${ARCH}-${VERSION}" |
||||
|
SectionEnd |
||||
|
|
File diff suppressed because it is too large
@ -0,0 +1,104 @@ |
|||||
|
/* Copyright (c) 2015 Saúl Ibarra Corretgé <saghul@gmail.com>.
|
||||
|
* 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> |
||||
|
|
||||
|
|
||||
|
static int connection_cb_called = 0; |
||||
|
static int connect_cb_called = 0; |
||||
|
|
||||
|
#define NUM_CLIENTS 4 |
||||
|
|
||||
|
typedef struct { |
||||
|
uv_pipe_t pipe_handle; |
||||
|
uv_connect_t conn_req; |
||||
|
} client_t; |
||||
|
|
||||
|
static uv_pipe_t server_handle; |
||||
|
static client_t clients[NUM_CLIENTS]; |
||||
|
static uv_pipe_t connections[NUM_CLIENTS]; |
||||
|
|
||||
|
|
||||
|
static void connection_cb(uv_stream_t* server, int status) { |
||||
|
int r; |
||||
|
uv_pipe_t* conn; |
||||
|
ASSERT(status == 0); |
||||
|
|
||||
|
conn = &connections[connection_cb_called]; |
||||
|
r = uv_pipe_init(server->loop, conn, 0); |
||||
|
ASSERT(r == 0); |
||||
|
|
||||
|
r = uv_accept(server, (uv_stream_t*)conn); |
||||
|
ASSERT(r == 0); |
||||
|
|
||||
|
if (++connection_cb_called == NUM_CLIENTS && |
||||
|
connect_cb_called == NUM_CLIENTS) { |
||||
|
uv_stop(server->loop); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
static void connect_cb(uv_connect_t* connect_req, int status) { |
||||
|
ASSERT(status == 0); |
||||
|
if (++connect_cb_called == NUM_CLIENTS && |
||||
|
connection_cb_called == NUM_CLIENTS) { |
||||
|
uv_stop(connect_req->handle->loop); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
TEST_IMPL(pipe_connect_multiple) { |
||||
|
int i; |
||||
|
int r; |
||||
|
uv_loop_t* loop; |
||||
|
|
||||
|
loop = uv_default_loop(); |
||||
|
|
||||
|
r = uv_pipe_init(loop, &server_handle, 0); |
||||
|
ASSERT(r == 0); |
||||
|
|
||||
|
r = uv_pipe_bind(&server_handle, TEST_PIPENAME); |
||||
|
ASSERT(r == 0); |
||||
|
|
||||
|
r = uv_listen((uv_stream_t*)&server_handle, 128, connection_cb); |
||||
|
ASSERT(r == 0); |
||||
|
|
||||
|
for (i = 0; i < NUM_CLIENTS; i++) { |
||||
|
r = uv_pipe_init(loop, &clients[i].pipe_handle, 0); |
||||
|
ASSERT(r == 0); |
||||
|
uv_pipe_connect(&clients[i].conn_req, |
||||
|
&clients[i].pipe_handle, |
||||
|
TEST_PIPENAME, |
||||
|
connect_cb); |
||||
|
} |
||||
|
|
||||
|
uv_run(loop, UV_RUN_DEFAULT); |
||||
|
|
||||
|
ASSERT(connection_cb_called == NUM_CLIENTS); |
||||
|
ASSERT(connect_cb_called == NUM_CLIENTS); |
||||
|
|
||||
|
MAKE_VALGRIND_HAPPY(); |
||||
|
return 0; |
||||
|
} |
@ -0,0 +1,59 @@ |
|||||
|
/* Copyright (c) 2015 Saúl Ibarra Corretgé <saghul@gmail.com>.
|
||||
|
* 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" |
||||
|
|
||||
|
|
||||
|
static void connection_cb(uv_stream_t* server, int status) { |
||||
|
ASSERT(0 && "this will never be called"); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
TEST_IMPL(pipe_pending_instances) { |
||||
|
int r; |
||||
|
uv_pipe_t pipe_handle; |
||||
|
uv_loop_t* loop; |
||||
|
|
||||
|
loop = uv_default_loop(); |
||||
|
|
||||
|
r = uv_pipe_init(loop, &pipe_handle, 0); |
||||
|
ASSERT(r == 0); |
||||
|
|
||||
|
uv_pipe_pending_instances(&pipe_handle, 8); |
||||
|
|
||||
|
r = uv_pipe_bind(&pipe_handle, TEST_PIPENAME); |
||||
|
ASSERT(r == 0); |
||||
|
|
||||
|
uv_pipe_pending_instances(&pipe_handle, 16); |
||||
|
|
||||
|
r = uv_listen((uv_stream_t*)&pipe_handle, 128, connection_cb); |
||||
|
ASSERT(r == 0); |
||||
|
|
||||
|
uv_close((uv_handle_t*)&pipe_handle, NULL); |
||||
|
|
||||
|
r = uv_run(loop, UV_RUN_DEFAULT); |
||||
|
ASSERT(r == 0); |
||||
|
|
||||
|
MAKE_VALGRIND_HAPPY(); |
||||
|
return 0; |
||||
|
} |
@ -0,0 +1,206 @@ |
|||||
|
/* Copyright (c) 2015 Saúl Ibarra Corretgé <saghul@gmail.com>.
|
||||
|
* 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> |
||||
|
|
||||
|
#ifdef _WIN32 |
||||
|
# define INVALID_FD (INVALID_HANDLE_VALUE) |
||||
|
#else |
||||
|
# define INVALID_FD (-1) |
||||
|
#endif |
||||
|
|
||||
|
|
||||
|
static void on_connect(uv_connect_t* req, int status) { |
||||
|
ASSERT(status == 0); |
||||
|
uv_close((uv_handle_t*) req->handle, NULL); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
static void on_connection(uv_stream_t* server, int status) { |
||||
|
uv_tcp_t* handle; |
||||
|
int r; |
||||
|
|
||||
|
ASSERT(status == 0); |
||||
|
|
||||
|
handle = malloc(sizeof(*handle)); |
||||
|
ASSERT(handle != NULL); |
||||
|
|
||||
|
r = uv_tcp_init_ex(server->loop, handle, AF_INET); |
||||
|
ASSERT(r == 0); |
||||
|
|
||||
|
r = uv_accept(server, (uv_stream_t*)handle); |
||||
|
ASSERT(r == UV_EBUSY); |
||||
|
|
||||
|
uv_close((uv_handle_t*) server, NULL); |
||||
|
uv_close((uv_handle_t*) handle, (uv_close_cb)free); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
static void tcp_listener(uv_loop_t* loop, uv_tcp_t* server) { |
||||
|
struct sockaddr_in addr; |
||||
|
int r; |
||||
|
|
||||
|
ASSERT(0 == uv_ip4_addr("0.0.0.0", TEST_PORT, &addr)); |
||||
|
|
||||
|
r = uv_tcp_init(loop, server); |
||||
|
ASSERT(r == 0); |
||||
|
|
||||
|
r = uv_tcp_bind(server, (const struct sockaddr*) &addr, 0); |
||||
|
ASSERT(r == 0); |
||||
|
|
||||
|
r = uv_listen((uv_stream_t*) server, 128, on_connection); |
||||
|
ASSERT(r == 0); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
static void tcp_connector(uv_loop_t* loop, uv_tcp_t* client, uv_connect_t* req) { |
||||
|
struct sockaddr_in server_addr; |
||||
|
int r; |
||||
|
|
||||
|
ASSERT(0 == uv_ip4_addr("127.0.0.1", TEST_PORT, &server_addr)); |
||||
|
|
||||
|
r = uv_tcp_init(loop, client); |
||||
|
ASSERT(r == 0); |
||||
|
|
||||
|
r = uv_tcp_connect(req, |
||||
|
client, |
||||
|
(const struct sockaddr*) &server_addr, |
||||
|
on_connect); |
||||
|
ASSERT(r == 0); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
TEST_IMPL(tcp_create_early) { |
||||
|
struct sockaddr_in addr; |
||||
|
struct sockaddr_in sockname; |
||||
|
uv_tcp_t client; |
||||
|
uv_os_fd_t fd; |
||||
|
int r, namelen; |
||||
|
|
||||
|
ASSERT(0 == uv_ip4_addr("127.0.0.1", TEST_PORT, &addr)); |
||||
|
|
||||
|
r = uv_tcp_init_ex(uv_default_loop(), &client, AF_INET); |
||||
|
ASSERT(r == 0); |
||||
|
|
||||
|
r = uv_fileno((const uv_handle_t*) &client, &fd); |
||||
|
ASSERT(r == 0); |
||||
|
ASSERT(fd != INVALID_FD); |
||||
|
|
||||
|
/* Windows returns WSAEINVAL if the socket is not bound */ |
||||
|
#ifndef _WIN32 |
||||
|
namelen = sizeof sockname; |
||||
|
r = uv_tcp_getsockname(&client, (struct sockaddr*) &sockname, &namelen); |
||||
|
ASSERT(r == 0); |
||||
|
ASSERT(sockname.sin_family == AF_INET); |
||||
|
#endif |
||||
|
|
||||
|
r = uv_tcp_bind(&client, (const struct sockaddr*) &addr, 0); |
||||
|
ASSERT(r == 0); |
||||
|
|
||||
|
namelen = sizeof sockname; |
||||
|
r = uv_tcp_getsockname(&client, (struct sockaddr*) &sockname, &namelen); |
||||
|
ASSERT(r == 0); |
||||
|
ASSERT(memcmp(&addr.sin_addr, |
||||
|
&sockname.sin_addr, |
||||
|
sizeof(addr.sin_addr)) == 0); |
||||
|
|
||||
|
uv_close((uv_handle_t*) &client, NULL); |
||||
|
uv_run(uv_default_loop(), UV_RUN_DEFAULT); |
||||
|
|
||||
|
MAKE_VALGRIND_HAPPY(); |
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
TEST_IMPL(tcp_create_early_bad_bind) { |
||||
|
struct sockaddr_in addr; |
||||
|
uv_tcp_t client; |
||||
|
uv_os_fd_t fd; |
||||
|
int r; |
||||
|
|
||||
|
ASSERT(0 == uv_ip4_addr("127.0.0.1", TEST_PORT, &addr)); |
||||
|
|
||||
|
r = uv_tcp_init_ex(uv_default_loop(), &client, AF_INET6); |
||||
|
ASSERT(r == 0); |
||||
|
|
||||
|
r = uv_fileno((const uv_handle_t*) &client, &fd); |
||||
|
ASSERT(r == 0); |
||||
|
ASSERT(fd != INVALID_FD); |
||||
|
|
||||
|
/* Windows returns WSAEINVAL if the socket is not bound */ |
||||
|
#ifndef _WIN32 |
||||
|
{ |
||||
|
int namelen; |
||||
|
struct sockaddr_in6 sockname; |
||||
|
namelen = sizeof sockname; |
||||
|
r = uv_tcp_getsockname(&client, (struct sockaddr*) &sockname, &namelen); |
||||
|
ASSERT(r == 0); |
||||
|
ASSERT(sockname.sin6_family == AF_INET6); |
||||
|
} |
||||
|
#endif |
||||
|
|
||||
|
r = uv_tcp_bind(&client, (const struct sockaddr*) &addr, 0); |
||||
|
#ifndef _WIN32 |
||||
|
ASSERT(r == UV_EINVAL); |
||||
|
#else |
||||
|
ASSERT(r == UV_EFAULT); |
||||
|
#endif |
||||
|
|
||||
|
uv_close((uv_handle_t*) &client, NULL); |
||||
|
uv_run(uv_default_loop(), UV_RUN_DEFAULT); |
||||
|
|
||||
|
MAKE_VALGRIND_HAPPY(); |
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
TEST_IMPL(tcp_create_early_bad_domain) { |
||||
|
uv_tcp_t client; |
||||
|
int r; |
||||
|
|
||||
|
r = uv_tcp_init_ex(uv_default_loop(), &client, 47); |
||||
|
ASSERT(r == UV_EINVAL); |
||||
|
|
||||
|
r = uv_tcp_init_ex(uv_default_loop(), &client, 1024); |
||||
|
ASSERT(r == UV_EINVAL); |
||||
|
|
||||
|
uv_run(uv_default_loop(), UV_RUN_DEFAULT); |
||||
|
|
||||
|
MAKE_VALGRIND_HAPPY(); |
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
TEST_IMPL(tcp_create_early_accept) { |
||||
|
uv_tcp_t client, server; |
||||
|
uv_connect_t connect_req; |
||||
|
|
||||
|
tcp_listener(uv_default_loop(), &server); |
||||
|
tcp_connector(uv_default_loop(), &client, &connect_req); |
||||
|
|
||||
|
uv_run(uv_default_loop(), UV_RUN_DEFAULT); |
||||
|
|
||||
|
MAKE_VALGRIND_HAPPY(); |
||||
|
return 0; |
||||
|
} |
@ -0,0 +1,119 @@ |
|||||
|
/* Copyright (c) 2015, Santiago Gimeno <santiago.gimeno@gmail.com>
|
||||
|
* |
||||
|
* 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> |
||||
|
|
||||
|
|
||||
|
static uv_tcp_t tcp_server; |
||||
|
static uv_tcp_t tcp_client; |
||||
|
static uv_tcp_t tcp_server_client; |
||||
|
static uv_connect_t connect_req; |
||||
|
static uv_write_t write_req; |
||||
|
|
||||
|
static void alloc_cb(uv_handle_t* handle, |
||||
|
size_t size, |
||||
|
uv_buf_t* buf) { |
||||
|
buf->base = malloc(size); |
||||
|
buf->len = size; |
||||
|
} |
||||
|
|
||||
|
static void read_cb(uv_stream_t* tcp, ssize_t nread, const uv_buf_t* buf) { |
||||
|
free(buf->base); |
||||
|
ASSERT(nread == UV_EOF); |
||||
|
} |
||||
|
|
||||
|
static void on_connect(uv_connect_t* req, int status) { |
||||
|
int r; |
||||
|
uv_buf_t outbuf; |
||||
|
|
||||
|
ASSERT(req != NULL); |
||||
|
ASSERT(status == 0); |
||||
|
|
||||
|
outbuf = uv_buf_init("ping", 4); |
||||
|
r = uv_write(&write_req, (uv_stream_t*) req->handle, &outbuf, 1, NULL); |
||||
|
ASSERT(r == 0); |
||||
|
|
||||
|
r = uv_read_start((uv_stream_t*) req->handle, alloc_cb, read_cb); |
||||
|
ASSERT(r == 0); |
||||
|
} |
||||
|
|
||||
|
static void on_connection(uv_stream_t* server, int status) { |
||||
|
int r; |
||||
|
|
||||
|
ASSERT(status == 0); |
||||
|
|
||||
|
r = uv_tcp_init(uv_default_loop(), &tcp_server_client); |
||||
|
ASSERT(r == 0); |
||||
|
|
||||
|
r = uv_accept(server, (uv_stream_t*) &tcp_server_client); |
||||
|
ASSERT(r == 0); |
||||
|
|
||||
|
uv_close((uv_handle_t*) &tcp_server_client, NULL); |
||||
|
uv_close((uv_handle_t*) &tcp_server, NULL); |
||||
|
} |
||||
|
|
||||
|
static void start_server(void) { |
||||
|
struct sockaddr_in addr; |
||||
|
int r; |
||||
|
|
||||
|
ASSERT(0 == uv_ip4_addr("0.0.0.0", TEST_PORT, &addr)); |
||||
|
|
||||
|
r = uv_tcp_init(uv_default_loop(), &tcp_server); |
||||
|
ASSERT(r == 0); |
||||
|
|
||||
|
r = uv_tcp_bind(&tcp_server, (const struct sockaddr*) &addr, 0); |
||||
|
ASSERT(r == 0); |
||||
|
|
||||
|
r = uv_listen((uv_stream_t*) &tcp_server, SOMAXCONN, on_connection); |
||||
|
ASSERT(r == 0); |
||||
|
} |
||||
|
|
||||
|
static void start_client(void) { |
||||
|
struct sockaddr_in addr; |
||||
|
int r; |
||||
|
|
||||
|
ASSERT(0 == uv_ip4_addr("127.0.0.1", TEST_PORT, &addr)); |
||||
|
|
||||
|
r = uv_tcp_init(uv_default_loop(), &tcp_client); |
||||
|
ASSERT(r == 0); |
||||
|
|
||||
|
r = uv_tcp_connect(&connect_req, |
||||
|
&tcp_client, |
||||
|
(const struct sockaddr*) &addr, |
||||
|
on_connect); |
||||
|
ASSERT(r == 0); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
TEST_IMPL(tcp_squelch_connreset) { |
||||
|
|
||||
|
start_server(); |
||||
|
|
||||
|
start_client(); |
||||
|
|
||||
|
uv_run(uv_default_loop(), UV_RUN_DEFAULT); |
||||
|
|
||||
|
MAKE_VALGRIND_HAPPY(); |
||||
|
return 0; |
||||
|
} |
@ -0,0 +1,132 @@ |
|||||
|
/* Copyright (c) 2015 Saúl Ibarra Corretgé <saghul@gmail.com>.
|
||||
|
* 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> |
||||
|
|
||||
|
#ifdef _WIN32 |
||||
|
# define INVALID_FD (INVALID_HANDLE_VALUE) |
||||
|
#else |
||||
|
# define INVALID_FD (-1) |
||||
|
#endif |
||||
|
|
||||
|
|
||||
|
TEST_IMPL(udp_create_early) { |
||||
|
struct sockaddr_in addr; |
||||
|
struct sockaddr_in sockname; |
||||
|
uv_udp_t client; |
||||
|
uv_os_fd_t fd; |
||||
|
int r, namelen; |
||||
|
|
||||
|
ASSERT(0 == uv_ip4_addr("127.0.0.1", TEST_PORT, &addr)); |
||||
|
|
||||
|
r = uv_udp_init_ex(uv_default_loop(), &client, AF_INET); |
||||
|
ASSERT(r == 0); |
||||
|
|
||||
|
r = uv_fileno((const uv_handle_t*) &client, &fd); |
||||
|
ASSERT(r == 0); |
||||
|
ASSERT(fd != INVALID_FD); |
||||
|
|
||||
|
/* Windows returns WSAEINVAL if the socket is not bound */ |
||||
|
#ifndef _WIN32 |
||||
|
namelen = sizeof sockname; |
||||
|
r = uv_udp_getsockname(&client, (struct sockaddr*) &sockname, &namelen); |
||||
|
ASSERT(r == 0); |
||||
|
ASSERT(sockname.sin_family == AF_INET); |
||||
|
#endif |
||||
|
|
||||
|
r = uv_udp_bind(&client, (const struct sockaddr*) &addr, 0); |
||||
|
ASSERT(r == 0); |
||||
|
|
||||
|
namelen = sizeof sockname; |
||||
|
r = uv_udp_getsockname(&client, (struct sockaddr*) &sockname, &namelen); |
||||
|
ASSERT(r == 0); |
||||
|
ASSERT(memcmp(&addr.sin_addr, |
||||
|
&sockname.sin_addr, |
||||
|
sizeof(addr.sin_addr)) == 0); |
||||
|
|
||||
|
uv_close((uv_handle_t*) &client, NULL); |
||||
|
uv_run(uv_default_loop(), UV_RUN_DEFAULT); |
||||
|
|
||||
|
MAKE_VALGRIND_HAPPY(); |
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
TEST_IMPL(udp_create_early_bad_bind) { |
||||
|
struct sockaddr_in addr; |
||||
|
uv_udp_t client; |
||||
|
uv_os_fd_t fd; |
||||
|
int r; |
||||
|
|
||||
|
ASSERT(0 == uv_ip4_addr("127.0.0.1", TEST_PORT, &addr)); |
||||
|
|
||||
|
r = uv_udp_init_ex(uv_default_loop(), &client, AF_INET6); |
||||
|
ASSERT(r == 0); |
||||
|
|
||||
|
r = uv_fileno((const uv_handle_t*) &client, &fd); |
||||
|
ASSERT(r == 0); |
||||
|
ASSERT(fd != INVALID_FD); |
||||
|
|
||||
|
/* Windows returns WSAEINVAL if the socket is not bound */ |
||||
|
#ifndef _WIN32 |
||||
|
{ |
||||
|
int namelen; |
||||
|
struct sockaddr_in6 sockname; |
||||
|
namelen = sizeof sockname; |
||||
|
r = uv_udp_getsockname(&client, (struct sockaddr*) &sockname, &namelen); |
||||
|
ASSERT(r == 0); |
||||
|
ASSERT(sockname.sin6_family == AF_INET6); |
||||
|
} |
||||
|
#endif |
||||
|
|
||||
|
r = uv_udp_bind(&client, (const struct sockaddr*) &addr, 0); |
||||
|
#ifndef _WIN32 |
||||
|
ASSERT(r == UV_EINVAL); |
||||
|
#else |
||||
|
ASSERT(r == UV_EFAULT); |
||||
|
#endif |
||||
|
|
||||
|
uv_close((uv_handle_t*) &client, NULL); |
||||
|
uv_run(uv_default_loop(), UV_RUN_DEFAULT); |
||||
|
|
||||
|
MAKE_VALGRIND_HAPPY(); |
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
TEST_IMPL(udp_create_early_bad_domain) { |
||||
|
uv_udp_t client; |
||||
|
int r; |
||||
|
|
||||
|
r = uv_udp_init_ex(uv_default_loop(), &client, 47); |
||||
|
ASSERT(r == UV_EINVAL); |
||||
|
|
||||
|
r = uv_udp_init_ex(uv_default_loop(), &client, 1024); |
||||
|
ASSERT(r == UV_EINVAL); |
||||
|
|
||||
|
uv_run(uv_default_loop(), UV_RUN_DEFAULT); |
||||
|
|
||||
|
MAKE_VALGRIND_HAPPY(); |
||||
|
return 0; |
||||
|
} |
Loading…
Reference in new issue