Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 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,23 @@ 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)
|
||||||
|
// {
|
||||||
|
// struct statvfs stat;
|
||||||
|
// if (::statvfs(path, &stat) != 0)
|
||||||
|
// {
|
||||||
|
// throw new Exception("Error calling statvfs to get available disk space.");
|
||||||
|
// }
|
||||||
|
// // Calculate available space in bytes. Multiply Number of free inodes * Fragment size
|
||||||
|
// return (size_t)stat.f_bavail * stat.f_frsize;
|
||||||
|
// }
|
||||||
|
|
||||||
|
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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,11 @@
|
|||||||
#include <sstp/clientsocketsender.hpp>
|
#include <sstp/clientsocketsender.hpp>
|
||||||
#include <sstp/sstp.hpp>
|
#include <sstp/sstp.hpp>
|
||||||
|
|
||||||
|
// 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 --
|
||||||
|
// 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
|
||||||
|
|
||||||
|
|
||||||
void handleServer(Block<String> &commands); // handler for server mode
|
void handleServer(Block<String> &commands); // handler for server mode
|
||||||
void handleClient(Block<String> &commands); // handler for client mode
|
void handleClient(Block<String> &commands); // handler for client mode
|
||||||
bool registerSignalHandler(void); // registers a Control-c handler
|
bool registerSignalHandler(void); // registers a Control-c handler
|
||||||
@@ -15,8 +20,6 @@ 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 +28,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 = "0.1.0.5"; // 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())
|
||||||
|
|||||||
@@ -94,10 +94,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) << 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())
|
||||||
|
|||||||
Reference in New Issue
Block a user