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

Side by Side 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: Running tests on package 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // Called by the common.js module. 4 // Called by the common.js module.
5
6 function runTCPEchoServer(port) {
7 console.log("Starting server on TCP port: " + port);
8 chrome.socket.create("tcp", {}, function(createInfo) {
9 listeningSocket = createInfo.socketId;
binji 2013/08/09 19:28:06 var listeningSocket
noelallen1 2013/08/09 22:53:22 Done.
10 creatingServer = false;
binji 2013/08/09 19:28:06 unused
noelallen1 2013/08/09 22:53:22 Done.
11 chrome.socket.listen(listeningSocket,
12 '127.0.0.1',
13 port,
14 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.
15 function(result) {
16 if (result !== 0) {
17 console.log("Listen failed: " + result);
18 return;
19 }
20
21 chrome.socket.accept(listeningSocket, function(acceptInfo) {
22 if (result !== 0) {
23 cconsole.log("Accept failed: " + result);
binji 2013/08/09 19:28:06 s/cconsole/console/
noelallen1 2013/08/09 22:53:22 Done.
24 return;
25 }
26
27 var newSock = acceptInfo.socketId;
28
29 var readCallback = function(readInfo) {
30 if (readInfo.resultCode < 0) {
31 console.log("Read failed: " + readInfo.resultCode);
32 chrome.socket.destroy(newSock);
33 return;
34 }
35
36 chrome.socket.write(newSock, readInfo.data, function(writeInfo) {})
37 chrome.socket.read(newSock, readCallback);
38 }
39
40 chrome.socket.read(newSock, readCallback);
41 })
42 })
43 })
44 }
45
5 function moduleDidLoad() { 46 function moduleDidLoad() {
6 // The module is not hidden by default so we can easily see if the plugin 47 // The module is not hidden by default so we can easily see if the plugin
7 // failed to load. 48 // failed to load.
8 common.hideModule(); 49 common.hideModule();
50 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
9 } 51 }
10 52
11 var currentTestEl = null; 53 var currentTestEl = null;
12 54
13 function startCommand(testName) { 55 function startCommand(testName) {
14 var testListEl = document.getElementById('tests'); 56 var testListEl = document.getElementById('tests');
15 var testEl = document.createElement('li'); 57 var testEl = document.createElement('li');
16 var testRowEl = document.createElement('div'); 58 var testRowEl = document.createElement('div');
17 var testNameEl = document.createElement('span'); 59 var testNameEl = document.createElement('span');
18 var testResultEl = document.createElement('span'); 60 var testResultEl = document.createElement('span');
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 argList = argList.substr(comma + 1); 118 argList = argList.substr(comma + 1);
77 } 119 }
78 args.push(arg); 120 args.push(arg);
79 } 121 }
80 122
81 // Last argument is the rest of the message. 123 // Last argument is the rest of the message.
82 args.push(argList); 124 args.push(argList);
83 125
84 cmdFunction.apply(null, args); 126 cmdFunction.apply(null, args);
85 } 127 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698