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

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: 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 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 var listeningSocket = createInfo.socketId;
10 chrome.socket.listen(listeningSocket,
11 '127.0.0.1',
12 port,
13 10,
14 function(result) {
15 if (result !== 0) {
16 console.log("Listen failed: " + result);
17 return;
18 }
19
20 chrome.socket.accept(listeningSocket, function(acceptInfo) {
21 if (result !== 0) {
22 console.log("Accept failed: " + result);
23 return;
24 }
25
26 var newSock = acceptInfo.socketId;
27
28 var readCallback = function(readInfo) {
29 if (readInfo.resultCode < 0) {
30 console.log("Read failed: " + readInfo.resultCode);
31 chrome.socket.destroy(newSock);
32 return;
33 }
34
35 chrome.socket.write(newSock, readInfo.data, function(writeInfo) {})
36 chrome.socket.read(newSock, readCallback);
37 }
38
39 chrome.socket.read(newSock, readCallback);
40 })
41 })
42 })
43 }
44
5 function moduleDidLoad() { 45 function moduleDidLoad() {
6 // The module is not hidden by default so we can easily see if the plugin 46 // The module is not hidden by default so we can easily see if the plugin
7 // failed to load. 47 // failed to load.
8 common.hideModule(); 48 common.hideModule();
49 runTCPEchoServer(4006);
9 } 50 }
10 51
11 var currentTestEl = null; 52 var currentTestEl = null;
12 53
13 function startCommand(testName) { 54 function startCommand(testName) {
14 var testListEl = document.getElementById('tests'); 55 var testListEl = document.getElementById('tests');
15 var testEl = document.createElement('li'); 56 var testEl = document.createElement('li');
16 var testRowEl = document.createElement('div'); 57 var testRowEl = document.createElement('div');
17 var testNameEl = document.createElement('span'); 58 var testNameEl = document.createElement('span');
18 var testResultEl = document.createElement('span'); 59 var testResultEl = document.createElement('span');
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 argList = argList.substr(comma + 1); 117 argList = argList.substr(comma + 1);
77 } 118 }
78 args.push(arg); 119 args.push(arg);
79 } 120 }
80 121
81 // Last argument is the rest of the message. 122 // Last argument is the rest of the message.
82 args.push(argList); 123 args.push(argList);
83 124
84 cmdFunction.apply(null, args); 125 cmdFunction.apply(null, args);
85 } 126 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698