3 Commits

Author SHA1 Message Date
ebb7628498 Code cleanup 2025-11-20 11:30:41 -05:00
9abd4b195b Add build info to main.cpp 2025-11-03 16:45:34 -05:00
f7facd3319 Add check for available disk space 2025-08-17 10:08:49 -04:00
5 changed files with 41 additions and 9 deletions

View File

@@ -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

View File

@@ -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"
} }
} }

View File

@@ -8,15 +8,15 @@
#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
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 +25,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.6"; // 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())

View File

@@ -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) << 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())

View File

@@ -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