Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6d87851117 | |||
| 5c5f4d7d8f | |||
| ebb7628498 | |||
| 9abd4b195b | |||
| f7facd3319 |
@@ -3,6 +3,8 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <sys/statvfs.h>
|
||||||
#include <common/string.hpp>
|
#include <common/string.hpp>
|
||||||
|
|
||||||
class Utility
|
class Utility
|
||||||
@@ -16,6 +18,7 @@ class Utility
|
|||||||
static bool fmod(double dividend,double divisor);
|
static bool fmod(double dividend,double divisor);
|
||||||
static bool fmod(double dividend, double divisor,double epsilon);
|
static bool fmod(double dividend, double divisor,double epsilon);
|
||||||
static String byteCountToString(double bytesTransferred, bool perSecond = true);
|
static String byteCountToString(double bytesTransferred, bool perSecond = true);
|
||||||
|
static size_t getAvailableDiskSpace(const String &path);
|
||||||
private:
|
private:
|
||||||
static String pad(String theString,char padChar,int toLength);
|
static String pad(String theString,char padChar,int toLength);
|
||||||
static String addCommas(String& theString);
|
static String addCommas(String& theString);
|
||||||
@@ -172,4 +175,11 @@ bool Utility::fmod(double dividend, double divisor)
|
|||||||
// Check if the absolute remainder is less than epsilon
|
// Check if the absolute remainder is less than epsilon
|
||||||
return std::fabs(remainder) < epsilon;
|
return std::fabs(remainder) < epsilon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
size_t Utility::getAvailableDiskSpace(const String& path)
|
||||||
|
{
|
||||||
|
std::filesystem::space_info si = std::filesystem::space(path.str());
|
||||||
|
return si.available;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
4
sstp/.vscode/settings.json
vendored
4
sstp/.vscode/settings.json
vendored
@@ -53,6 +53,8 @@
|
|||||||
"stop_token": "cpp",
|
"stop_token": "cpp",
|
||||||
"thread": "cpp",
|
"thread": "cpp",
|
||||||
"*.tpp": "cpp",
|
"*.tpp": "cpp",
|
||||||
"csignal": "cpp"
|
"csignal": "cpp",
|
||||||
|
"codecvt": "cpp",
|
||||||
|
"iomanip": "cpp"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#include <sstp/clientsocketsender.hpp>
|
#include <sstp/clientsocketsender.hpp>
|
||||||
|
#include <common/utility.hpp>
|
||||||
|
|
||||||
/// @brief This is to provide a definition for SmartPointer
|
/// @brief This is to provide a definition for SmartPointer
|
||||||
ClientSocketSender::ClientSocketSender()
|
ClientSocketSender::ClientSocketSender()
|
||||||
@@ -69,6 +70,7 @@ bool ClientSocketSender::sendFile(String &pathFileName)
|
|||||||
sendPutIndicator(pathFileName, fileLength);
|
sendPutIndicator(pathFileName, fileLength);
|
||||||
Array<char> readBuffer;
|
Array<char> readBuffer;
|
||||||
readBuffer.size(BUFFER_LENGTH);
|
readBuffer.size(BUFFER_LENGTH);
|
||||||
|
std::cout << "Sending file " << pathFileName << " " << Utility::byteCountToString(fileLength, false) << std::endl;
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
size_t bytesRead = readFile.read(&readBuffer[0], readBuffer.size());
|
size_t bytesRead = readFile.read(&readBuffer[0], readBuffer.size());
|
||||||
|
|||||||
@@ -8,15 +8,17 @@
|
|||||||
#include <sstp/clientsocketsender.hpp>
|
#include <sstp/clientsocketsender.hpp>
|
||||||
#include <sstp/sstp.hpp>
|
#include <sstp/sstp.hpp>
|
||||||
|
|
||||||
void handleServer(Block<String> &commands); // handler for server mode
|
// To Clean: From the top menu choose "View", "Command Palette", Then choose CMake: Clean OR /usr/bin/cmake --build /home/pi/CPP/sstp/build --config Debug --target clean --
|
||||||
void handleClient(Block<String> &commands); // handler for client mode
|
// To Build: From the top menu choose "View", "Command Palette", Then choose CMake: Build OR /usr/bin/cmake --build /home/pi/CPP/sstp/build --config Debug --target all --
|
||||||
|
// Output will be here. /home/pi/CPP/sstp/build
|
||||||
|
// On Isonoe to receive we will point to the binaries here /home/pi/CPP/sstp/build
|
||||||
|
// On Adrastea we will point to the binaries here /home/pi/Boneyard/sstp
|
||||||
|
|
||||||
bool registerSignalHandler(void); // registers a Control-c handler
|
bool registerSignalHandler(void); // registers a Control-c handler
|
||||||
void signalHandler(int signal); // The Control-C handler
|
void signalHandler(int signal); // The Control-C handler
|
||||||
|
|
||||||
SmartPointer<SSTP> sstp;
|
SmartPointer<SSTP> sstp;
|
||||||
|
|
||||||
// ****************************************************************************************************************************************************************
|
|
||||||
|
|
||||||
/// @brief
|
/// @brief
|
||||||
/// @param argc
|
/// @param argc
|
||||||
/// @param argv [0] program. [1] SERVERMODE {port} [2] CLIENTMODE {serveripaddress} {serverport} SEND {FileName}
|
/// @param argv [0] program. [1] SERVERMODE {port} [2] CLIENTMODE {serveripaddress} {serverport} SEND {FileName}
|
||||||
@@ -25,7 +27,7 @@ int main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
int returnCode(0);
|
int returnCode(0);
|
||||||
Profiler profiler;
|
Profiler profiler;
|
||||||
String version = "0.1.0.4"; // major version, minor version, patch, build
|
String version = "1.0.0.8"; // major version, minor version, patch, build
|
||||||
|
|
||||||
std::cout << "sstp version " << version.str() << std::endl;
|
std::cout << "sstp version " << version.str() << std::endl;
|
||||||
if(!registerSignalHandler())
|
if(!registerSignalHandler())
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
#include <common/utility.hpp>
|
#include <common/utility.hpp>
|
||||||
#include <common/stringbuffer.hpp>
|
#include <common/stringbuffer.hpp>
|
||||||
|
|
||||||
|
|
||||||
SocketConnectionReceiver::SocketConnectionReceiver()
|
SocketConnectionReceiver::SocketConnectionReceiver()
|
||||||
: mSocket(-1), mIsRunnable(true)
|
: mSocket(-1), mIsRunnable(true)
|
||||||
{
|
{
|
||||||
@@ -94,10 +93,20 @@ bool SocketConnectionReceiver::handlePut(Block<String> &commands)
|
|||||||
size_t fileLength;
|
size_t fileLength;
|
||||||
size_t totalBytesRead=0;
|
size_t totalBytesRead=0;
|
||||||
size_t totalPacketsRead=0;
|
size_t totalPacketsRead=0;
|
||||||
|
size_t availableDiskSpace=0;
|
||||||
|
|
||||||
fileName = commands[1];
|
fileName = commands[1];
|
||||||
fileLength = commands[commands.size()-1].toLong();
|
fileLength = commands[commands.size()-1].toLong();
|
||||||
std::cout << "PUT" << " " << fileName << " " << fileLength << std::endl;
|
std::cout << "PUT" << " " << fileName << " " << Utility::byteCountToString(fileLength,false) << std::endl;
|
||||||
|
|
||||||
|
availableDiskSpace=Utility::getAvailableDiskSpace(String("./"));
|
||||||
|
std::cout << Utility::byteCountToString(availableDiskSpace,false) << " available space on disk" << std::endl;
|
||||||
|
if(fileLength > availableDiskSpace)
|
||||||
|
{
|
||||||
|
std::cout << "Unsufficient space on disk. Required space " << Utility::byteCountToString(availableDiskSpace,false) << " , available space" << Utility::byteCountToString(availableDiskSpace,false) << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
FileIO writeFile(fileName, FileIO::ByteOrder::LittleEndian, FileIO::Mode::ReadWrite,FileIO::CreationFlags::CreateAlways);
|
FileIO writeFile(fileName, FileIO::ByteOrder::LittleEndian, FileIO::Mode::ReadWrite,FileIO::CreationFlags::CreateAlways);
|
||||||
|
|
||||||
if(!writeFile.isOkay())
|
if(!writeFile.isOkay())
|
||||||
@@ -140,7 +149,7 @@ bool SocketConnectionReceiver::handlePut(Block<String> &commands)
|
|||||||
double elapsedTimeSeconds = profiler.elapsed()/1000.00;
|
double elapsedTimeSeconds = profiler.elapsed()/1000.00;
|
||||||
double bytesPerSecond = totalBytesRead / elapsedTimeSeconds;
|
double bytesPerSecond = totalBytesRead / elapsedTimeSeconds;
|
||||||
String strBytesPerSecond = Utility::byteCountToString(bytesPerSecond);
|
String strBytesPerSecond = Utility::byteCountToString(bytesPerSecond);
|
||||||
std::cout << "Transferred " << Utility::byteCountToString(totalBytesRead,false) << " of " << Utility::byteCountToString(fileLength,false) << " " << percent << " percent " << strBytesPerSecond << std::endl;
|
std::cout << "Received " << Utility::byteCountToString(totalBytesRead,false) << " of " << Utility::byteCountToString(fileLength,false) << " " << percent << " percent " << strBytesPerSecond << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
writeFile.close();
|
writeFile.close();
|
||||||
|
|||||||
@@ -53,7 +53,6 @@ SocketServer::~SocketServer()
|
|||||||
std::cout << "close" << std::endl;
|
std::cout << "close" << std::endl;
|
||||||
close(); // close the listener socket
|
close(); // close the listener socket
|
||||||
std::cout << "~SocketServer, done" << std::endl;
|
std::cout << "~SocketServer, done" << std::endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Join all threads
|
/// @brief Join all threads
|
||||||
|
|||||||
Reference in New Issue
Block a user