(socket) replace a std::vector with an std::array used as a tmp buffer in Socket::readBytes
This commit is contained in:
parent
594d2e194a
commit
4e2a40e031
@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
All changes to this project will be documented in this file.
|
All changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
## [11.0.1] - 2020-11-11
|
||||||
|
|
||||||
|
(socket) replace a std::vector with an std::array used as a tmp buffer in Socket::readBytes
|
||||||
|
|
||||||
## [11.0.0] - 2020-11-11
|
## [11.0.0] - 2020-11-11
|
||||||
|
|
||||||
(openssl security fix) in the client to server connection, peer verification is not done in all cases. See https://github.com/machinezone/IXWebSocket/pull/250
|
(openssl security fix) in the client to server connection, peer verification is not done in all cases. See https://github.com/machinezone/IXWebSocket/pull/250
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include "IXSelectInterruptFactory.h"
|
#include "IXSelectInterruptFactory.h"
|
||||||
#include "IXSocketConnect.h"
|
#include "IXSocketConnect.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <array>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
@ -18,6 +19,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#ifdef min
|
#ifdef min
|
||||||
#undef min
|
#undef min
|
||||||
@ -27,7 +29,6 @@ namespace ix
|
|||||||
{
|
{
|
||||||
const int Socket::kDefaultPollNoTimeout = -1; // No poll timeout by default
|
const int Socket::kDefaultPollNoTimeout = -1; // No poll timeout by default
|
||||||
const int Socket::kDefaultPollTimeout = kDefaultPollNoTimeout;
|
const int Socket::kDefaultPollTimeout = kDefaultPollNoTimeout;
|
||||||
constexpr size_t Socket::kChunkSize;
|
|
||||||
|
|
||||||
Socket::Socket(int fd)
|
Socket::Socket(int fd)
|
||||||
: _sockfd(fd)
|
: _sockfd(fd)
|
||||||
@ -364,10 +365,7 @@ namespace ix
|
|||||||
const OnProgressCallback& onProgressCallback,
|
const OnProgressCallback& onProgressCallback,
|
||||||
const CancellationRequest& isCancellationRequested)
|
const CancellationRequest& isCancellationRequested)
|
||||||
{
|
{
|
||||||
if (_readBuffer.empty())
|
std::array<uint8_t, 1 << 14> readBuffer;
|
||||||
{
|
|
||||||
_readBuffer.resize(kChunkSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<uint8_t> output;
|
std::vector<uint8_t> output;
|
||||||
while (output.size() != length)
|
while (output.size() != length)
|
||||||
@ -378,12 +376,12 @@ namespace ix
|
|||||||
return std::make_pair(false, errorMsg);
|
return std::make_pair(false, errorMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t size = std::min(kChunkSize, length - output.size());
|
size_t size = std::min(readBuffer.size(), length - output.size());
|
||||||
ssize_t ret = recv((char*) &_readBuffer[0], size);
|
ssize_t ret = recv((char*) &readBuffer[0], size);
|
||||||
|
|
||||||
if (ret > 0)
|
if (ret > 0)
|
||||||
{
|
{
|
||||||
output.insert(output.end(), _readBuffer.begin(), _readBuffer.begin() + ret);
|
output.insert(output.end(), readBuffer.begin(), readBuffer.begin() + ret);
|
||||||
}
|
}
|
||||||
else if (ret <= 0 && !Socket::isWaitNeeded())
|
else if (ret <= 0 && !Socket::isWaitNeeded())
|
||||||
{
|
{
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <BaseTsd.h>
|
#include <BaseTsd.h>
|
||||||
@ -102,10 +101,6 @@ namespace ix
|
|||||||
static const int kDefaultPollTimeout;
|
static const int kDefaultPollTimeout;
|
||||||
static const int kDefaultPollNoTimeout;
|
static const int kDefaultPollNoTimeout;
|
||||||
|
|
||||||
// Buffer for reading from our socket. That buffer is never resized.
|
|
||||||
std::vector<uint8_t> _readBuffer;
|
|
||||||
static constexpr size_t kChunkSize = 1 << 15;
|
|
||||||
|
|
||||||
SelectInterruptPtr _selectInterrupt;
|
SelectInterruptPtr _selectInterrupt;
|
||||||
};
|
};
|
||||||
} // namespace ix
|
} // namespace ix
|
||||||
|
@ -6,4 +6,4 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define IX_WEBSOCKET_VERSION "11.0.0"
|
#define IX_WEBSOCKET_VERSION "11.0.1"
|
||||||
|
Loading…
Reference in New Issue
Block a user