Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(660)

Unified Diff: native_client_sdk/src/libraries/nacl_io_socket_test/example.js

Issue 22587003: [NaCl SDK] Add UDP and TCP Sockets (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to browser tester fix. Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..1a6a8bf8683a7150e4bcea680546de6175c2c5bd 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,51 @@
// 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) {
+ var listeningSocket = createInfo.socketId;
+ chrome.socket.listen(listeningSocket,
+ '127.0.0.1',
+ port,
+ 10,
+ function(result) {
+ if (result !== 0) {
+ console.log("Listen failed: " + result);
+ return;
+ }
+
+ chrome.socket.accept(listeningSocket, function(acceptInfo) {
+ if (result !== 0) {
+ console.log("Accept failed: " + result);
+ 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);
}
var currentTestEl = null;

Powered by Google App Engine
This is Rietveld 408576698