Fix websocket bugs
This commit is contained in:
parent
414e9b5fa6
commit
8a82d988ec
File diff suppressed because it is too large
Load Diff
|
@ -438,7 +438,7 @@ std::string parseWebsockFrame(trantor::MsgBuffer *buffer)
|
|||
if(buffer->readableBytes()>=2)
|
||||
{
|
||||
auto secondByte=(*buffer)[1];
|
||||
unsigned int length=secondByte & 127;
|
||||
size_t length=secondByte & 127;
|
||||
int isMasked=(secondByte & 0x80);
|
||||
if(isMasked!=0)
|
||||
{
|
||||
|
@ -459,18 +459,22 @@ std::string parseWebsockFrame(trantor::MsgBuffer *buffer)
|
|||
{
|
||||
if(indexFirstMask==4)
|
||||
{
|
||||
length=(unsigned int)(*buffer)[2];
|
||||
length=(length<<8)+(unsigned int)(*buffer)[3];
|
||||
length=(unsigned char)(*buffer)[2];
|
||||
length=(length<<8)+(unsigned char)(*buffer)[3];
|
||||
LOG_TRACE<<"bytes[2]="<<(unsigned char)(*buffer)[2];
|
||||
LOG_TRACE<<"bytes[3]="<<(unsigned char)(*buffer)[3];
|
||||
} else if(indexFirstMask==10)
|
||||
{
|
||||
length=(unsigned int)(*buffer)[2];
|
||||
length=(length<<8)+(unsigned int)(*buffer)[3];
|
||||
length=(length<<8)+(unsigned int)(*buffer)[4];
|
||||
length=(length<<8)+(unsigned int)(*buffer)[5];
|
||||
length=(length<<8)+(unsigned int)(*buffer)[6];
|
||||
length=(length<<8)+(unsigned int)(*buffer)[7];
|
||||
length=(length<<8)+(unsigned int)(*buffer)[8];
|
||||
length=(length<<8)+(unsigned int)(*buffer)[9];
|
||||
length=(unsigned char)(*buffer)[2];
|
||||
length=(length<<8)+(unsigned char)(*buffer)[3];
|
||||
length=(length<<8)+(unsigned char)(*buffer)[4];
|
||||
length=(length<<8)+(unsigned char)(*buffer)[5];
|
||||
length=(length<<8)+(unsigned char)(*buffer)[6];
|
||||
length=(length<<8)+(unsigned char)(*buffer)[7];
|
||||
length=(length<<8)+(unsigned char)(*buffer)[8];
|
||||
length=(length<<8)+(unsigned char)(*buffer)[9];
|
||||
// length=*((uint64_t *)(buffer->peek()+2));
|
||||
// length=ntohll(length);
|
||||
} else{
|
||||
assert(0);
|
||||
}
|
||||
|
@ -483,10 +487,14 @@ std::string parseWebsockFrame(trantor::MsgBuffer *buffer)
|
|||
auto rawData=buffer->peek()+indexFirstDataByte;
|
||||
std::string message;
|
||||
message.resize(length);
|
||||
LOG_TRACE<<"rawData[0]="<<(unsigned char)rawData[0];
|
||||
LOG_TRACE<<"masks[0]="<<(unsigned char)masks[0];
|
||||
for(int i=0;i<length;i++)
|
||||
{
|
||||
message[i]=(rawData[i]^masks[i%4]);
|
||||
}
|
||||
LOG_TRACE<<"message[0]="<<message[0];
|
||||
LOG_TRACE<<"message[1]="<<message[1];
|
||||
buffer->retrieve(indexFirstMask+4+length);
|
||||
LOG_TRACE<<"got message len="<<message.length();
|
||||
return message;
|
||||
|
|
|
@ -33,7 +33,8 @@ void WebSocketConnectionImpl::send(const char *msg,uint64_t len)
|
|||
bytesFormatted[1] = 126;
|
||||
bytesFormatted[2] = (( len >> 8 ) & 255);
|
||||
bytesFormatted[3] = (( len ) & 255);
|
||||
|
||||
LOG_TRACE<<"bytes[2]="<<(size_t)bytesFormatted[2];
|
||||
LOG_TRACE<<"bytes[3]="<<(size_t)bytesFormatted[3];
|
||||
indexStartRawData = 4;
|
||||
}
|
||||
else
|
||||
|
|
2
trantor
2
trantor
|
@ -1 +1 @@
|
|||
Subproject commit 4dcae2358c9362031ca759f39673eb441af00394
|
||||
Subproject commit 992b40e7eb2a73744f56d95882bfc3cd38cdc199
|
Loading…
Reference in New Issue