mirror of https://github.com/lukechilds/node.git
Ryan Dahl
14 years ago
30 changed files with 1107 additions and 608 deletions
@ -0,0 +1,155 @@ |
|||||
|
/* 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 <assert.h> |
||||
|
|
||||
|
#include "uv.h" |
||||
|
#include "../uv-common.h" |
||||
|
#include "internal.h" |
||||
|
|
||||
|
|
||||
|
/* Winsock extension functions (ipv4) */ |
||||
|
LPFN_CONNECTEX pConnectEx; |
||||
|
LPFN_ACCEPTEX pAcceptEx; |
||||
|
LPFN_GETACCEPTEXSOCKADDRS pGetAcceptExSockAddrs; |
||||
|
LPFN_DISCONNECTEX pDisconnectEx; |
||||
|
LPFN_TRANSMITFILE pTransmitFile; |
||||
|
|
||||
|
/* Winsock extension functions (ipv6) */ |
||||
|
LPFN_CONNECTEX pConnectEx6; |
||||
|
LPFN_ACCEPTEX pAcceptEx6; |
||||
|
LPFN_GETACCEPTEXSOCKADDRS pGetAcceptExSockAddrs6; |
||||
|
LPFN_DISCONNECTEX pDisconnectEx6; |
||||
|
LPFN_TRANSMITFILE pTransmitFile6; |
||||
|
|
||||
|
/* Whether ipv6 is supported */ |
||||
|
int uv_allow_ipv6; |
||||
|
|
||||
|
/* Ip address used to bind to any port at any interface */ |
||||
|
struct sockaddr_in uv_addr_ip4_any_; |
||||
|
struct sockaddr_in6 uv_addr_ip6_any_; |
||||
|
|
||||
|
|
||||
|
/*
|
||||
|
* Retrieves the pointer to a winsock extension function. |
||||
|
*/ |
||||
|
static BOOL uv_get_extension_function(SOCKET socket, GUID guid, |
||||
|
void **target) { |
||||
|
DWORD result, bytes; |
||||
|
|
||||
|
result = WSAIoctl(socket, |
||||
|
SIO_GET_EXTENSION_FUNCTION_POINTER, |
||||
|
&guid, |
||||
|
sizeof(guid), |
||||
|
(void*)target, |
||||
|
sizeof(*target), |
||||
|
&bytes, |
||||
|
NULL, |
||||
|
NULL); |
||||
|
|
||||
|
if (result == SOCKET_ERROR) { |
||||
|
*target = NULL; |
||||
|
return FALSE; |
||||
|
} else { |
||||
|
return TRUE; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void uv_winsock_init() { |
||||
|
const GUID wsaid_connectex = WSAID_CONNECTEX; |
||||
|
const GUID wsaid_acceptex = WSAID_ACCEPTEX; |
||||
|
const GUID wsaid_getacceptexsockaddrs = WSAID_GETACCEPTEXSOCKADDRS; |
||||
|
const GUID wsaid_disconnectex = WSAID_DISCONNECTEX; |
||||
|
const GUID wsaid_transmitfile = WSAID_TRANSMITFILE; |
||||
|
|
||||
|
WSADATA wsa_data; |
||||
|
int errorno; |
||||
|
SOCKET dummy; |
||||
|
SOCKET dummy6; |
||||
|
|
||||
|
/* Initialize winsock */ |
||||
|
errorno = WSAStartup(MAKEWORD(2, 2), &wsa_data); |
||||
|
if (errorno != 0) { |
||||
|
uv_fatal_error(errorno, "WSAStartup"); |
||||
|
} |
||||
|
|
||||
|
/* Set implicit binding address used by connectEx */ |
||||
|
uv_addr_ip4_any_ = uv_ip4_addr("0.0.0.0", 0); |
||||
|
uv_addr_ip6_any_ = uv_ip6_addr("::", 0); |
||||
|
|
||||
|
/* Retrieve the needed winsock extension function pointers. */ |
||||
|
dummy = socket(AF_INET, SOCK_STREAM, IPPROTO_IP); |
||||
|
if (dummy == INVALID_SOCKET) { |
||||
|
uv_fatal_error(WSAGetLastError(), "socket"); |
||||
|
} |
||||
|
|
||||
|
if (!uv_get_extension_function(dummy, |
||||
|
wsaid_connectex, |
||||
|
(void**)&pConnectEx) || |
||||
|
!uv_get_extension_function(dummy, |
||||
|
wsaid_acceptex, |
||||
|
(void**)&pAcceptEx) || |
||||
|
!uv_get_extension_function(dummy, |
||||
|
wsaid_getacceptexsockaddrs, |
||||
|
(void**)&pGetAcceptExSockAddrs) || |
||||
|
!uv_get_extension_function(dummy, |
||||
|
wsaid_disconnectex, |
||||
|
(void**)&pDisconnectEx) || |
||||
|
!uv_get_extension_function(dummy, |
||||
|
wsaid_transmitfile, |
||||
|
(void**)&pTransmitFile)) { |
||||
|
uv_fatal_error(WSAGetLastError(), |
||||
|
"WSAIoctl(SIO_GET_EXTENSION_FUNCTION_POINTER)"); |
||||
|
} |
||||
|
|
||||
|
if (closesocket(dummy) == SOCKET_ERROR) { |
||||
|
uv_fatal_error(WSAGetLastError(), "closesocket"); |
||||
|
} |
||||
|
|
||||
|
/* optional IPv6 versions of winsock extension functions */ |
||||
|
dummy6 = socket(AF_INET6, SOCK_STREAM, IPPROTO_IP); |
||||
|
if (dummy6 != INVALID_SOCKET) { |
||||
|
uv_allow_ipv6 = TRUE; |
||||
|
|
||||
|
if (!uv_get_extension_function(dummy6, |
||||
|
wsaid_connectex, |
||||
|
(void**)&pConnectEx6) || |
||||
|
!uv_get_extension_function(dummy6, |
||||
|
wsaid_acceptex, |
||||
|
(void**)&pAcceptEx6) || |
||||
|
!uv_get_extension_function(dummy6, |
||||
|
wsaid_getacceptexsockaddrs, |
||||
|
(void**)&pGetAcceptExSockAddrs6) || |
||||
|
!uv_get_extension_function(dummy6, |
||||
|
wsaid_disconnectex, |
||||
|
(void**)&pDisconnectEx6) || |
||||
|
!uv_get_extension_function(dummy6, |
||||
|
wsaid_transmitfile, |
||||
|
(void**)&pTransmitFile6)) { |
||||
|
uv_allow_ipv6 = FALSE; |
||||
|
} |
||||
|
|
||||
|
if (closesocket(dummy6) == SOCKET_ERROR) { |
||||
|
uv_fatal_error(WSAGetLastError(), "closesocket"); |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,130 @@ |
|||||
|
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
||||
|
* |
||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
|
* of this software and associated documentation files (the "Software"), to |
||||
|
* deal in the Software without restriction, including without limitation the |
||||
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
||||
|
* sell copies of the Software, and to permit persons to whom the Software is |
||||
|
* furnished to do so, subject to the following conditions: |
||||
|
* |
||||
|
* The above copyright notice and this permission notice shall be included in |
||||
|
* all copies or substantial portions of the Software. |
||||
|
* |
||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
||||
|
* IN THE SOFTWARE. |
||||
|
*/ |
||||
|
|
||||
|
#ifndef UV_WIN_WINSOCK_H_ |
||||
|
#define UV_WIN_WINSOCK_H_ |
||||
|
|
||||
|
#include <winsock2.h> |
||||
|
#include <mswsock.h> |
||||
|
#include <ws2tcpip.h> |
||||
|
#include <windows.h> |
||||
|
|
||||
|
|
||||
|
/*
|
||||
|
* Guids and typedefs for winsock extension functions |
||||
|
* Mingw32 doesn't have these :-( |
||||
|
*/ |
||||
|
#ifndef WSAID_ACCEPTEX |
||||
|
# define WSAID_ACCEPTEX \ |
||||
|
{0xb5367df1, 0xcbac, 0x11cf, \ |
||||
|
{0x95, 0xca, 0x00, 0x80, 0x5f, 0x48, 0xa1, 0x92}} |
||||
|
|
||||
|
# define WSAID_CONNECTEX \ |
||||
|
{0x25a207b9, 0xddf3, 0x4660, \ |
||||
|
{0x8e, 0xe9, 0x76, 0xe5, 0x8c, 0x74, 0x06, 0x3e}} |
||||
|
|
||||
|
# define WSAID_GETACCEPTEXSOCKADDRS \ |
||||
|
{0xb5367df2, 0xcbac, 0x11cf, \ |
||||
|
{0x95, 0xca, 0x00, 0x80, 0x5f, 0x48, 0xa1, 0x92}} |
||||
|
|
||||
|
# define WSAID_DISCONNECTEX \ |
||||
|
{0x7fda2e11, 0x8630, 0x436f, \ |
||||
|
{0xa0, 0x31, 0xf5, 0x36, 0xa6, 0xee, 0xc1, 0x57}} |
||||
|
|
||||
|
# define WSAID_TRANSMITFILE \ |
||||
|
{0xb5367df0, 0xcbac, 0x11cf, \ |
||||
|
{0x95, 0xca, 0x00, 0x80, 0x5f, 0x48, 0xa1, 0x92}} |
||||
|
|
||||
|
typedef BOOL PASCAL (*LPFN_ACCEPTEX) |
||||
|
(SOCKET sListenSocket, |
||||
|
SOCKET sAcceptSocket, |
||||
|
PVOID lpOutputBuffer, |
||||
|
DWORD dwReceiveDataLength, |
||||
|
DWORD dwLocalAddressLength, |
||||
|
DWORD dwRemoteAddressLength, |
||||
|
LPDWORD lpdwBytesReceived, |
||||
|
LPOVERLAPPED lpOverlapped); |
||||
|
|
||||
|
typedef BOOL PASCAL (*LPFN_CONNECTEX) |
||||
|
(SOCKET s, |
||||
|
const struct sockaddr* name, |
||||
|
int namelen, |
||||
|
PVOID lpSendBuffer, |
||||
|
DWORD dwSendDataLength, |
||||
|
LPDWORD lpdwBytesSent, |
||||
|
LPOVERLAPPED lpOverlapped); |
||||
|
|
||||
|
typedef void PASCAL (*LPFN_GETACCEPTEXSOCKADDRS) |
||||
|
(PVOID lpOutputBuffer, |
||||
|
DWORD dwReceiveDataLength, |
||||
|
DWORD dwLocalAddressLength, |
||||
|
DWORD dwRemoteAddressLength, |
||||
|
LPSOCKADDR* LocalSockaddr, |
||||
|
LPINT LocalSockaddrLength, |
||||
|
LPSOCKADDR* RemoteSockaddr, |
||||
|
LPINT RemoteSockaddrLength); |
||||
|
|
||||
|
typedef BOOL PASCAL (*LPFN_DISCONNECTEX) |
||||
|
(SOCKET hSocket, |
||||
|
LPOVERLAPPED lpOverlapped, |
||||
|
DWORD dwFlags, |
||||
|
DWORD reserved); |
||||
|
|
||||
|
typedef BOOL PASCAL (*LPFN_TRANSMITFILE) |
||||
|
(SOCKET hSocket, |
||||
|
HANDLE hFile, |
||||
|
DWORD nNumberOfBytesToWrite, |
||||
|
DWORD nNumberOfBytesPerSend, |
||||
|
LPOVERLAPPED lpOverlapped, |
||||
|
LPTRANSMIT_FILE_BUFFERS lpTransmitBuffers, |
||||
|
DWORD dwFlags); |
||||
|
#endif |
||||
|
|
||||
|
/*
|
||||
|
* MinGW is missing this too |
||||
|
*/ |
||||
|
#ifndef SO_UPDATE_CONNECT_CONTEXT |
||||
|
# define SO_UPDATE_CONNECT_CONTEXT 0x7010 |
||||
|
#endif |
||||
|
|
||||
|
|
||||
|
/* Winsock extension functions (ipv4) */ |
||||
|
extern LPFN_CONNECTEX pConnectEx; |
||||
|
extern LPFN_ACCEPTEX pAcceptEx; |
||||
|
extern LPFN_GETACCEPTEXSOCKADDRS pGetAcceptExSockAddrs; |
||||
|
extern LPFN_DISCONNECTEX pDisconnectEx; |
||||
|
extern LPFN_TRANSMITFILE pTransmitFile; |
||||
|
|
||||
|
/* Winsock extension functions (ipv6) */ |
||||
|
extern LPFN_CONNECTEX pConnectEx6; |
||||
|
extern LPFN_ACCEPTEX pAcceptEx6; |
||||
|
extern LPFN_GETACCEPTEXSOCKADDRS pGetAcceptExSockAddrs6; |
||||
|
extern LPFN_DISCONNECTEX pDisconnectEx6; |
||||
|
extern LPFN_TRANSMITFILE pTransmitFile6; |
||||
|
|
||||
|
/* Whether ipv6 is supported */ |
||||
|
extern int uv_allow_ipv6; |
||||
|
|
||||
|
/* Ip address used to bind to any port at any interface */ |
||||
|
extern struct sockaddr_in uv_addr_ip4_any_; |
||||
|
extern struct sockaddr_in6 uv_addr_ip6_any_; |
||||
|
|
||||
|
#endif /* UV_WIN_WINSOCK_H_ */ |
@ -0,0 +1,76 @@ |
|||||
|
@echo off |
||||
|
|
||||
|
cd %~dp0 |
||||
|
|
||||
|
if /i "%1"=="help" goto help |
||||
|
if /i "%1"=="--help" goto help |
||||
|
if /i "%1"=="-help" goto help |
||||
|
if /i "%1"=="/help" goto help |
||||
|
if /i "%1"=="?" goto help |
||||
|
if /i "%1"=="-?" goto help |
||||
|
if /i "%1"=="--?" goto help |
||||
|
if /i "%1"=="/?" goto help |
||||
|
|
||||
|
@rem Bail out early if not running in VS build env. |
||||
|
if not defined VCINSTALLDIR goto msbuild-not-found |
||||
|
|
||||
|
@rem Process arguments. |
||||
|
set config=Debug |
||||
|
set target=Build |
||||
|
set noprojgen= |
||||
|
set run= |
||||
|
|
||||
|
:next-arg |
||||
|
if "%1"=="" goto args-done |
||||
|
if /i "%1"=="debug" set config=Debug&goto arg-ok |
||||
|
if /i "%1"=="release" set config=Release&goto arg-ok |
||||
|
if /i "%1"=="test" set run=run-tests.exe&goto arg-ok |
||||
|
if /i "%1"=="bench" set run=run-benchmarks.exe&goto arg-ok |
||||
|
if /i "%1"=="clean" set target=Clean&goto arg-ok |
||||
|
if /i "%1"=="noprojgen" set noprojgen=1&goto arg-ok |
||||
|
:arg-ok |
||||
|
shift |
||||
|
goto next-arg |
||||
|
:args-done |
||||
|
|
||||
|
|
||||
|
@rem Skip project generation if requested. |
||||
|
if defined noprojgen goto msbuild |
||||
|
|
||||
|
:project-gen |
||||
|
@rem Generate the VS project. |
||||
|
call create-msvs-files.bat |
||||
|
if errorlevel 1 goto create-msvs-files-failed |
||||
|
if not exist uv.sln goto create-msvs-files-failed |
||||
|
|
||||
|
:msbuild |
||||
|
@rem Build the sln with msbuild. |
||||
|
msbuild uv.sln /t:%target% /p:Configuration=%config% /clp:NoSummary;NoItemAndPropertyList;Verbosity=minimal /nologo |
||||
|
if errorlevel 1 goto exit |
||||
|
|
||||
|
:run |
||||
|
@rem Run tests if requested. |
||||
|
if "%run%"=="" goto exit |
||||
|
if not exist %config%\%run% goto exit |
||||
|
%config%\%run% |
||||
|
goto exit |
||||
|
|
||||
|
:create-msvs-files-failed |
||||
|
echo Failed to create vc project files. |
||||
|
goto exit |
||||
|
|
||||
|
:msbuild-not-found |
||||
|
echo Failed to build. In order to build the solution this file needs |
||||
|
echo to run from VS command script. |
||||
|
goto exit |
||||
|
|
||||
|
:help |
||||
|
echo This script must run from VS command prompt. |
||||
|
echo vcbuild.bat [debug/release] [test/bench] [clean] [noprojgen] |
||||
|
echo Examples: |
||||
|
echo vcbuild.bat : builds debug build |
||||
|
echo vcbuild.bat test : builds debug build and runs tests |
||||
|
echo vcbuild.bat release bench: builds release build and runs benchmarks |
||||
|
goto exit |
||||
|
|
||||
|
:exit |
Loading…
Reference in new issue