Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

win support #329

Merged
merged 44 commits into from
Oct 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
be16bb5
build for win
haiyangwu Aug 26, 2019
e9ee7c3
code style
haiyangwu Aug 26, 2019
27c1307
code style
haiyangwu Aug 26, 2019
f2b060e
scripts
haiyangwu Aug 26, 2019
8de983a
replace duplex pipe with two pipe
haiyangwu Aug 29, 2019
3e57e56
code style
haiyangwu Aug 29, 2019
12b6a3c
add explicit key word
haiyangwu Aug 30, 2019
283351a
move getopt to deps
haiyangwu Aug 30, 2019
9cd71b3
Merge remote-tracking branch 'versatica/v3' into v3. Fix typo
haiyangwu Aug 30, 2019
a15863c
single quotes
haiyangwu Aug 30, 2019
b86a32f
pyc explicit path
haiyangwu Aug 30, 2019
9a66008
delete unused dep
haiyangwu Aug 30, 2019
c20fb5b
log text & code style
haiyangwu Aug 30, 2019
850761f
rename SocketRole to role
haiyangwu Aug 30, 2019
6a1a927
log text & code style
haiyangwu Aug 30, 2019
af693c4
replace _MSC_VER with _WIN32 for better compatibility
haiyangwu Aug 30, 2019
d3f3a4c
add public keyword to separate method and var
haiyangwu Aug 30, 2019
cbc1b1d
Generate sln under worker directory for unifying test:woker logic
haiyangwu Aug 30, 2019
e489d3b
add "getopt" entry in worker/scripts/get-dep.sh
haiyangwu Sep 1, 2019
793900d
code style
haiyangwu Sep 1, 2019
3585288
add comment for skipping test case in win32
haiyangwu Sep 1, 2019
14a38ba
move gulp-clang-format into devDep
haiyangwu Sep 1, 2019
cac00ed
unify name
haiyangwu Sep 1, 2019
3dbf56d
change for lint
haiyangwu Sep 2, 2019
4f10db0
use run-script-os instead of gulp
haiyangwu Sep 2, 2019
174c1dd
use @dr.amaton/run-script-os instead of a git repo
haiyangwu Sep 3, 2019
7b20534
win tasks
haiyangwu Sep 5, 2019
e70535c
remove useless tasks
haiyangwu Sep 7, 2019
a4bed7d
run mediasoup-worker-test
haiyangwu Sep 7, 2019
e566abe
add win-tasks.js to lint
haiyangwu Sep 7, 2019
cda5e7e
code style
haiyangwu Sep 11, 2019
6885c44
code style and readability
haiyangwu Sep 11, 2019
b6775ab
code style
haiyangwu Sep 11, 2019
faa375f
code style
haiyangwu Sep 11, 2019
6578c6b
remove duplicated LF
haiyangwu Sep 11, 2019
6fbcc2a
wrap consumer socket and producer socket
haiyangwu Sep 11, 2019
d0a9005
gitignore
haiyangwu Sep 12, 2019
36e2b4c
code style
haiyangwu Sep 12, 2019
bbdae70
add virtual destructor
haiyangwu Sep 12, 2019
3dddc43
Merge remote-tracking branch 'versatica/devel' into v3
haiyangwu Oct 3, 2019
7ac3a99
add defines for abseil
haiyangwu Oct 3, 2019
461e7a5
include
haiyangwu Oct 3, 2019
96a62bd
Merge remote-tracking branch 'versatica/devel' into v3
haiyangwu Oct 5, 2019
62aeb29
dot at the end of the comment
haiyangwu Oct 6, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
# gyp generated stuff.
/worker/out/
/worker/**/*.xcodeproj/
/worker/**/*.sln
/worker/**/*.vcxproj
/worker/**/*.vcxproj.filters
/worker/**/*.vcxproj.user

# clang-fuzzer stuff is too big.
/worker/deps/clang-fuzzer
Expand All @@ -22,3 +26,14 @@

# Mac Stuff.
.DS_Store

# Python generated stuff in Windows.
/worker/scripts/configure.pyc

# Vistual Studio generated Stuff.
/worker/**/Debug/
/worker/**/Release/
/worker/.vs/

