Comments (3)
caused by the follwing line:
Line 475 in b896f54
from norm.
Setting the tx_pending_path[0] = '\0' is used to indicate there is no pending transmit file. The TxFilePending() method is checked before EnqueueFileObject() is called when it returns false, EnqueueFileObject() should not be called. So I am not sure how this problem is occurring. I am investigating it further.
from norm.
The C++17 std::filesystem provides much eacher way to iterate dir:
#include <iostream>
#include <string>
#include <filesystem> // C++ 17
#include "normApi.h"
namespace fs = std::filesystem;
// find first normal file
bool fileEnqueue(NormSessionHandle session, fs::recursive_directory_iterator& itEntry)
{
while (itEntry != fs::recursive_directory_iterator()) {
if (!itEntry->is_regular_file()) {
++itEntry;
continue;
};
const auto filePathStr = itEntry->path().string(); //.filename().string();
auto info = std::string(filePathStr);
std::replace(info.begin(), info.end(), '\\', '/');
NormObjectHandle objHandler = NormFileEnqueue(session, filePathStr.c_str(), info.c_str(), info.length());
if (objHandler != NORM_OBJECT_INVALID) {
std::cout << "push:" << filePathStr<<std::endl;
};
++itEntry;
return true;
}
return false;
}
NormSessionHandle create_Session(NormInstanceHandle normInstance, fs::recursive_directory_iterator& itEntry, const char* addr, uint16_t port, const char* localAddr, NormNodeId localID) {
auto session = NormCreateSession(normInstance, addr, port, localID);
NormSetTxPort(session, 0, true, localAddr);
NormSetTxOnly(session, true);
NormSetCongestionControl(session, true);
//NormSetTxRateBounds
NormSessionId instanceId = NormGetRandomSessionId();
NormStartSender(session, 1, 100 * 1024 * 1024, 1400, 128, 0);
//auto& dirEntry : std::filesystem::recursive_directory_iterator(path)
fileEnqueue(session, itEntry);
return session;
}
int main()
{
NormInstanceHandle normInstance = NormCreateInstance();
NormSetDebugLevel(3);
uint16_t port = 6003;
int localID = 191;
auto localAddr = "10.65.39.191";
auto addr = "224.1.2.3";
const char* dirPath = "E:\\PythonPrj\\sendFiles\\ch1"; //Change this to real dir
auto itEntry = fs::recursive_directory_iterator(dirPath);
auto session1 = create_Session(normInstance, itEntry, addr, port, localAddr, localID);
auto addr2 = "224.1.2.4";
const char* dirPath2 = "E:\\PythonPrj\\sendFiles\\ch2"; //Change this to real dir
auto itEntry2 = fs::recursive_directory_iterator(dirPath2);
auto session2 = create_Session(normInstance, itEntry2, addr2, port, localAddr, localID);
char buffer[512];
bool success = false;
bool keepGoing = true;
int count1 = 0;
int count2 = 0;
NormEvent theEvent =NormEvent();
while (keepGoing)
{
auto session = theEvent.session;
if (!NormGetNextEvent(normInstance, &theEvent)) continue;
switch (theEvent.type)
{
case NORM_TX_QUEUE_EMPTY:
if (theEvent.session == session1)
{
fileEnqueue(session, itEntry);
}
else if (theEvent.session == session2)
{
fileEnqueue(session, itEntry2);
};
break;
case NORM_TX_OBJECT_PURGED:
success = NormFileGetName(theEvent.object, buffer, sizeof(buffer));
if (success) {
fs::remove(fs::path(buffer) ); //remove file
}
else
{
std::cout << "xxx"<<std::endl;
}
if (theEvent.session == session1) {
++count1;
}
else if (theEvent.session == session2)
{
++count2;
}
std::cerr << "count1:" << count1 << " count2:" << count2 << std::endl;
if (theEvent.session == session1)
{
fileEnqueue(session, itEntry);
}
else if (theEvent.session == session2)
{
fileEnqueue(session, itEntry2);
};
break;
//case NORM_TX_FLUSH_COMPLETED:
// std::cerr << "normFileSend: NORM_TX_FLUSH_COMPLETED event ...\n";
// keepGoing = false; // our file has been sent (we think)
// break;
default:
std::cerr <<"type:"<< theEvent.type<<std::endl;
} // end switch(theEvent.type)
} // end while (NormGetNextEvent())
NormStopSender(session1);
NormDestroySession(session1);
NormStopSender(session2);
NormDestroySession(session2);
NormDestroyInstance(normInstance);
//listFiles("E:\\PythonPrj\\NORM\\norm159\\examples");
return 0;
}
from norm.
Related Issues (20)
- norm 1.5.9 python binding failure HOT 4
- norm 1.5.9 python binding of setRxPortReuse session's method seems not to work HOT 1
- norm 1.5.9 fatal error with the python binding of session's method fileEnqueue HOT 1
- Segmentation fault (normObject.cpp) HOT 1
- Receiving File and writing to mounted share is slow HOT 10
- Suggestion: Make pynorm work with Python3 HOT 3
- debugStats.py: No module named 'pynorm.extra.pipeparser' HOT 2
- add arguments `txBindAddress` back to pynorm Session.setTxPort HOT 1
- Suggestion: Use Python enum in pynorm/constants.py
- function `setTxOnly` missed in pynorm/session.py
- function `NormChangeDestination` missed in pynorm and NormDeveloperGuide
- Question:how to get the status of each sender session? HOT 2
- the fairness among multiple sender sessions. HOT 6
- NormRestartInstance cause ASSERT INVALID_DESCRIPTOR error HOT 4
- ProtoTree x->right ==x Caused infinite loop HOT 41
- NormStreamSend Java Example Does Not Compile HOT 2
- NormObjectTable::Remove(NormObject*): Assertion `__null != tree.Find(theObject->GetId().GetValuePtr(), 8*sizeof(UINT16))' failed HOT 3
- 2 compiler warnings seem to indicate errors HOT 1
- Suggestion: .NET NORM Extension HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from norm.