0

最近在chrome、firefox、opera上测试了一个原生消息协议的扩展,有个问题就是在我们的平台上特制的NativeApp总是崩溃。

在调试时,我发现应用程序会崩溃并记录:“错误:只能读取 0。” 在来自扩展的消息的特殊大小中。

通过循环测试demo,当发送给应用的json消息大小为282B,538B,794B,1050B,1306B,1562B,1818B,2074B...

这是在消息之前读取包含消息长度的 32 位值的函数。

int InputParser::readMessageLengthFromStream() {
int result = 0;
char size[sizeof (int)];
CString str = "";
inputStream.read(size, sizeof (int));

//check the input
if (inputStream){
    Dlog("All characters read successfully!");
}
else{
    Dlog("error: only %d could be read.",inputStream.gcount());
    return -1;
}

for (int n = sizeof (int) - 1; n >= 0; n--) {
    result = (result << 8) + (unsigned char)size[n];
}
return result;
}

你有同样的问题吗?

有什么解决方案可以解决吗?

4

0 回答 0