(socket server) add a callback to the ConnectionState to be invoked when the connection is terminated. This will be used by the SocketServer in the future to know on time that the associated connection thread can be terminated.
This commit is contained in:
parent
261095fa12
commit
785842de03
@ -2,6 +2,10 @@
|
||||
|
||||
All changes to this project will be documented in this file.
|
||||
|
||||
## [10.2.2] - 2020-08-15
|
||||
|
||||
(socket server) add a callback to the ConnectionState to be invoked when the connection is terminated. This will be used by the SocketServer in the future to know on time that the associated connection thread can be terminated.
|
||||
|
||||
## [10.2.1] - 2020-08-15
|
||||
|
||||
(socket server) do not create a select interrupt object everytime when polling for notifications while waiting for new connections, instead use a persistent one which is a member variable
|
||||
|
@ -31,6 +31,11 @@ namespace ix
|
||||
return std::make_shared<ConnectionState>();
|
||||
}
|
||||
|
||||
void ConnectionState::setOnSetTerminatedCallback(const OnSetTerminatedCallback& callback)
|
||||
{
|
||||
_onSetTerminatedCallback = callback;
|
||||
}
|
||||
|
||||
bool ConnectionState::isTerminated() const
|
||||
{
|
||||
return _terminated;
|
||||
@ -39,5 +44,10 @@ namespace ix
|
||||
void ConnectionState::setTerminated()
|
||||
{
|
||||
_terminated = true;
|
||||
|
||||
if (_onSetTerminatedCallback)
|
||||
{
|
||||
_onSetTerminatedCallback();
|
||||
}
|
||||
}
|
||||
} // namespace ix
|
||||
|
@ -7,12 +7,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
|
||||
namespace ix
|
||||
{
|
||||
using OnSetTerminatedCallback = std::function<void()>;
|
||||
|
||||
class ConnectionState
|
||||
{
|
||||
public:
|
||||
@ -27,10 +30,16 @@ namespace ix
|
||||
|
||||
static std::shared_ptr<ConnectionState> createConnectionState();
|
||||
|
||||
private:
|
||||
void setOnSetTerminatedCallback(const OnSetTerminatedCallback& callback);
|
||||
|
||||
protected:
|
||||
std::atomic<bool> _terminated;
|
||||
std::string _id;
|
||||
OnSetTerminatedCallback _onSetTerminatedCallback;
|
||||
|
||||
static std::atomic<uint64_t> _globalId;
|
||||
|
||||
friend class SocketServer;
|
||||
};
|
||||
} // namespace ix
|
||||
|
@ -8,11 +8,11 @@
|
||||
|
||||
#include "IXNetSystem.h"
|
||||
#include "IXSelectInterrupt.h"
|
||||
#include "IXSelectInterruptFactory.h"
|
||||
#include "IXSetThreadName.h"
|
||||
#include "IXSocket.h"
|
||||
#include "IXSocketConnect.h"
|
||||
#include "IXSocketFactory.h"
|
||||
#include "IXSelectInterruptFactory.h"
|
||||
#include <assert.h>
|
||||
#include <sstream>
|
||||
#include <stdio.h>
|
||||
@ -259,7 +259,7 @@ namespace ix
|
||||
if (_stop) return;
|
||||
|
||||
// Use poll to check whether a new connection is in progress
|
||||
int timeoutMs = 10;
|
||||
int timeoutMs = 10000;
|
||||
bool readyToRead = true;
|
||||
PollResultType pollResult =
|
||||
Socket::poll(readyToRead, timeoutMs, _serverFd, _acceptSelectInterrupt);
|
||||
@ -355,6 +355,7 @@ namespace ix
|
||||
{
|
||||
connectionState = _connectionStateFactory();
|
||||
}
|
||||
connectionState->setOnSetTerminatedCallback([this] { onSetTerminatedCallback(); });
|
||||
|
||||
if (_stop) return;
|
||||
|
||||
@ -423,4 +424,9 @@ namespace ix
|
||||
{
|
||||
_socketTLSOptions = socketTLSOptions;
|
||||
}
|
||||
|
||||
void SocketServer::onSetTerminatedCallback()
|
||||
{
|
||||
;
|
||||
}
|
||||
} // namespace ix
|
||||
|
@ -85,6 +85,7 @@ namespace ix
|
||||
// background thread to wait for incoming connections
|
||||
std::thread _thread;
|
||||
void run();
|
||||
void onSetTerminatedCallback();
|
||||
|
||||
// background thread to cleanup (join) terminated threads
|
||||
std::atomic<bool> _stopGc;
|
||||
|
@ -6,4 +6,4 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#define IX_WEBSOCKET_VERSION "10.2.2"
|
||||
#define IX_WEBSOCKET_VERSION "10.2.3"
|
||||
|
Loading…
x
Reference in New Issue
Block a user