Skip to content

Commit 91f4835

Browse files
author
Alexandre jublot
committed
feat: added members copy methods for session store
1 parent 7c0d0ce commit 91f4835

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

include/Polymorph/Network/SessionStore.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ namespace polymorph::network
8383

8484
/////////////////////////////// METHODS /////////////////////////////////
8585
public:
86+
void copyTcpSessionsFrom(SessionStore &other);
87+
88+
void copyUdpSessionsFrom(SessionStore &other);
89+
90+
void copyTcpAuthorizationKeysFrom(SessionStore &other);
91+
92+
void copyUdpAuthorizationKeysFrom(SessionStore &other);
93+
8694
/**
8795
* @brief Register a client with a specific sessionId from an endpoint (UDP)
8896
* @throws UnauthorizedException if the authorization key is not valid

src/src/SessionStore.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,43 @@ polymorph::network::SessionStore::SessionStore(const polymorph::network::Session
195195
{
196196

197197
}
198+
199+
void polymorph::network::SessionStore::copyTcpSessionsFrom(polymorph::network::SessionStore &other)
200+
{
201+
std::lock_guard<std::mutex> lock(_tcpSessionsMutex);
202+
std::lock_guard<std::mutex> lock2(other._tcpSessionsMutex);
203+
204+
std::copy_if(other._tcpSessions.begin(), other._tcpSessions.end(), std::inserter(_tcpSessions, _tcpSessions.end()), [this](auto &pair) {
205+
return !_tcpSessions.contains(pair.first);
206+
});
207+
}
208+
209+
void polymorph::network::SessionStore::copyUdpSessionsFrom(polymorph::network::SessionStore &other)
210+
{
211+
std::lock_guard<std::mutex> lock(_udpSessionsMutex);
212+
std::lock_guard<std::mutex> lock2(other._udpSessionsMutex);
213+
214+
std::copy_if(other._udpSessions.begin(), other._udpSessions.end(), std::inserter(_udpSessions, _udpSessions.end()), [this](auto &pair) {
215+
return !_udpSessions.contains(pair.first);
216+
});
217+
}
218+
219+
void polymorph::network::SessionStore::copyTcpAuthorizationKeysFrom(polymorph::network::SessionStore &other)
220+
{
221+
std::lock_guard<std::mutex> lock(_tcpSessionsAuthorizationKeysMutex);
222+
std::lock_guard<std::mutex> lock2(other._tcpSessionsAuthorizationKeysMutex);
223+
224+
std::copy_if(other._tcpSessionsAuthorizationKeys.begin(), other._tcpSessionsAuthorizationKeys.end(), std::inserter(_tcpSessionsAuthorizationKeys, _tcpSessionsAuthorizationKeys.end()), [this](auto &pair) {
225+
return !_tcpSessionsAuthorizationKeys.contains(pair.first);
226+
});
227+
}
228+
229+
void polymorph::network::SessionStore::copyUdpAuthorizationKeysFrom(polymorph::network::SessionStore &other)
230+
{
231+
std::lock_guard<std::mutex> lock(_udpSessionsAuthorizationKeysMutex);
232+
std::lock_guard<std::mutex> lock2(other._udpSessionsAuthorizationKeysMutex);
233+
234+
std::copy_if(other._udpSessionsAuthorizationKeys.begin(), other._udpSessionsAuthorizationKeys.end(), std::inserter(_udpSessionsAuthorizationKeys, _udpSessionsAuthorizationKeys.end()), [this](auto &pair) {
235+
return !_udpSessionsAuthorizationKeys.contains(pair.first);
236+
});
237+
}

0 commit comments

Comments
 (0)