# Vistual Studio Code stuff.
/.vscode/
30 changes: 20 additions & 10 deletions lib/Channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Channel extends EnhancedEventEmitter
/**
* @private
*/
constructor({ socket, pid })
constructor({ producerSocket, consumerSocket, pid })
{
const logger = new Logger(`Channel[pid:${pid}]`);
const workerLogger = new Logger(`worker[pid:${pid}]`);
Expand All @@ -30,7 +30,8 @@ class Channel extends EnhancedEventEmitter

// Unix Socket instance.
// @type {net.Socket}
this._socket = socket;
this._producerSocket = producerSocket;
this._consumerSocket = consumerSocket;

// Next request id.
// @type {Number}
Expand All @@ -45,7 +46,7 @@ class Channel extends EnhancedEventEmitter
this._recvBuffer = null;

// Read Channel responses/notifications from the worker.
this._socket.on('data', (buffer) =>
this._consumerSocket.on('data', (buffer) =>
{
if (!this._recvBuffer)
{
Expand Down Expand Up @@ -147,8 +148,11 @@ class Channel extends EnhancedEventEmitter
}
});

this._socket.on('end', () => this._logger.debug('Channel ended by the worker process'));
this._socket.on('error', (error) => this._logger.error('Channel error: %s', String(error)));
this._consumerSocket.on('end', () => this._logger.debug('Consumer Channel ended by the worker process'));
this._consumerSocket.on('error', (error) => this._logger.error('Consumer Channel error: %s', String(error)));

this._producerSocket.on('end', () => this._logger.debug('Producer Channel ended by the worker process'));
this._producerSocket.on('error', (error) => this._logger.error('Producer Channel error: %s', String(error)));
}

/**
Expand All @@ -171,14 +175,20 @@ class Channel extends EnhancedEventEmitter

// Remove event listeners but leave a fake 'error' hander to avoid
// propagation.
this._socket.removeAllListeners('end');
this._socket.removeAllListeners('error');
this._socket.on('error', () => {});
this._consumerSocket.removeAllListeners('end');
this._consumerSocket.removeAllListeners('error');
this._consumerSocket.on('error', () => {});

this._producerSocket.removeAllListeners('end');
this._producerSocket.removeAllListeners('error');
this._producerSocket.on('error', () => {});

// Destroy the socket after a while to allow pending incoming messages.
setTimeout(() =>
{
try { this._socket.destroy(); }
try { this._producerSocket.destroy(); }
catch (error) {}
try { this._consumerSocket.destroy(); }
catch (error) {}
}, 200);
}
Expand Down Expand Up @@ -206,7 +216,7 @@ class Channel extends EnhancedEventEmitter
throw new Error('Channel request too big');

// This may throw if closed or remote side ended.
this._socket.write(ns);
this._producerSocket.write(ns);

return new Promise((pResolve, pReject) =>
{
Expand Down
10 changes: 6 additions & 4 deletions lib/Worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,10 @@ class Worker extends EnhancedEventEmitter
* fd 0 (stdin) : Just ignore it.
* fd 1 (stdout) : Pipe it for 3rd libraries that log their own stuff.
* fd 2 (stderr) : Same as stdout.
* fd 3 (channel) : Channel fd.
* fd 3 (channel) : Producer Channel fd.
* fd 4 (channel) : Consumer Channel fd.
*/
stdio : [ 'ignore', 'pipe', 'pipe', 'pipe' ]
stdio : [ 'ignore', 'pipe', 'pipe', 'pipe', 'pipe' ]
});

this._workerLogger = new Logger(`worker[pid:${this._child.pid}]`);
Expand All @@ -105,8 +106,9 @@ class Worker extends EnhancedEventEmitter
// @type {Channel}
this._channel = new Channel(
{
socket : this._child.stdio[3],
pid : this._pid
producerSocket : this._child.stdio[3],
consumerSocket : this._child.stdio[4],
pid : this._pid
});

// Closed flag.
Expand Down
26 changes: 16 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,27 @@
"sfu",
"nodejs"
],
"os": [
"!win32"
],
"engines": {
"node": ">=8.6.0"
},
"scripts": {
"lint": "npm run lint:node && npm run lint:worker",
"lint:node": "eslint -c .eslintrc.js gulpfile.js lib test",
"lint:worker": "make lint -C worker",
"format:worker": "make format -C worker",
"lint:node": "eslint -c .eslintrc.js gulpfile.js lib test worker/win-tasks.js",
"lint:worker": "run-script-os",
"lint:worker:win32": "\"\"%NODE%\"\" ./worker/win-tasks.js lint",
"lint:worker:default": "make lint -C worker",
"format:worker": "run-script-os",
"format:worker:win32": "\"\"%NODE%\"\" ./worker/win-tasks.js format",
"format:worker:default": "make format -C worker",
"test": "npm run test:node && npm run test:worker",
"test:node": "make -C worker && jest",
"test:worker": "make test -C worker",
"coverage:node": "make -C worker && jest --coverage && open-cli coverage/lcov-report/index.html",
"postinstall": "make -C worker"
"test:node": "npm run postinstall && jest",
ibc marked this conversation as resolved.
Show resolved Hide resolved
"test:worker": "run-script-os",
"test:worker:win32": "\"\"%NODE%\"\" ./worker/win-tasks.js test",
"test:worker:default": "make test -C worker",
"coverage:node": "npm run postinstall && jest --coverage && open-cli coverage/lcov-report/index.html",
"postinstall": "run-script-os",
"postinstall:win32": "\"\"%NODE%\"\" ./worker/win-tasks.js make",
"postinstall:default": "make -C worker"
},
"jest": {
"verbose": true,
Expand All @@ -46,6 +51,7 @@
"h264-profile-level-id": "^1.0.0",
"netstring": "^0.3.0",
"random-number": "^0.0.9",
"@dr.amaton/run-script-os": "^1.1.2",
"uuid": "^3.3.3"
},
"devDependencies": {
Expand Down
6 changes: 6 additions & 0 deletions test/test-Worker.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const os = require('os');
const process = require('process');
const { toBeType } = require('jest-tobetype');
const mediasoup = require('../');
Expand Down Expand Up @@ -194,6 +195,11 @@ test('Worker emits "died" if worker process died unexpectedly', async () =>

test('worker process ignores PIPE, HUP, ALRM, USR1 and USR2 signals', async () =>
{
// Windows doesn't have some signals such as SIGPIPE, SIGALRM, SIGUSR1, SIGUSR2
// so we just skip this test in Windows.
if (os.platform() === 'win32')
ibc marked this conversation as resolved.
Show resolved Hide resolved
haiyangwu marked this conversation as resolved.
Show resolved Hide resolved
return;

worker = await createWorker({ logLevel: 'warn' });

await new Promise((resolve, reject) =>
Expand Down
22 changes: 22 additions & 0 deletions worker/deps/getopt/getopt.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
'targets':
[
{
'target_name': 'getopt',
'type': 'static_library',
'sources':
[
'getopt/src/getopt.h',
'getopt/src/getopt.c'
],
'include_dirs':
[
'getopt/src/'
],
'direct_dependent_settings':
{
'include_dirs': ['getopt/src/']
},
}
]
}
8 changes: 8 additions & 0 deletions worker/deps/getopt/getopt/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CMakeCache.txt
CMakeFiles
Makefile
cmake_install.cmake
install_manifest.txt
build
*.lib
*.pdb
23 changes: 23 additions & 0 deletions worker/deps/getopt/getopt/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
PROJECT(wingetopt)
cmake_minimum_required(VERSION 2.8)

option(BUILD_SHARED_LIBS "Build the shared library" OFF)

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)

add_definitions(-D_CRT_SECURE_NO_WARNINGS)

if(BUILD_SHARED_LIBS)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
add_definitions(-DBUILDING_WINGETOPT_DLL -DWINGETOPT_SHARED_LIB)
endif()

add_library(wingetopt src/getopt.c src/getopt.h)

install(FILES src/getopt.h DESTINATION include)

install(TARGETS wingetopt
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)

54 changes: 54 additions & 0 deletions worker/deps/getopt/getopt/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#### AUTHORS:

* Todd C. Miller <[email protected]>
* The NetBSD Foundation, Inc.
* Alexei Kasatkin is the author of trivial CMakeLists.txt, build script itself is Public Domain

#### LICENSE

Copyright (c) 2002 Todd C. Miller <[email protected]>

Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

Sponsored in part by the Defense Advanced Research Projects
Agency (DARPA) and Air Force Research Laboratory, Air Force
Materiel Command, USAF, under agreement number F39502-99-1-0512.

***

Copyright (c) 2000 The NetBSD Foundation, Inc.
All rights reserved.

This code is derived from software contributed to The NetBSD Foundation
by Dieter Baron and Thomas Klausner.

Redistribution and use in source and binary forms, with or without
modification, 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
63 changes: 63 additions & 0 deletions worker/deps/getopt/getopt/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# wingetopt

getopt library for Windows compilers


This library was created to allow compilation linux-based software on Windows.
http://en.wikipedia.org/wiki/Getopt

The sources were taken from MinGW-runtime project.

#### AUTHORS:

* Todd C. Miller <[email protected]>
* The NetBSD Foundation, Inc.

#### LICENSE

Copyright (c) 2002 Todd C. Miller <[email protected]>

Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

Sponsored in part by the Defense Advanced Research Projects
Agency (DARPA) and Air Force Research Laboratory, Air Force
Materiel Command, USAF, under agreement number F39502-99-1-0512.

***

Copyright (c) 2000 The NetBSD Foundation, Inc.
All rights reserved.

This code is derived from software contributed to The NetBSD Foundation
by Dieter Baron and Thomas Klausner.

Redistribution and use in source and binary forms, with or without
modification, 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
Loading