Last active
December 18, 2015 12:39
-
-
Save fzzzy/5784043 to your computer and use it in GitHub Desktop.
possible fix for 788960
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/dom/network/src/TCPSocket.js b/dom/network/src/TCPSocket.js | |
--- a/dom/network/src/TCPSocket.js | |
+++ b/dom/network/src/TCPSocket.js | |
@@ -42,16 +42,25 @@ const BUFFER_SIZE = 65536; | |
// this file to slightly more readable explanations. | |
function createTCPError(aErrorName, aErrorType) { | |
let error = Cc["@mozilla.org/dom-error;1"] | |
.createInstance(Ci.nsIDOMDOMError); | |
error.wrappedJSObject.init(aErrorName); | |
return error; | |
} | |
+let Timer = Components.classes["@mozilla.org/timer;1"], | |
+ nsITimer = Components.interfaces.nsITimer, | |
+ TYPE_ONE_SHOT = Components.interfaces.nsITimer.TYPE_ONE_SHOT; | |
+ | |
+function next_turn(func) { | |
+ Timer.createInstance( | |
+ nsITimer | |
+ ).initWithCallback({notify: func}, 0, TYPE_ONE_SHOT); | |
+} | |
/* | |
* Debug logging function | |
*/ | |
let debug = true; | |
function LOG(msg) { | |
if (debug) | |
@@ -386,45 +395,47 @@ TCPSocket.prototype = { | |
if (this._inChild) { | |
that._socketBridge = Cc["@mozilla.org/tcp-socket-child;1"] | |
.createInstance(Ci.nsITCPSocketChild); | |
that._socketBridge.open(that, host, port, !!that._ssl, | |
that._binaryType, this.useWin, this.useWin || this); | |
return that; | |
} | |
- let transport = that._transport = this._createTransport(host, port, that._ssl); | |
- transport.setEventSink(that, Services.tm.currentThread); | |
+ next_turn(function() { | |
+ let transport = that._transport = that._createTransport(host, port, that._ssl); | |
+ transport.setEventSink(that, Services.tm.currentThread); | |
- that._socketInputStream = transport.openInputStream(0, 0, 0); | |
- that._socketOutputStream = transport.openOutputStream( | |
- Ci.nsITransport.OPEN_UNBUFFERED, 0, 0); | |
+ that._socketInputStream = transport.openInputStream(0, 0, 0); | |
+ that._socketOutputStream = transport.openOutputStream( | |
+ Ci.nsITransport.OPEN_UNBUFFERED, 0, 0); | |
- // If the other side is not listening, we will | |
- // get an onInputStreamReady callback where available | |
- // raises to indicate the connection was refused. | |
- that._socketInputStream.asyncWait( | |
- that, that._socketInputStream.WAIT_CLOSURE_ONLY, 0, Services.tm.currentThread); | |
+ // If the other side is not listening, we will | |
+ // get an onInputStreamReady callback where available | |
+ // raises to indicate the connection was refused. | |
+ that._socketInputStream.asyncWait( | |
+ that, that._socketInputStream.WAIT_CLOSURE_ONLY, 0, Services.tm.currentThread); | |
- if (that._binaryType === "arraybuffer") { | |
- that._inputStreamBinary = new BinaryInputStream(that._socketInputStream); | |
- } else { | |
- that._inputStreamScriptable = new ScriptableInputStream(that._socketInputStream); | |
- } | |
+ if (that._binaryType === "arraybuffer") { | |
+ that._inputStreamBinary = new BinaryInputStream(that._socketInputStream); | |
+ } else { | |
+ that._inputStreamScriptable = new ScriptableInputStream(that._socketInputStream); | |
+ } | |
- that._multiplexStream = new MultiplexInputStream(); | |
+ that._multiplexStream = new MultiplexInputStream(); | |
- that._multiplexStreamCopier = new AsyncStreamCopier( | |
- that._multiplexStream, | |
- that._socketOutputStream, | |
- // (nsSocketTransport uses gSocketTransportService) | |
- Cc["@mozilla.org/network/socket-transport-service;1"] | |
- .getService(Ci.nsIEventTarget), | |
- /* source buffered */ true, /* sink buffered */ false, | |
- BUFFER_SIZE, /* close source*/ false, /* close sink */ false); | |
+ that._multiplexStreamCopier = new AsyncStreamCopier( | |
+ that._multiplexStream, | |
+ that._socketOutputStream, | |
+ // (nsSocketTransport uses gSocketTransportService) | |
+ Cc["@mozilla.org/network/socket-transport-service;1"] | |
+ .getService(Ci.nsIEventTarget), | |
+ /* source buffered */ true, /* sink buffered */ false, | |
+ BUFFER_SIZE, /* close source*/ false, /* close sink */ false); | |
+ }); | |
return that; | |
}, | |
close: function ts_close() { | |
if (this._readyState === kCLOSED || this._readyState === kCLOSING) | |
return; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment