Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
The Tor Project
Applications
torbutton
Commits
2764f9a0
Commit
2764f9a0
authored
May 17, 2018
by
Arthur Edelstein
Browse files
Bug 26100: Use inputStream.asyncWait instead of nsIInputStreamPump
parent
e37b97e4
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/modules/tor-control-port.js
View file @
2764f9a0
...
...
@@ -68,35 +68,26 @@ io.asyncSocketStreams = function (ipcFile, host, port) {
};
// __io.pumpInputStream(scriptableInputStream, onInputData, onError)__.
// Run an "input stream pump" that takes an input stream and
// asynchronously pumps incoming data to the onInputData callback.
// Take an input stream and asynchronously pass data to the onInputData callback.
io
.
pumpInputStream
=
function
(
inputStream
,
onInputData
,
onError
)
{
// Wrap raw inputStream with a "ScriptableInputStream" so we can read incoming data.
let
ScriptableInputStream
=
Components
.
Constructor
(
"
@mozilla.org/scriptableinputstream;1
"
,
"
nsIScriptableInputStream
"
,
"
init
"
),
scriptableInputStream
=
new
ScriptableInputStream
(
inputStream
),
// A private method to read all data available on the input stream.
readAll
=
function
()
{
return
scriptableInputStream
.
read
(
scriptableInputStream
.
available
());
},
pump
=
Cc
[
"
@mozilla.org/network/input-stream-pump;1
"
]
.
createInstance
(
Components
.
interfaces
.
nsIInputStreamPump
);
// Start the pump.
pump
.
init
(
inputStream
,
-
1
,
-
1
,
0
,
0
,
true
);
// Tell the pump to read all data whenever it is available, and pass the data
// to the onInputData callback. The first argument to asyncRead implements
// nsIStreamListener.
pump
.
asyncRead
({
onStartRequest
:
function
(
request
,
context
)
{
},
onStopRequest
:
function
(
request
,
context
,
code
)
{
},
onDataAvailable
:
function
(
request
,
context
,
stream
,
offset
,
count
)
{
try
{
onInputData
(
readAll
());
}
catch
(
error
)
{
// readAll() or onInputData(...) has thrown an error.
// Notify calling code through onError.
onError
(
error
);
}
}
},
null
);
awaitNextChunk
=
function
()
{
inputStream
.
asyncWait
({
onInputStreamReady
:
(
stream
)
=>
{
try
{
let
chunk
=
scriptableInputStream
.
read
(
scriptableInputStream
.
available
());
onInputData
(
chunk
);
awaitNextChunk
();
}
catch
(
err
)
{
onError
(
err
);
}
}
},
0
,
0
,
Services
.
tm
.
currentThread
);
};
awaitNextChunk
();
};
// __io.asyncSocket(ipcFile, host, port, onInputData, onError)__.
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment