Chromium Code Reviews| Index: native_client_sdk/src/libraries/nacl_io_socket_test/example.js |
| diff --git a/native_client_sdk/src/libraries/nacl_io_test/example.js b/native_client_sdk/src/libraries/nacl_io_socket_test/example.js |
| similarity index 68% |
| copy from native_client_sdk/src/libraries/nacl_io_test/example.js |
| copy to native_client_sdk/src/libraries/nacl_io_socket_test/example.js |
| index bd175944b9a4deb1ac549ea1daabd4323271be1a..a661ec7ad7721adde5374963bb2e09a70f934bd4 100644 |
| --- a/native_client_sdk/src/libraries/nacl_io_test/example.js |
| +++ b/native_client_sdk/src/libraries/nacl_io_socket_test/example.js |
| @@ -2,10 +2,52 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| // Called by the common.js module. |
| + |
| +function runTCPEchoServer(port) { |
| + console.log("Starting server on TCP port: " + port); |
| + chrome.socket.create("tcp", {}, function(createInfo) { |
| + listeningSocket = createInfo.socketId; |
|
binji
2013/08/09 19:28:06
var listeningSocket
noelallen1
2013/08/09 22:53:22
Done.
|
| + creatingServer = false; |
|
binji
2013/08/09 19:28:06
unused
noelallen1
2013/08/09 22:53:22
Done.
|
| + chrome.socket.listen(listeningSocket, |
| + '127.0.0.1', |
| + port, |
| + 10, |
|
binji
2013/08/09 19:28:06
what is 10?
noelallen1
2013/08/09 22:53:22
Q depth.
Cut and paste from socket example.
|
| + function(result) { |
| + if (result !== 0) { |
| + console.log("Listen failed: " + result); |
| + return; |
| + } |
| + |
| + chrome.socket.accept(listeningSocket, function(acceptInfo) { |
| + if (result !== 0) { |
| + cconsole.log("Accept failed: " + result); |
|
binji
2013/08/09 19:28:06
s/cconsole/console/
noelallen1
2013/08/09 22:53:22
Done.
|
| + return; |
| + } |
| + |
| + var newSock = acceptInfo.socketId; |
| + |
| + var readCallback = function(readInfo) { |
| + if (readInfo.resultCode < 0) { |
| + console.log("Read failed: " + readInfo.resultCode); |
| + chrome.socket.destroy(newSock); |
| + return; |
| + } |
| + |
| + chrome.socket.write(newSock, readInfo.data, function(writeInfo) {}) |
| + chrome.socket.read(newSock, readCallback); |
| + } |
| + |
| + chrome.socket.read(newSock, readCallback); |
| + }) |
| + }) |
| + }) |
| +} |
| + |
| function moduleDidLoad() { |
| // The module is not hidden by default so we can easily see if the plugin |
| // failed to load. |
| common.hideModule(); |
| + runTCPEchoServer(4006); |
|
binji
2013/08/09 19:28:06
does this work with 0 for ephemeral? Maybe worth d
noelallen1
2013/08/09 22:53:22
New CL. We don't really support testing as packag
binji
2013/08/09 23:08:27
OK
|
| } |
| var currentTestEl = null; |