Hi team,
I met data receiving exception with nsIScriptableInputStream and socket-transport-service against FF ESR 68.
socket-transport-service can SEND message successfully, but exception when access stream with nsIScriptableInputStream.
We use socket-transport-service to communicate between windows service and FF extension, nsIScriptableInputStream to read stream.
It is XPCOM technology, not available in latest FF, but It’s large amount of work for us to port web extension, we need long time to finish it, is there any workaround?
Exception details:
message: “Component returned failure code: 0x80004001 (NS_ERROR_NOT_IMPLEMENTED) [nsIBufferedInputStream.data]”
name: “NS_ERROR_NOT_IMPLEMENTED”
result: 2147500033
stack: “propertyValue@resource://devtools/server/actors/object.js:586:18\nhandler@resource://devtools/shared/protocol.js:1221:37\nonPacket@resource://devtools/server/main.js:1395:58\nsend/<@resource://devtools/shared/transport/local-transport.js:70:25\nexports.makeInfallible/<@resource://devtools/shared/ThreadSafeDevToolsUtils.js:111:22\nexports.makeInfallible/<@resource://devtools/shared/ThreadSafeDevToolsUtils.js:111:22\n”
Source code:
var port = 7979;
var transportService = Components.classes["@mozilla.org/network/socket-transport-service;1"].getService(Components.interfaces.nsISocketTransportService);
var transport = transportService.createTransport([], 0, 'localhost', port, null);
// output stream works!
var osTemp = transport.openOutputStream(1,512,0);
var osConverter = Components.classes["@mozilla.org/intl/converter-output-stream;1"].createInstance(Components.interfaces.nsIConverterOutputStream);
osConverter.init(osTemp, "utf8", 512, null);
// input stream fails!
var stream = transport.openInputStream(0,0,0);
var instream = Components.classes["@mozilla.org/scriptableinputstream;1"].createInstance(Components.interfaces.nsIScriptableInputStream);
instream.init(stream);
var dataListener = {
converter: Components.classes["@mozilla.org/intl/scriptableunicodeconverter"]
.createInstance(Components.interfaces.nsIScriptableUnicodeConverter),
data : "",
onStartRequest: function(request, context){console.log("START DATA REQUEST.....");},
onStopRequest: function(request, context, status){
console.log("STATUS:" + status);
},
onDataAvailable: function(request, context, inputStream, offset, count){
this.converter.charset = "utf8";
console.log("COUNT: " + count);
this.data += instream.read(count);
var i = this.data.indexOf("\r\n");
while (i >= 0) {
var message = this.data.substring(0, i);
message = this.converter.ConvertToUnicode(message);
console.log(message);
this.data = this.data.substring(i + 2, this.data.length);
i = this.data.indexOf("\r\n");
}
},
};
var pump = Components.classes["@mozilla.org/network/input-stream-pump;1"].createInstance(Components.interfaces.nsIInputStreamPump);
pump.init(stream, 0, 0, true);
pump.asyncRead(dataListener,null);