Skip to content

Commit 9558773

Browse files
Modify transfer context
1 parent 3e4476a commit 9558773

File tree

4 files changed

+29
-19
lines changed

4 files changed

+29
-19
lines changed

dist/addon.node

2 KB
Binary file not shown.

include/sync_root_interface/TransferContext.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
#include <string>
77
#include "stdafx.h"
88
#include <cfapi.h>
9-
#include "Logger.h"
109
#include "Utilities.h"
1110
#include "Placeholders.h"
12-
#include "FileCopierWithProgress.h"
1311

14-
struct TransferContext {
12+
struct TransferContext
13+
{
1514
CF_CONNECTION_KEY connectionKey;
1615
CF_TRANSFER_KEY transferKey;
1716
LARGE_INTEGER fileSize;
@@ -31,8 +30,6 @@ struct TransferContext {
3130
std::wstring fullServerFilePath;
3231
};
3332

34-
std::shared_ptr<TransferContext> GetOrCreateTransferContext(
35-
CF_CONNECTION_KEY connKey,
36-
CF_TRANSFER_KEY transferKey);
37-
33+
std::shared_ptr<TransferContext> CreateTransferContext(CF_TRANSFER_KEY transferKey);
34+
std::shared_ptr<TransferContext> GetTransferContext(CF_TRANSFER_KEY transferKey);
3835
void RemoveTransferContext(CF_TRANSFER_KEY transferKey);

native-src/sync_root_interface/callbacks/FetchData/FetchData.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,9 @@ void CALLBACK fetch_data_callback_wrapper(
345345
{
346346
Logger::getInstance().log("fetch_data_callback_wrapper called", LogLevel::DEBUG);
347347

348-
auto ctx = GetOrCreateTransferContext(callbackInfo->ConnectionKey, callbackInfo->TransferKey);
348+
auto ctx = GetTransferContext(callbackInfo->TransferKey);
349349

350+
ctx->connectionKey = callbackInfo->ConnectionKey;
350351
ctx->fileSize = callbackInfo->FileSize;
351352
ctx->requiredLength = callbackParameters->FetchData.RequiredLength;
352353
ctx->requiredOffset = callbackParameters->FetchData.RequiredFileOffset;
Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
#include "TransferContext.h"
1+
#include <TransferContext.h>
22

3-
struct CfTransferKeyLess {
4-
bool operator()(const CF_TRANSFER_KEY &a, const CF_TRANSFER_KEY &b) const {
3+
struct CfTransferKeyLess
4+
{
5+
bool operator()(const CF_TRANSFER_KEY &a, const CF_TRANSFER_KEY &b) const
6+
{
57
return a.QuadPart < b.QuadPart;
68
}
79
};
@@ -10,22 +12,32 @@ static std::map<CF_TRANSFER_KEY, std::shared_ptr<TransferContext>, CfTransferKey
1012

1113
static std::mutex g_contextMapMutex;
1214

13-
std::shared_ptr<TransferContext> GetOrCreateTransferContext(CF_CONNECTION_KEY connKey, CF_TRANSFER_KEY transferKey) {
15+
std::shared_ptr<TransferContext> CreateTransferContext(CF_TRANSFER_KEY transferKey)
16+
{
1417
std::lock_guard<std::mutex> lock(g_contextMapMutex);
1518

16-
auto it = g_transferContextMap.find(transferKey);
17-
if (it != g_transferContextMap.end()) {
18-
return it->second;
19-
}
20-
2119
auto ctx = std::make_shared<TransferContext>();
22-
ctx->connectionKey = connKey;
2320
ctx->transferKey = transferKey;
21+
2422
g_transferContextMap[transferKey] = ctx;
2523
return ctx;
2624
}
2725

28-
void RemoveTransferContext(CF_TRANSFER_KEY transferKey) {
26+
std::shared_ptr<TransferContext> GetTransferContext(CF_TRANSFER_KEY transferKey)
27+
{
28+
std::lock_guard<std::mutex> lock(g_contextMapMutex);
29+
30+
auto it = g_transferContextMap.find(transferKey);
31+
if (it != g_transferContextMap.end())
32+
{
33+
return it->second;
34+
}
35+
36+
return nullptr;
37+
}
38+
39+
void RemoveTransferContext(CF_TRANSFER_KEY transferKey)
40+
{
2941
std::lock_guard<std::mutex> lock(g_contextMapMutex);
3042
g_transferContextMap.erase(transferKey);
3143
}

0 commit comments

Comments
 (0)