You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2014/12/31 06:56:51 UTC
[01/13] cordova-app-harness git commit: Provided a connection to the
appropriate port.
Repository: cordova-app-harness
Updated Branches:
refs/heads/master 64b68d70e -> a35f398dc
Provided a connection to the appropriate port.
This removes the necessity of running `dab forward` to get USB connections to work.
This adds a dependency on adbkit.
Project: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/commit/e867c3d3
Tree: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/tree/e867c3d3
Diff: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/diff/e867c3d3
Branch: refs/heads/master
Commit: e867c3d31e61b98d088170d97b6e8f8c8fe3c3b5
Parents: 64b68d7
Author: Max Woghiren <ma...@gmail.com>
Authored: Fri Oct 31 13:32:09 2014 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Wed Dec 31 00:34:35 2014 -0500
----------------------------------------------------------------------
.../cordova-harness-client/harnessclient.js | 220 +++++++++++++------
.../cordova-harness-client/package.json | 1 +
2 files changed, 148 insertions(+), 73 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/e867c3d3/harness-push/node_modules/cordova-harness-client/harnessclient.js
----------------------------------------------------------------------
diff --git a/harness-push/node_modules/cordova-harness-client/harnessclient.js b/harness-push/node_modules/cordova-harness-client/harnessclient.js
index a2b9d99..f11fca5 100644
--- a/harness-push/node_modules/cordova-harness-client/harnessclient.js
+++ b/harness-push/node_modules/cordova-harness-client/harnessclient.js
@@ -19,6 +19,8 @@
var http = require('http');
var url = require('url');
+var fs = require('fs');
+var adb = require('adbkit');
var Q = require('q');
var AgentKeepAlive = require('agentkeepalive');
var PushSession = require('./pushsession');
@@ -31,88 +33,160 @@ var httpAgent = new AgentKeepAlive({
function doRequest(method, target, action, options) {
var deferred = Q.defer();
- var targetParts = target.split(':');
- var host = targetParts[0];
- var port = +(targetParts[1] || 2424);
- options = options || {};
-
- var queryParams = {};
- if (options.query) {
- Object.keys(options.query).forEach(function(k) {
- queryParams[k] = options.query[k];
- });
- }
- if (options.appId) {
- queryParams['appId'] = options.appId;
- }
- if (options.appType) {
- queryParams['appType'] = options.appType;
- }
-
- var uri = url.format({
- protocol: 'http',
- hostname: host,
- port: port,
- pathname: action,
- query: queryParams
- });
- var pathWithQuery = uri.replace(/^.*?\/\/.*?\//, '/');
- process.stdout.write(method + ' ' + uri);
- var headers = {
- 'Connection': 'keep-alive'
- };
- var body = null;
- if (method == 'POST' || method == 'PUT') {
- body = options.body || '';
- if (options.json) {
- body = JSON.stringify(options.json);
- headers['Content-Type'] = 'application/json';
+ var client = adb.createClient();
+ client.listDevices()
+ .then(function(devices) {
+ if (devices.length === 0) {
+ console.error('No devices detected.');
}
- headers['Content-Length'] = body.length;
- }
- var startTime = new Date();
- var req = http.request({
- hostname: host,
- port: port,
- method: method,
- path: pathWithQuery,
- headers: headers,
- agent: httpAgent
- });
+ // We use the first device.
+ var device = devices[0];
- req.on('error', function(e) {
- deferred.reject(e);
- });
+ // Open a TCP connection to port 2424.
+ client.openTcp(device.id, 2424)
+ .then(function(socket) {
+ // Override the function that creates a socket, instead using the existing socket.
+ // This function is identical to the one found in agentkeepalive, except that it doesn't create a new socket.
+ AgentKeepAlive.prototype.createSocket = function(req, options) {
+ var self = this;
+ socket._requestCount = 0;
+ if (self.keepAliveMsecs) {
+ socket._maxKeepAliveTimeout = function () {
+ debug('maxKeepAliveTimeout, socket destroy()');
+ socket.destroy();
+ self.timeoutSocketCount++;
+ };
+ socket.setTimeout(self.keepAliveMsecs, socket._maxKeepAliveTimeout);
+ // Disable Nagle's algorithm: http://blog.caustik.com/2012/04/08/scaling-node-js-to-100k-concurrent-connections/
+ socket.setNoDelay(true);
+ }
+ this.createSocketCount++;
+ return socket;
+ };
+ }).then(function() {
+ var targetParts = target.split(':');
+ var host = targetParts[0];
+ var port = +(targetParts[1] || 2424);
+ options = options || {};
- if (body) {
- req.write(body);
- }
- req.end();
-
- req.on('response', function(res) {
- process.stdout.write(' ==> ' + res.statusCode);
- res.setEncoding('utf8');
- var body = '';
- res.on('data', function(chunk) {
- body += chunk;
- });
- res.on('end', function() {
- process.stdout.write(' (' + (new Date() - startTime) + ')\n');
- if (res.statusCode != 200) {
- deferred.reject(new Error('Server returned status code: ' + res.statusCode + '\n\n' + body));
- return;
+ var queryParams = {};
+ if (options.query) {
+ Object.keys(options.query).forEach(function(k) {
+ queryParams[k] = options.query[k];
+ });
}
- try {
- body = options.expectJson ? JSON.parse(body) : body;
- } catch (e) {
- deferred.reject(new Error('Invalid JSON: ' + body.slice(500)));
- return;
+ if (options.appId) {
+ queryParams['appId'] = options.appId;
}
- deferred.resolve({res:res, body:body});
+ if (options.appType) {
+ queryParams['appType'] = options.appType;
+ }
+
+ var uri = url.format({
+ protocol: 'http',
+ hostname: host,
+ port: port,
+ pathname: action,
+ query: queryParams
+ });
+ var pathWithQuery = uri.replace(/^.*?\/\/.*?\//, '/');
+ process.stdout.write(method + ' ' + uri);
+
+ var headers = {
+ 'Connection': 'keep-alive'
+ };
+ var body = null;
+ if (method == 'POST' || method == 'PUT') {
+ body = options.body || '';
+ if (options.json) {
+ body = JSON.stringify(options.json);
+ headers['Content-Type'] = 'application/json';
+ }
+ headers['Content-Length'] = body.length;
+ }
+
+ var startTime = new Date();
+ var req = http.request({
+ hostname: host,
+ port: port,
+ method: method,
+ path: pathWithQuery,
+ headers: headers,
+ agent: httpAgent
+ });
+
+ var outStream = null;
+ var innerDeferred = null;
+
+ if (options.saveResponseToFile) {
+ innerDeferred = Q.defer();
+ deferred.promise.then(function() {
+ return innerDeferred.promise;
+ }, function(e) {
+ if (outStream) {
+ outStream.close();
+ }
+ throw e;
+ });
+ }
+
+ req.on('error', function(e) {
+ deferred.reject(e);
+ });
+ // Disable timeouts for packapk until we can optimize it :(.
+ req.on('socket', function(socket) {
+ socket.setTimeout(0);
+ });
+
+ if (body) {
+ req.write(body);
+ }
+ req.end();
+ req.on('response', function(res) {
+ process.stdout.write(' ==> ' + res.statusCode);
+ var body = '';
+ var lastDotTime = Date.now();
+ if (options.saveResponseToFile) {
+ outStream = fs.createWriteStream(options.saveResponseToFile);
+ res.on('data', function() {
+ var now = Date.now();
+ if (now - lastDotTime > 1000) {
+ lastDotTime = now;
+ process.stdout.write('.');
+ }
+ });
+ res.pipe(outStream);
+ outStream.on('finish', function() {
+ outStream.close(innerDeferred.resolve); // close() is async, call cb after close completes.
+ });
+ } else {
+ res.setEncoding('utf8');
+ res.on('data', function(chunk) {
+ body += chunk;
+ });
+ }
+ res.on('end', function() {
+ process.stdout.write(' (' + (new Date() - startTime) + ')\n');
+ if (res.statusCode != 200) {
+ deferred.reject(new Error('Server returned status code: ' + res.statusCode + '\n\n' + body));
+ return;
+ }
+ if (!options.saveResponseToFile) {
+ try {
+ body = options.expectJson ? JSON.parse(body) : body;
+ } catch (e) {
+ deferred.reject(new Error('Invalid JSON: ' + body.slice(500)));
+ return;
+ }
+ }
+ deferred.resolve({res:res, body:body});
+ });
+ });
});
});
+
return deferred.promise;
}
http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/e867c3d3/harness-push/node_modules/cordova-harness-client/package.json
----------------------------------------------------------------------
diff --git a/harness-push/node_modules/cordova-harness-client/package.json b/harness-push/node_modules/cordova-harness-client/package.json
index 503f32c..50e921f 100644
--- a/harness-push/node_modules/cordova-harness-client/package.json
+++ b/harness-push/node_modules/cordova-harness-client/package.json
@@ -18,6 +18,7 @@
"cordova-app-harness"
],
"dependencies": {
+ "adbkit": "^2.1.2",
"agentkeepalive": "~0.2",
"jszip": "~2.1",
"q": "~0.9",
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org
[02/13] cordova-app-harness git commit: Allow
installer.getPluginMetadata() to return a value instead of a promise
Posted by ag...@apache.org.
Allow installer.getPluginMetadata() to return a value instead of a promise
Project: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/commit/3b91a0cc
Tree: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/tree/3b91a0cc
Diff: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/diff/3b91a0cc
Branch: refs/heads/master
Commit: 3b91a0cc65e760829f55b2c46fa0ae7d9d30aa5f
Parents: e867c3d
Author: Andrew Grieve <ag...@chromium.org>
Authored: Wed Dec 31 00:34:46 2014 -0500
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Wed Dec 31 00:34:46 2014 -0500
----------------------------------------------------------------------
www/cdvah/js/AppsService.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/3b91a0cc/www/cdvah/js/AppsService.js
----------------------------------------------------------------------
diff --git a/www/cdvah/js/AppsService.js b/www/cdvah/js/AppsService.js
index 00443d5..e10a940 100644
--- a/www/cdvah/js/AppsService.js
+++ b/www/cdvah/js/AppsService.js
@@ -158,7 +158,7 @@
activeInstaller = installer;
return installer.launch();
}).then(function(launchUrl) {
- return installer.getPluginMetadata()
+ return $q.when(installer.getPluginMetadata())
.then(function(pluginMetadata) {
$location.path('/inappmenu');
// If we're relaunching the active app, just reload the existing webview.
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org
[11/13] cordova-app-harness git commit: Add debug logging to
HttpServer.js (disabled by default)
Posted by ag...@apache.org.
Add debug logging to HttpServer.js (disabled by default)
Project: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/commit/ba347fd8
Tree: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/tree/ba347fd8
Diff: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/diff/ba347fd8
Branch: refs/heads/master
Commit: ba347fd860aed8a615780286dd215bbcab7c1fa0
Parents: 1d3f278
Author: Andrew Grieve <ag...@chromium.org>
Authored: Tue Nov 18 15:05:10 2014 -0800
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Wed Dec 31 00:50:42 2014 -0500
----------------------------------------------------------------------
www/cdvah/js/HttpServer.js | 34 ++++++++++++++++++++++++++++------
1 file changed, 28 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/ba347fd8/www/cdvah/js/HttpServer.js
----------------------------------------------------------------------
diff --git a/www/cdvah/js/HttpServer.js b/www/cdvah/js/HttpServer.js
index bec8175..dd773e6 100644
--- a/www/cdvah/js/HttpServer.js
+++ b/www/cdvah/js/HttpServer.js
@@ -18,6 +18,7 @@
*/
(function() {
'use strict';
+
/* global myApp */
/* global chrome */
myApp.factory('HttpServer', ['$q', function($q) {
@@ -35,6 +36,9 @@
var socketMap = Object.create(null);
chrome.sockets.tcp.onReceive.addListener(function(receiveInfo) {
+ if (HttpServer.VERBOSE_LOGGING) {
+ console.log('read on socket ' + receiveInfo.socketId + ' of len=' + (receiveInfo.data && receiveInfo.data.byteLength));
+ }
var socket = socketMap[receiveInfo.socketId];
if (socket) {
// data will be missing when piping to a file.
@@ -141,7 +145,9 @@
// TODO: Change this to pass in self.bytesRemaining.
return self._requestData.socket.pipeToUri(uri, true)
.then(null, null, function(numBytesRead) {
- console.log('Piped chunk of size ' + numBytesRead);
+ if (HttpServer.VERBOSE_LOGGING) {
+ console.log('Piped chunk of size ' + numBytesRead);
+ }
self._updateBytesRemaining(numBytesRead);
if (self.bytesRemaining === 0) {
// TODO: Delete stopPipeToFile() once pipeToUrl takes in a byteCount.
@@ -199,7 +205,9 @@
.then(function(chunk) {
if (chunk) {
var chunkSize = chunk.byteLength;
- console.log('Processing request chunk of size ' + chunkSize);
+ if (HttpServer.VERBOSE_LOGGING) {
+ console.log('Processing request chunk of size ' + chunkSize);
+ }
self._updateBytesRemaining(chunkSize);
}
return chunk;
@@ -291,7 +299,7 @@
if (disconnect) {
this._requestData.socket.close();
} else {
- this._requestData.httpServer._onAccept(this._requestData.socket);
+ this._requestData.httpServer._onAccept(this._requestData.socket, true);
}
};
@@ -441,6 +449,10 @@
var deferred = this._writeQueue[1];
if (arrayBuffer && arrayBuffer.byteLength > 0) {
var self = this;
+ if (HttpServer.VERBOSE_LOGGING) {
+ console.log('sending chunk of len=' + arrayBuffer.byteLength);
+ console.log('contents: ' + arrayBufferToString(arrayBuffer));
+ }
chrome.sockets.tcp.send(this.socketId, arrayBuffer, function(writeInfo) {
if (writeInfo.bytesSent !== arrayBuffer.byteLength) {
console.warn('Failed to write entire ArrayBuffer.');
@@ -457,6 +469,9 @@
}
});
} else {
+ if (HttpServer.VERBOSE_LOGGING) {
+ console.log('not sending chunk of len=' + arrayBuffer);
+ }
this._writeQueue.shift();
this._writeQueue.shift();
deferred.resolve();
@@ -470,6 +485,9 @@
this._handlers = Object.create(null); // Map of resourcePath -> function(httpRequest, httpResponse)
}
+ // Toggle this to enable more console logs.
+ HttpServer.VERBOSE_LOGGING = false;
+
HttpServer.prototype.addRoute = function(path, func) {
this._handlers[path] = func;
return this;
@@ -492,7 +510,7 @@
if (acceptInfo.socketId === createInfo.socketId) {
// Default size of 4k does not work very efficiently over Cordova's exec() bridge.
chrome.sockets.tcp.update(acceptInfo.clientSocketId, {bufferSize: 200 * 1024});
- self._onAccept(new Socket(acceptInfo.clientSocketId));
+ self._onAccept(new Socket(acceptInfo.clientSocketId), false);
}
});
chrome.sockets.tcpServer.onAcceptError.addListener(function(errorInfo) {
@@ -510,8 +528,12 @@
return deferred.promise;
};
- HttpServer.prototype._onAccept = function(socket) {
- console.log('Connection established on socket ' + socket.socketId);
+ HttpServer.prototype._onAccept = function(socket, isReuse) {
+ if (isReuse) {
+ console.log('Re-using socket ' + socket.socketId + ' due to Connection: keep-alive');
+ } else {
+ console.log('Connection established on socket ' + socket.socketId);
+ }
var requestData = {
state: STATE_NEW,
socket: socket,
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org
[09/13] cordova-app-harness git commit: Use
chrome.sockets.tcp.update({uri:}) to more efficiently pipe request payloads
to files
Posted by ag...@apache.org.
Use chrome.sockets.tcp.update({uri:}) to more efficiently pipe request payloads to files
20 megs new takes just a few seconds!
Added in some TODOs to tweak the code once the API can take in the
number of bytes to pipe.
Project: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/commit/d3e08982
Tree: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/tree/d3e08982
Diff: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/diff/d3e08982
Branch: refs/heads/master
Commit: d3e0898244cf8f6a8805028e677cff9162d1df5a
Parents: e1a6069
Author: Andrew Grieve <ag...@chromium.org>
Authored: Fri Nov 14 21:33:23 2014 +0100
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Wed Dec 31 00:49:12 2014 -0500
----------------------------------------------------------------------
www/cdvah/js/HarnessServer.js | 29 +-------
www/cdvah/js/HttpServer.js | 147 +++++++++++++++++++++++++++++++------
2 files changed, 128 insertions(+), 48 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/d3e08982/www/cdvah/js/HarnessServer.js
----------------------------------------------------------------------
diff --git a/www/cdvah/js/HarnessServer.js b/www/cdvah/js/HarnessServer.js
index d6bf873..0e6b102 100644
--- a/www/cdvah/js/HarnessServer.js
+++ b/www/cdvah/js/HarnessServer.js
@@ -79,31 +79,10 @@
}
function pipeRequestToFile(req, destUrl) {
- var writer = null;
- function handleChunk(arrayBuffer) {
- var ret = $q.when();
- if (writer == null) {
- ret = ResourcesLoader.createFileWriter(destUrl)
- .then(function(w) {
- writer = w;
- });
- }
- return ret.then(function() {
- var deferred = $q.defer();
- writer.onwrite = deferred.resolve;
- writer.onerror = function() {
- deferred.reject(writer.error);
- };
- writer.write(arrayBuffer);
- return deferred.promise;
- })
- .then(function() {
- if (req.bytesRemaining > 0) {
- return req.readChunk().then(handleChunk);
- }
- });
- }
- return req.readChunk().then(handleChunk);
+ return ResourcesLoader.createFileWriter(destUrl)
+ .then(function(w) {
+ return req.pipeToUri(w, destUrl);
+ });
}
function pipeFileToResponse(srcUrl, resp) {
http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/d3e08982/www/cdvah/js/HttpServer.js
----------------------------------------------------------------------
diff --git a/www/cdvah/js/HttpServer.js b/www/cdvah/js/HttpServer.js
index 1055008..bec8175 100644
--- a/www/cdvah/js/HttpServer.js
+++ b/www/cdvah/js/HttpServer.js
@@ -37,8 +37,13 @@
chrome.sockets.tcp.onReceive.addListener(function(receiveInfo) {
var socket = socketMap[receiveInfo.socketId];
if (socket) {
- socket._pendingReadChunks.push(receiveInfo.data);
- socket._onReceive();
+ // data will be missing when piping to a file.
+ var numBytes = receiveInfo.bytesRead;
+ if (receiveInfo.data) {
+ numBytes = receiveInfo.data.byteLength;
+ socket._pendingReadChunks.push(receiveInfo.data);
+ }
+ socket._onReceive(numBytes);
}
});
@@ -126,7 +131,58 @@
});
};
- HttpRequest.prototype.readChunk = function(/* optional */maxChunkSize) {
+ HttpRequest.prototype.pipeToUri = function(fileWriter, uri) {
+ var useNativePipeApi = uri && typeof cordova != 'undefined';
+ var self = this;
+ function handleChunk(arrayBuffer) {
+ var deferred = $q.defer();
+ // Only way to get a null arrayBuffer is when flushReadQueue() has been called.
+ if (!arrayBuffer) {
+ // TODO: Change this to pass in self.bytesRemaining.
+ return self._requestData.socket.pipeToUri(uri, true)
+ .then(null, null, function(numBytesRead) {
+ console.log('Piped chunk of size ' + numBytesRead);
+ self._updateBytesRemaining(numBytesRead);
+ if (self.bytesRemaining === 0) {
+ // TODO: Delete stopPipeToFile() once pipeToUrl takes in a byteCount.
+ self._requestData.socket.stopPipeToFile();
+ }
+ });
+ }
+ fileWriter.onwrite = deferred.resolve;
+ fileWriter.onerror = function() {
+ deferred.reject(fileWriter.error);
+ };
+ fileWriter.write(arrayBuffer);
+ return deferred.promise
+ .then(function() {
+ if (self.bytesRemaining > 0) {
+ return self._readChunkInternal(0, useNativePipeApi).then(handleChunk);
+ }
+ });
+ }
+ if (useNativePipeApi) {
+ return this._requestData.socket.flushReadQueue()
+ .then(function() {
+ return self._readChunkInternal(0, true).then(handleChunk);
+ });
+ }
+ return self._readChunkInternal(0, false).then(handleChunk);
+ };
+
+ HttpRequest.prototype._updateBytesRemaining = function(numBytesRead) {
+ this.bytesRemaining -= numBytesRead;
+ if (this.bytesRemaining < 0) {
+ throw new Error('Bytes remaining negative: ' + this.bytesRemaining);
+ }
+ if (this.bytesRemaining === 0 && this._requestData.state === STATE_HEADERS_RECEIVED) {
+ changeState(this._requestData, STATE_REQUEST_RECEIVED);
+ }
+ };
+
+ HttpRequest.prototype._readChunkInternal = function(/* optional */maxChunkSize, sync) {
+ // Don't read past bytesRemaining.
+ maxChunkSize = maxChunkSize ? Math.min(maxChunkSize, this.bytesRemaining) : this.bytesRemaining;
// Allow readChunk() to be called *once* after request is already received.
// This is convenient for empty payloads.
if (this._requestData.state === STATE_REQUEST_RECEIVED) {
@@ -139,21 +195,21 @@
}
}
var self = this;
- return this._requestData.socket.read(maxChunkSize)
+ return (sync ? $q.when(this._requestData.socket.readSync(maxChunkSize)) : this._requestData.socket.read(maxChunkSize))
.then(function(chunk) {
- var chunkSize = chunk.byteLength;
- console.log('Processing request chunk of size ' + chunkSize);
- self.bytesRemaining -= chunkSize;
- if (self.bytesRemaining < 0) {
- throw new Error('Bytes remaining negative: ' + self.bytesRemaining);
- }
- if (self.bytesRemaining === 0 && self._requestData.state === STATE_HEADERS_RECEIVED) {
- changeState(self._requestData, STATE_REQUEST_RECEIVED);
+ if (chunk) {
+ var chunkSize = chunk.byteLength;
+ console.log('Processing request chunk of size ' + chunkSize);
+ self._updateBytesRemaining(chunkSize);
}
return chunk;
});
};
+ HttpRequest.prototype.readChunk = function(/* optional */maxChunkSize) {
+ return this._readChunkInternal(maxChunkSize, false);
+ };
+
function HttpResponse(requestData) {
this._requestData = requestData;
this.headers = Object.create(null);
@@ -246,6 +302,7 @@
this.onClose = null;
this._pendingReadChunks = [];
this._pendingReadDeferred = null;
+ this._pendingPipeToFileDeferred = null;
this._writeQueue = [];
this._paused = true;
}
@@ -253,26 +310,32 @@
Socket.prototype.unread = function(chunk) {
if (chunk.byteLength > 0) {
this._pendingReadChunks.unshift(chunk);
- this._onReceive();
+ this._onReceive(chunk.byteLength);
}
};
- Socket.prototype.read = function(maxLength) {
+ // Returns data that's already in JS, or null if nothing is ready.
+ // Never unpauses the socket.
+ Socket.prototype.readSync = function(maxLength) {
if (this._pendingReadDeferred) {
throw new Error('Read already in progress.');
} else if (!this.alive) {
throw new Error('Socket.read called after socket closed.');
}
maxLength = maxLength || Infinity;
- var deferred = $q.defer();
var chunk = this._pendingReadChunks.shift();
+ if (chunk && chunk.byteLength > maxLength) {
+ this._pendingReadChunks.unshift(chunk.slice(maxLength));
+ chunk = chunk.slice(0, maxLength);
+ }
+ return chunk;
+ };
+
+ Socket.prototype.read = function(maxLength) {
+ var deferred = $q.defer();
+ var chunk = this.readSync(maxLength);
if (chunk) {
- if (chunk.byteLength <= maxLength) {
- deferred.resolve(chunk);
- } else {
- this._pendingReadChunks.unshift(chunk.slice(maxLength));
- deferred.resolve(chunk.slice(0, maxLength));
- }
+ deferred.resolve(chunk);
} else {
this._pendingReadDeferred = deferred;
}
@@ -309,6 +372,42 @@
}
};
+ // Pauses the socket, and then returns all pending read chunks in as an array.
+ // Fails if there's a pending call to read(), but you can call read() again
+ // after the flush.
+ Socket.prototype.flushReadQueue = function() {
+ if (this._pendingReadDeferred) {
+ throw new Error('socket.flushReadQueue() called during socket.read()');
+ }
+ var deferred = $q.defer();
+ this._paused = true;
+ chrome.sockets.tcp.setPaused(this.socketId, true, deferred.resolve);
+ return deferred.promise;
+ };
+
+ Socket.prototype.pipeToUri = function(uri, append) {
+ if (this._pendingReadDeferred) {
+ throw new Error('socket.pipeToUri() called during bad state.');
+ }
+ if (!this._paused) {
+ throw new Error('socket.pipeToUri() called without first calling flushReadQueue().');
+ }
+ if (this._pendingReadChunks.length) {
+ throw new Error('socket.pipeToUri() called when there are outstanding read chunks.');
+ }
+ this._pendingPipeToFileDeferred = $q.defer();
+ chrome.sockets.tcp.update(this.socketId, { destUri: uri, append: append });
+ // TODO: The sockets call to initiate piping should unpause automatically.
+ this._setPaused(false);
+ return this._pendingPipeToFileDeferred.promise;
+ };
+
+ Socket.prototype.stopPipeToFile = function() {
+ var deferred = this._pendingPipeToFileDeferred;
+ this._pendingPipeToFileDeferred = null;
+ chrome.sockets.tcp.update(this.socketId, { destUri: '' }, deferred.resolve);
+ };
+
Socket.prototype._setPaused = function(value) {
if (value != this._paused) {
chrome.sockets.tcp.setPaused(this.socketId, value, null);
@@ -316,8 +415,10 @@
}
};
- Socket.prototype._onReceive = function() {
- if (this._pendingReadDeferred) {
+ Socket.prototype._onReceive = function(numBytes) {
+ if (this._pendingPipeToFileDeferred) {
+ this._pendingPipeToFileDeferred.notify(numBytes);
+ } else if (this._pendingReadDeferred) {
var deferred = this._pendingReadDeferred;
this._pendingReadDeferred = null;
deferred.resolve(this._pendingReadChunks.shift());
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org
[10/13] cordova-app-harness git commit: Fix "Unable to bind to port"
message when wifi is disabled.
Posted by ag...@apache.org.
Fix "Unable to bind to port" message when wifi is disabled.
Instead, display that you are bound to localhost, which is perfectly
fine for deploying via USB.
Project: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/commit/1d3f2789
Tree: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/tree/1d3f2789
Diff: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/diff/1d3f2789
Branch: refs/heads/master
Commit: 1d3f2789268eb786227be9790b8b1137c9518493
Parents: d3e0898
Author: Andrew Grieve <ag...@chromium.org>
Authored: Fri Nov 14 21:50:41 2014 +0100
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Wed Dec 31 00:50:14 2014 -0500
----------------------------------------------------------------------
www/cdvah/js/ListCtrl.js | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/1d3f2789/www/cdvah/js/ListCtrl.js
----------------------------------------------------------------------
diff --git a/www/cdvah/js/ListCtrl.js b/www/cdvah/js/ListCtrl.js
index b831a69..84740b1 100644
--- a/www/cdvah/js/ListCtrl.js
+++ b/www/cdvah/js/ListCtrl.js
@@ -34,7 +34,8 @@
var getInfoCallback = function() {
HarnessServer.getListenAddress(/* skipCache */ true)
.then(function(value) {
- $scope.ipAddress = value ? value : 'Failed to start server';
+ // No IP addresses happens when wifi is not connected.
+ $scope.ipAddress = value ? value : '127.0.0.1';
});
};
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org
[03/13] cordova-app-harness git commit: Improved error handling.
Posted by ag...@apache.org.
Improved error handling.
Project: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/commit/a2260d12
Tree: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/tree/a2260d12
Diff: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/diff/a2260d12
Branch: refs/heads/master
Commit: a2260d12f65b0432b9426b9df7efc4472ad612d6
Parents: 3b91a0c
Author: Max Woghiren <ma...@gmail.com>
Authored: Tue Nov 4 15:09:51 2014 -0500
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Wed Dec 31 00:36:25 2014 -0500
----------------------------------------------------------------------
.../node_modules/cordova-harness-client/harnessclient.js | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/a2260d12/harness-push/node_modules/cordova-harness-client/harnessclient.js
----------------------------------------------------------------------
diff --git a/harness-push/node_modules/cordova-harness-client/harnessclient.js b/harness-push/node_modules/cordova-harness-client/harnessclient.js
index f11fca5..cf59ebe 100644
--- a/harness-push/node_modules/cordova-harness-client/harnessclient.js
+++ b/harness-push/node_modules/cordova-harness-client/harnessclient.js
@@ -38,7 +38,8 @@ function doRequest(method, target, action, options) {
client.listDevices()
.then(function(devices) {
if (devices.length === 0) {
- console.error('No devices detected.');
+ deferred.reject('No devices detected.');
+ return;
}
// We use the first device.
@@ -65,6 +66,8 @@ function doRequest(method, target, action, options) {
this.createSocketCount++;
return socket;
};
+ }, function(error) {
+ deferred.reject('\nCould not connect to the device. Make sure you have the Chrome App Developer Tool for Mobile open.');
}).then(function() {
var targetParts = target.split(':');
var host = targetParts[0];
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org
[06/13] cordova-app-harness git commit: Fix jslint error in
harnessclient
Posted by ag...@apache.org.
Fix jslint error in harnessclient
Project: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/commit/eb79102c
Tree: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/tree/eb79102c
Diff: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/diff/eb79102c
Branch: refs/heads/master
Commit: eb79102cf562c8f94546319a5f990b541504af2c
Parents: 8da05bf
Author: Andrew Grieve <ag...@chromium.org>
Authored: Thu Nov 6 15:44:50 2014 -0500
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Wed Dec 31 00:42:25 2014 -0500
----------------------------------------------------------------------
harness-push/node_modules/cordova-harness-client/harnessclient.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/eb79102c/harness-push/node_modules/cordova-harness-client/harnessclient.js
----------------------------------------------------------------------
diff --git a/harness-push/node_modules/cordova-harness-client/harnessclient.js b/harness-push/node_modules/cordova-harness-client/harnessclient.js
index 169a4dd..ab76548 100644
--- a/harness-push/node_modules/cordova-harness-client/harnessclient.js
+++ b/harness-push/node_modules/cordova-harness-client/harnessclient.js
@@ -46,7 +46,7 @@ HarnessClient.detectAdbTargets = function() {
a.type > b.type ? 1 :
0;
});
- return devices.map(function(d) { return 'adb:' + d.id });
+ return devices.map(function(d) { return 'adb:' + d.id; });
}, function() {
return Q.reject('Could not run adb command.');
});
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org
[05/13] cordova-app-harness git commit: Fix typo from prev adbkit
commit (delete createSocket vs delete createConnection)
Posted by ag...@apache.org.
Fix typo from prev adbkit commit (delete createSocket vs delete createConnection)
Project: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/commit/8da05bf6
Tree: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/tree/8da05bf6
Diff: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/diff/8da05bf6
Branch: refs/heads/master
Commit: 8da05bf6f7af113b512aaf85eb051dfb090b6463
Parents: 60211b8
Author: Andrew Grieve <ag...@chromium.org>
Authored: Thu Nov 6 12:09:42 2014 -0500
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Wed Dec 31 00:42:05 2014 -0500
----------------------------------------------------------------------
.../node_modules/cordova-harness-client/harnessclient.js | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/8da05bf6/harness-push/node_modules/cordova-harness-client/harnessclient.js
----------------------------------------------------------------------
diff --git a/harness-push/node_modules/cordova-harness-client/harnessclient.js b/harness-push/node_modules/cordova-harness-client/harnessclient.js
index 0919087..169a4dd 100644
--- a/harness-push/node_modules/cordova-harness-client/harnessclient.js
+++ b/harness-push/node_modules/cordova-harness-client/harnessclient.js
@@ -97,7 +97,7 @@ HarnessClient.prototype.doRequest = function(method, action, options) {
};
} else {
// Revert to prototype implementation.
- delete httpAgent.createSocket;
+ delete httpAgent.createConnection;
}
options = options || {};
@@ -170,8 +170,7 @@ HarnessClient.prototype.doRequest = function(method, action, options) {
socket.setTimeout(0);
// Check if for some reason our adb socket was not used.
if (adbSocket && adbSocket != socket) {
- console.log('destroying');
- delete httpAgent.createSocket;
+ delete httpAgent.createConnection;
adbSocket.destroy();
}
});
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org
[04/13] cordova-app-harness git commit: Enhancements to new adbkit
integration.
Posted by ag...@apache.org.
Enhancements to new adbkit integration.
- Fix jshint errors
- Fix process never exiting after pushing
- Expose a symbol for detecting connected devices
- Destroy socket if it's not picked up by the connection
- Disable multiple connections per-host since we were just returning the same socket for each call to createSocket
Project: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/commit/60211b80
Tree: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/tree/60211b80
Diff: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/diff/60211b80
Branch: refs/heads/master
Commit: 60211b80bc0978d1d9483964e8bb1557447dac38
Parents: a2260d1
Author: Andrew Grieve <ag...@chromium.org>
Authored: Wed Nov 5 14:54:08 2014 -0500
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Wed Dec 31 00:41:44 2014 -0500
----------------------------------------------------------------------
.../cordova-harness-client/harnessclient.js | 144 +++++++++++--------
1 file changed, 86 insertions(+), 58 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/60211b80/harness-push/node_modules/cordova-harness-client/harnessclient.js
----------------------------------------------------------------------
diff --git a/harness-push/node_modules/cordova-harness-client/harnessclient.js b/harness-push/node_modules/cordova-harness-client/harnessclient.js
index cf59ebe..0919087 100644
--- a/harness-push/node_modules/cordova-harness-client/harnessclient.js
+++ b/harness-push/node_modules/cordova-harness-client/harnessclient.js
@@ -20,58 +20,85 @@
var http = require('http');
var url = require('url');
var fs = require('fs');
-var adb = require('adbkit');
+var adbkit = require('adbkit');
var Q = require('q');
var AgentKeepAlive = require('agentkeepalive');
var PushSession = require('./pushsession');
var httpAgent = new AgentKeepAlive({
- maxSockets: 5,
- maxFreeSockets: 5,
+ maxSockets: 1, // Must be set to 1 unless we refactor to allow multiple sockets through adbkit.
+ maxFreeSockets: 1,
keepAliveMsecs: 3000000
});
-function doRequest(method, target, action, options) {
- var deferred = Q.defer();
+// Client creation is cheap. No IO done until first command.
+var adbClient = adbkit.createClient();
- var client = adb.createClient();
- client.listDevices()
+function HarnessClient(target) {
+ this.target = target;
+}
+
+HarnessClient.detectAdbTargets = function() {
+ return adbClient.listDevices()
+ .then(function(devices) {
+ devices.sort(function(a,b) {
+ return a.type < b.type ? -1 :
+ a.type > b.type ? 1 :
+ 0;
+ });
+ return devices.map(function(d) { return 'adb:' + d.id });
+ }, function() {
+ return Q.reject('Could not run adb command.');
+ });
+};
+
+HarnessClient.prototype.autoDetectTarget = function() {
+ return HarnessClient.detectAdbTargets()
.then(function(devices) {
if (devices.length === 0) {
- deferred.reject('No devices detected.');
- return;
+ return '127.0.0.1:2424';
}
+ return devices[0];
+ }, function() {
+ return Q.reject('Could not run adb command.');
+ });
+};
- // We use the first device.
- var device = devices[0];
-
- // Open a TCP connection to port 2424.
- client.openTcp(device.id, 2424)
- .then(function(socket) {
- // Override the function that creates a socket, instead using the existing socket.
- // This function is identical to the one found in agentkeepalive, except that it doesn't create a new socket.
- AgentKeepAlive.prototype.createSocket = function(req, options) {
- var self = this;
- socket._requestCount = 0;
- if (self.keepAliveMsecs) {
- socket._maxKeepAliveTimeout = function () {
- debug('maxKeepAliveTimeout, socket destroy()');
- socket.destroy();
- self.timeoutSocketCount++;
- };
- socket.setTimeout(self.keepAliveMsecs, socket._maxKeepAliveTimeout);
- // Disable Nagle's algorithm: http://blog.caustik.com/2012/04/08/scaling-node-js-to-100k-concurrent-connections/
- socket.setNoDelay(true);
- }
- this.createSocketCount++;
- return socket;
- };
- }, function(error) {
- deferred.reject('\nCould not connect to the device. Make sure you have the Chrome App Developer Tool for Mobile open.');
- }).then(function() {
- var targetParts = target.split(':');
- var host = targetParts[0];
- var port = +(targetParts[1] || 2424);
+HarnessClient.prototype.doRequest = function(method, action, options) {
+ var self = this;
+ return Q.when().then(function() {
+ return self.target || self.autoDetectTarget();
+ }).catch(function() {
+ return '127.0.0.1:2424';
+ }).then(function(target) {
+ self.target = target;
+ var targetParts = target.split(':');
+ var host = targetParts[0];
+ var port = +(targetParts[1] || 2424);
+ var deviceId = null;
+ if (host == 'adb') {
+ deviceId = targetParts[1];
+ port = +(targetParts[2] || 2424);
+ host = 'adb_' + deviceId;
+ }
+ // If using adb, try to open a socket.
+ return Q.when().then(function() {
+ return deviceId && adbClient.openTcp(deviceId, port);
+ }).catch(function() {
+ return Q.reject('Could not connect to device. Make sure you have the Chrome App Developer Tool for Mobile open.');
+ }).then(function(adbSocket) {
+ var deferred = Q.defer();
+
+ if (adbSocket) {
+ // Override the function that creates a socket, instead using the existing socket.
+ // This function is identical to the one found in agentkeepalive, except that it doesn't create a new socket.
+ httpAgent.createConnection = function() {
+ return adbSocket;
+ };
+ } else {
+ // Revert to prototype implementation.
+ delete httpAgent.createSocket;
+ }
options = options || {};
var queryParams = {};
@@ -138,9 +165,15 @@ function doRequest(method, target, action, options) {
req.on('error', function(e) {
deferred.reject(e);
});
- // Disable timeouts for packapk until we can optimize it :(.
req.on('socket', function(socket) {
+ // Disable timeouts for packapk until we can optimize it :(.
socket.setTimeout(0);
+ // Check if for some reason our adb socket was not used.
+ if (adbSocket && adbSocket != socket) {
+ console.log('destroying');
+ delete httpAgent.createSocket;
+ adbSocket.destroy();
+ }
});
if (body) {
@@ -187,46 +220,41 @@ function doRequest(method, target, action, options) {
deferred.resolve({res:res, body:body});
});
});
+ return deferred.promise;
});
});
-
- return deferred.promise;
-}
-
-function HarnessClient(target) {
- this.target = target || '127.0.0.1';
-}
+};
HarnessClient.prototype.info = function() {
- return doRequest('GET', this.target, '/info', { expectJson: true });
+ return this.doRequest('GET', '/info', { expectJson: true });
};
HarnessClient.prototype.assetmanifest = function(/* optional */ appId) {
- return doRequest('GET', this.target, '/assetmanifest', {expectJson: true, appId: appId});
+ return this.doRequest('GET', '/assetmanifest', {expectJson: true, appId: appId});
};
HarnessClient.prototype.menu = function() {
- return doRequest('POST', this.target, '/menu');
+ return this.doRequest('POST', '/menu');
};
HarnessClient.prototype.quit = function() {
- return doRequest('POST', this.target, '/quit');
+ return this.doRequest('POST', '/quit');
};
HarnessClient.prototype.evalJs = function(someJs) {
- return doRequest('POST', this.target, '/exec', { query: {code: someJs} });
+ return this.doRequest('POST', '/exec', { query: {code: someJs} });
};
HarnessClient.prototype.launch = function(/* optional */ appId) {
- return doRequest('POST', this.target, '/launch', { appId: appId});
+ return this.doRequest('POST', '/launch', { appId: appId});
};
HarnessClient.prototype.deleteAllApps = function() {
- return doRequest('POST', this.target, '/deleteapp', { query: {'all': 1} });
+ return this.doRequest('POST', '/deleteapp', { query: {'all': 1} });
};
HarnessClient.prototype.deleteApp = function(/* optional */ appId) {
- return doRequest('POST', this.target, '/deleteapp', { appId: appId});
+ return this.doRequest('POST', '/deleteapp', { appId: appId});
};
HarnessClient.prototype.pushZip = function(appId, appType, zipData, /* optional */ totalPushBytes, /* optional */ manifestEtag) {
@@ -237,7 +265,7 @@ HarnessClient.prototype.pushZip = function(appId, appType, zipData, /* optional
if (manifestEtag) {
query['manifestEtag'] = manifestEtag;
}
- return doRequest('POST', this.target, '/zippush', {
+ return this.doRequest('POST', '/zippush', {
appId: appId,
appType: appType,
body: zipData,
@@ -256,7 +284,7 @@ HarnessClient.prototype.pushFile = function(appId, appType, payload, etag, remot
if (manifestEtag) {
query['manifestEtag'] = manifestEtag;
}
- return doRequest('PUT', this.target, '/putfile', {
+ return this.doRequest('PUT', '/putfile', {
appId: appId,
appType: appType,
body: payload,
@@ -269,7 +297,7 @@ HarnessClient.prototype.deleteFiles = function(appId, deleteList, /* optional */
if (manifestEtag) {
query['manifestEtag'] = manifestEtag;
}
- return doRequest('POST', this.target, 'deletefiles', { appId: appId, json: {'paths': deleteList}, query: query});
+ return this.doRequest('POST', 'deletefiles', { appId: appId, json: {'paths': deleteList}, query: query});
};
HarnessClient.prototype.createPushSession = function(dir) {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org
[12/13] cordova-app-harness git commit: Update HttpServer to use
chrome.sockets.tcp.pipeToFile.
Posted by ag...@apache.org.
Update HttpServer to use chrome.sockets.tcp.pipeToFile.
Project: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/commit/939fd660
Tree: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/tree/939fd660
Diff: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/diff/939fd660
Branch: refs/heads/master
Commit: 939fd660988fb4969bc7766bb3ddcabb82a14c69
Parents: ba347fd
Author: Andrew Grieve <ag...@chromium.org>
Authored: Tue Nov 25 15:59:01 2014 -0500
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Wed Dec 31 00:51:24 2014 -0500
----------------------------------------------------------------------
www/cdvah/js/HttpServer.js | 60 ++++++++++++++++++++++++++---------------
1 file changed, 38 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/939fd660/www/cdvah/js/HttpServer.js
----------------------------------------------------------------------
diff --git a/www/cdvah/js/HttpServer.js b/www/cdvah/js/HttpServer.js
index dd773e6..b6571e1 100644
--- a/www/cdvah/js/HttpServer.js
+++ b/www/cdvah/js/HttpServer.js
@@ -37,7 +37,11 @@
chrome.sockets.tcp.onReceive.addListener(function(receiveInfo) {
if (HttpServer.VERBOSE_LOGGING) {
- console.log('read on socket ' + receiveInfo.socketId + ' of len=' + (receiveInfo.data && receiveInfo.data.byteLength));
+ if (receiveInfo.data) {
+ console.log('read on socket ' + receiveInfo.socketId + ' of len=' + receiveInfo.data.byteLength);
+ } else {
+ console.log('piped read on socket ' + receiveInfo.socketId + ' of len=' + receiveInfo.bytesRead);
+ }
}
var socket = socketMap[receiveInfo.socketId];
if (socket) {
@@ -142,17 +146,9 @@
var deferred = $q.defer();
// Only way to get a null arrayBuffer is when flushReadQueue() has been called.
if (!arrayBuffer) {
- // TODO: Change this to pass in self.bytesRemaining.
- return self._requestData.socket.pipeToUri(uri, true)
+ return self._requestData.socket.pipeToUri(uri, self.bytesRemaining, true)
.then(null, null, function(numBytesRead) {
- if (HttpServer.VERBOSE_LOGGING) {
- console.log('Piped chunk of size ' + numBytesRead);
- }
self._updateBytesRemaining(numBytesRead);
- if (self.bytesRemaining === 0) {
- // TODO: Delete stopPipeToFile() once pipeToUrl takes in a byteCount.
- self._requestData.socket.stopPipeToFile();
- }
});
}
fileWriter.onwrite = deferred.resolve;
@@ -371,6 +367,8 @@
chrome.sockets.tcp.close(this.socketId);
if (this.onClose) {
this.onClose(error);
+ } else if (error) {
+ console.warn(error);
}
}
if (this._pendingReadDeferred) {
@@ -393,7 +391,7 @@
return deferred.promise;
};
- Socket.prototype.pipeToUri = function(uri, append) {
+ Socket.prototype.pipeToUri = function(uri, numBytes, append) {
if (this._pendingReadDeferred) {
throw new Error('socket.pipeToUri() called during bad state.');
}
@@ -403,17 +401,16 @@
if (this._pendingReadChunks.length) {
throw new Error('socket.pipeToUri() called when there are outstanding read chunks.');
}
- this._pendingPipeToFileDeferred = $q.defer();
- chrome.sockets.tcp.update(this.socketId, { destUri: uri, append: append });
+ var deferred = $q.defer();
+ this._pendingPipeToFileDeferred = deferred;
+ var self = this;
+ chrome.sockets.tcp.pipeToFile(this.socketId, { uri: uri, append: append, numBytes: numBytes}, function() {
+ self._pendingPipeToFileDeferred = null;
+ deferred.resolve();
+ });
// TODO: The sockets call to initiate piping should unpause automatically.
this._setPaused(false);
- return this._pendingPipeToFileDeferred.promise;
- };
-
- Socket.prototype.stopPipeToFile = function() {
- var deferred = this._pendingPipeToFileDeferred;
- this._pendingPipeToFileDeferred = null;
- chrome.sockets.tcp.update(this.socketId, { destUri: '' }, deferred.resolve);
+ return deferred.promise;
};
Socket.prototype._setPaused = function(value) {
@@ -437,7 +434,15 @@
};
Socket.prototype._onReceiveError = function(resultCode) {
- var err = new Error('Socket.read() failed with code ' + resultCode);
+ var desc = (chrome.runtime.lastError && chrome.runtime.lastError.message);
+ var msg;
+ if (this._pendingReadDeferred) {
+ msg = 'Socket.read() failed with code ' + resultCode + ' reason: ' + desc;
+ } else {
+ msg = 'Socket closed because: ' + desc + ' (code=' + resultCode + ')';
+ }
+ var err = new Error(msg);
+ err.resultCode = resultCode;
this.close(err);
};
@@ -470,7 +475,7 @@
});
} else {
if (HttpServer.VERBOSE_LOGGING) {
- console.log('not sending chunk of len=' + arrayBuffer);
+ console.log('not sending chunk of len=' + (arrayBuffer && arrayBuffer.byteLength));
}
this._writeQueue.shift();
this._writeQueue.shift();
@@ -548,6 +553,17 @@
};
this._requests[socket.socketId] = requestData;
var self = this;
+ socket.onClose = function(err) {
+ // -2 means closed by remote side.
+ if (err && err.resultCode == -2 && requestData.state === STATE_NEW) {
+ if (HttpServer.VERBOSE_LOGGING) {
+ console.log('Socket ' + socket.socketId + ' closed by remote peer');
+ }
+ } else if (err) {
+ console.warn('Socket ' + socket.socketId + ': ' + err);
+ }
+ delete self._requests[socket.socketId];
+ };
return readRequestHeaders(requestData)
.then(function() {
var req = new HttpRequest(requestData);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org
[08/13] cordova-app-harness git commit: Fix appharness.reload() not
calling success callback on iOS
Posted by ag...@apache.org.
Fix appharness.reload() not calling success callback on iOS
Was causing /launch to never send a response.
Project: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/commit/e1a60693
Tree: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/tree/e1a60693
Diff: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/diff/e1a60693
Branch: refs/heads/master
Commit: e1a60693aaf6d9f6c1e55a8c6747e7d9827471e9
Parents: 1f58b1c
Author: Andrew Grieve <ag...@chromium.org>
Authored: Thu Nov 13 13:19:46 2014 +0100
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Wed Dec 31 00:49:01 2014 -0500
----------------------------------------------------------------------
AppHarnessUI/AppHarnessUI.m | 2 ++
1 file changed, 2 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/e1a60693/AppHarnessUI/AppHarnessUI.m
----------------------------------------------------------------------
diff --git a/AppHarnessUI/AppHarnessUI.m b/AppHarnessUI/AppHarnessUI.m
index 006f2c1..38c660f 100644
--- a/AppHarnessUI/AppHarnessUI.m
+++ b/AppHarnessUI/AppHarnessUI.m
@@ -138,6 +138,8 @@
NSURLRequest *requestObj = [NSURLRequest requestWithURL:urlObj];
[[_slaveCordovaViewController webView] loadRequest:requestObj];
}
+ CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
- (void)destroy:(CDVInvokedUrlCommand*)command {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org
[13/13] cordova-app-harness git commit: Fix typo in error message
(chrome-app-developer-tool-client -> harness-client)
Posted by ag...@apache.org.
Fix typo in error message (chrome-app-developer-tool-client -> harness-client)
Project: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/commit/a35f398d
Tree: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/tree/a35f398d
Diff: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/diff/a35f398d
Branch: refs/heads/master
Commit: a35f398dce4077303c0ea0a543619e5633518792
Parents: 939fd66
Author: Andrew Grieve <ag...@chromium.org>
Authored: Wed Dec 31 00:54:55 2014 -0500
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Wed Dec 31 00:55:32 2014 -0500
----------------------------------------------------------------------
harness-push/harness-push.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/a35f398d/harness-push/harness-push.js
----------------------------------------------------------------------
diff --git a/harness-push/harness-push.js b/harness-push/harness-push.js
index eae3168..4f07695 100755
--- a/harness-push/harness-push.js
+++ b/harness-push/harness-push.js
@@ -29,7 +29,7 @@ try {
var HarnessClient = require('cordova-harness-client');
} catch (e) {
console.log('Please run: ( cd ' +
- path.join(__dirname, 'node_modules', 'chrome-app-developer-tool-client') +
+ path.join(__dirname, 'node_modules', 'cordova-harness-client') +
' && npm install )');
process.exit(1);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org
[07/13] cordova-app-harness git commit: Make gulpfile use
windows-compatible paths
Posted by ag...@apache.org.
Make gulpfile use windows-compatible paths
Project: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/commit/1f58b1c2
Tree: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/tree/1f58b1c2
Diff: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/diff/1f58b1c2
Branch: refs/heads/master
Commit: 1f58b1c27dfc04551078d88371e333762ab1072e
Parents: eb79102
Author: Andrew Grieve <ag...@chromium.org>
Authored: Sat Nov 8 21:07:20 2014 +0100
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Wed Dec 31 00:48:42 2014 -0500
----------------------------------------------------------------------
gulpfile.js | 27 ++++++++++++++++++++++++---
1 file changed, 24 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/1f58b1c2/gulpfile.js
----------------------------------------------------------------------
diff --git a/gulpfile.js b/gulpfile.js
index 0ecc709..fadf04d 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -1,5 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
var gulp = require('gulp');
var jshint = require('gulp-jshint');
+var path = require('path');
/******************************************************************************/
/******************************************************************************/
@@ -8,7 +29,7 @@ gulp.task('default', ['lint']);
gulp.task('watch', ['lint'], function() {
gulp.watch([
- 'www/**/*',
+ path.join('www', '**', '*'),
], ['lint']);
});
@@ -18,14 +39,14 @@ gulp.task('lint', ['lint:app', 'lint:harness-push']);
/******************************************************************************/
gulp.task('lint:app', function() {
- return gulp.src(['www/**/*.js', '!www/cdvah/js/libs/*.js'])
+ return gulp.src([path.join('www', '**', '*.js'), path.join('!www', 'cdvah', 'js', 'libs', '*.js')])
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(jshint.reporter('fail'));
});
gulp.task('lint:harness-push', function() {
- return gulp.src(['harness-push/*.js', 'harness-push/node_modules/cordova-harness-client/*.js'])
+ return gulp.src([path.join('harness-push', '*.js'), path.join('harness-push', 'node_modules', 'cordova-harness-client', '*.js')])
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(jshint.reporter('fail'));
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org