summaryrefslogtreecommitdiff
path: root/protocols/Discord/src/gateway.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2017-01-09 01:03:17 +0300
committerGeorge Hazan <ghazan@miranda.im>2017-01-09 01:03:17 +0300
commit4f8c1e527ab9b5421f3ebb1c61ffe9a859df82e4 (patch)
treeab5bf5bec8891993939b2d4c09ce3d1feba11b96 /protocols/Discord/src/gateway.cpp
parent9ab52162d7d1e0bdbf47d412fcfe83d533f0708b (diff)
- misprint in a json field name;
- fix for parsing private channels; - fix for long gateway packets reading; - version bump
Diffstat (limited to 'protocols/Discord/src/gateway.cpp')
-rw-r--r--protocols/Discord/src/gateway.cpp23
1 files changed, 17 insertions, 6 deletions
diff --git a/protocols/Discord/src/gateway.cpp b/protocols/Discord/src/gateway.cpp
index 43c923ff00..7454383878 100644
--- a/protocols/Discord/src/gateway.cpp
+++ b/protocols/Discord/src/gateway.cpp
@@ -206,25 +206,36 @@ void CDiscordProto::GatewayThreadWorker()
// we have some additional data, not only opcode
if (bufSize > headerSize) {
- if (bIsFinal && dataBuf == NULL) { // it fits, no need to reallocate a buffer
+ if (bIsFinal && payloadSize < _countof(buf)) { // it fits, no need to reallocate a buffer
bDataBufAllocated = false;
dataBuf = (char*)buf + headerSize;
dataBufSize = bufSize - headerSize;
}
else {
bDataBufAllocated = true;
- size_t newSize = dataBufSize + bufSize - headerSize;
+ size_t newSize = dataBufSize + payloadSize;
+ size_t currPacketSize = bufSize - headerSize;
dataBuf = (char*)mir_realloc(dataBuf, newSize+1);
- memcpy(dataBuf + dataBufSize, buf + headerSize, bufSize - headerSize);
+ memcpy(dataBuf + dataBufSize, buf + headerSize, currPacketSize);
+ while (currPacketSize < payloadSize) {
+ int result = Netlib_Recv(m_hGatewayConnection, dataBuf + dataBufSize + currPacketSize, int(payloadSize - currPacketSize), 0);
+ if (result == 0) {
+ debugLogA("Gateway connection gracefully closed");
+ break;
+ }
+ if (result < 0) {
+ debugLogA("Gateway connection error, exiting");
+ break;
+ }
+ currPacketSize += result;
+ }
+
dataBufSize = newSize;
debugLogA("data buffer reallocated to %d bytes", dataBufSize);
}
dataBuf[dataBufSize] = 0;
}
- if (dataBufSize < payloadSize)
- continue;
-
switch (opCode){
case 0: // text packet
case 1: // binary packet