(socket) selectInterrupt member is an unique_ptr instead of being a shared_ptr

This commit is contained in:
Benjamin Sergeant 2020-03-24 10:00:41 -07:00
parent 9dcc2538ae
commit 9f818c7acf
9 changed files with 20 additions and 14 deletions

View File

@ -5,7 +5,3 @@ repos:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
# - repo: https://github.com/pocc/pre-commit-hooks
# rev: master
# hooks:
# - id: clang-format

View File

@ -1,6 +1,10 @@
# Changelog
All changes to this project will be documented in this file.
## [9.0.1] - 2020-03-24
(socket) selectInterrupt member is an unique_ptr instead of being a shared_ptr
## [9.0.0] - 2020-03-23
(websocket) reset per-message deflate codec everytime we connect to a server/client

View File

@ -14,12 +14,12 @@
namespace ix
{
std::shared_ptr<SelectInterrupt> createSelectInterrupt()
SelectInterruptPtr createSelectInterrupt()
{
#if defined(__linux__) || defined(__APPLE__)
return std::make_shared<SelectInterruptPipe>();
return std::make_unique<SelectInterruptPipe>();
#else
return std::make_shared<SelectInterrupt>();
return std::make_unique<SelectInterrupt>();
#endif
}
} // namespace ix

View File

@ -11,5 +11,6 @@
namespace ix
{
class SelectInterrupt;
std::shared_ptr<SelectInterrupt> createSelectInterrupt();
using SelectInterruptPtr = std::unique_ptr<SelectInterrupt>;
SelectInterruptPtr createSelectInterrupt();
} // namespace ix

View File

@ -46,7 +46,7 @@ namespace ix
PollResultType Socket::poll(bool readyToRead,
int timeoutMs,
int sockfd,
std::shared_ptr<SelectInterrupt> selectInterrupt)
const SelectInterruptPtr& selectInterrupt)
{
//
// We used to use ::select to poll but on Android 9 we get large fds out of

View File

@ -38,6 +38,7 @@ typedef SSIZE_T ssize_t;
namespace ix
{
class SelectInterrupt;
using SelectInterruptPtr = std::unique_ptr<SelectInterrupt>;
enum class PollResultType
{
@ -93,7 +94,7 @@ namespace ix
static PollResultType poll(bool readyToRead,
int timeoutMs,
int sockfd,
std::shared_ptr<SelectInterrupt> selectInterrupt = nullptr);
const SelectInterruptPtr& selectInterrupt);
// Used as special codes for pipe communication
@ -112,6 +113,6 @@ namespace ix
std::vector<uint8_t> _readBuffer;
static constexpr size_t kChunkSize = 1 << 15;
std::shared_ptr<SelectInterrupt> _selectInterrupt;
SelectInterruptPtr _selectInterrupt;
};
} // namespace ix

View File

@ -9,6 +9,7 @@
#include "IXDNSLookup.h"
#include "IXNetSystem.h"
#include "IXSocket.h"
#include "IXSelectInterrupt.h"
#include <fcntl.h>
#include <string.h>
#include <sys/types.h>
@ -64,7 +65,8 @@ namespace ix
int timeoutMs = 10;
bool readyToRead = false;
PollResultType pollResult = Socket::poll(readyToRead, timeoutMs, fd);
auto selectInterrupt = std::make_unique<SelectInterrupt>();
PollResultType pollResult = Socket::poll(readyToRead, timeoutMs, fd, selectInterrupt);
if (pollResult == PollResultType::Timeout)
{

View File

@ -11,6 +11,7 @@
#include "IXSocket.h"
#include "IXSocketConnect.h"
#include "IXSocketFactory.h"
#include "IXSelectInterrupt.h"
#include <assert.h>
#include <sstream>
#include <stdio.h>
@ -257,7 +258,8 @@ namespace ix
// Use poll to check whether a new connection is in progress
int timeoutMs = 10;
bool readyToRead = true;
PollResultType pollResult = Socket::poll(readyToRead, timeoutMs, _serverFd);
auto selectInterrupt = std::make_unique<SelectInterrupt>();
PollResultType pollResult = Socket::poll(readyToRead, timeoutMs, _serverFd, selectInterrupt);
if (pollResult == PollResultType::Error)
{

View File

@ -6,4 +6,4 @@
#pragma once
#define IX_WEBSOCKET_VERSION "9.0.0"
#define IX_WEBSOCKET_VERSION "9.0.1"