| OLD | NEW | 
|---|
| 1 /* | 1 /* | 
| 2  * Copyright (c) 2014 The Native Client Authors. All rights reserved. | 2  * Copyright (c) 2014 The Native Client Authors. All rights reserved. | 
| 3  * Use of this source code is governed by a BSD-style license that can be | 3  * Use of this source code is governed by a BSD-style license that can be | 
| 4  * found in the LICENSE file. | 4  * found in the LICENSE file. | 
| 5  */ | 5  */ | 
| 6 | 6 | 
| 7 'use strict'; | 7 'use strict'; | 
| 8 | 8 | 
| 9 // This is the PPAPI code for TCP FIN (disconnected). | 9 // This is the PPAPI code for TCP FIN (disconnected). | 
| 10 var ERROR_CODE_FIN = -100; | 10 var ERROR_CODE_FIN = -100; | 
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 56 }); | 56 }); | 
| 57 | 57 | 
| 58 chrome.runtime.onConnectExternal.addListener(function(port) { | 58 chrome.runtime.onConnectExternal.addListener(function(port) { | 
| 59   var tcp = chrome.sockets.tcp; | 59   var tcp = chrome.sockets.tcp; | 
| 60 | 60 | 
| 61   port.onMessage.addListener(function(msg) { | 61   port.onMessage.addListener(function(msg) { | 
| 62     function resolve(data) { | 62     function resolve(data) { | 
| 63       var response = { | 63       var response = { | 
| 64         name: msg.name + '_reply', | 64         name: msg.name + '_reply', | 
| 65         data: data || null | 65         data: data || null | 
| 66       } | 66       }; | 
| 67       port.postMessage(response); | 67       port.postMessage(response); | 
| 68     } | 68     } | 
| 69     function reject(err) { | 69     function reject(err) { | 
| 70       var response = { | 70       var response = { | 
| 71         name: msg.name + '_error', | 71         name: msg.name + '_error', | 
| 72         error: err || null | 72         error: err || null | 
| 73       } | 73       }; | 
| 74       port.postMessage(response); | 74       port.postMessage(response); | 
| 75     } | 75     } | 
| 76 | 76 | 
| 77     switch (msg.name) { | 77     switch (msg.name) { | 
| 78       case 'tcp_connect': | 78       case 'tcp_connect': | 
| 79         if (msg.addr === undefined || msg.port === undefined) { | 79         if (msg.addr === undefined || msg.port === undefined) { | 
| 80           reject('"addr" and "port" fields expected'); | 80           reject('"addr" and "port" fields expected'); | 
| 81           break; | 81           break; | 
| 82         } | 82         } | 
| 83         tcp.create({}, function(createInfo) { | 83         tcp.create({}, function(createInfo) { | 
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 127     // O(N) time, but there's something wrong if there are enough TCP | 127     // O(N) time, but there's something wrong if there are enough TCP | 
| 128     // connections that the performance of this loop matters. | 128     // connections that the performance of this loop matters. | 
| 129     for (var socket in portMap) { | 129     for (var socket in portMap) { | 
| 130       if (portMap[socket] === port) { | 130       if (portMap[socket] === port) { | 
| 131         delete portMap[socket]; | 131         delete portMap[socket]; | 
| 132         tcp.close(parseInt(socket), function() {}); | 132         tcp.close(parseInt(socket), function() {}); | 
| 133       } | 133       } | 
| 134     } | 134     } | 
| 135   }); | 135   }); | 
| 136 }); | 136 }); | 
| OLD | NEW | 
|---|