6 Commits

Author SHA1 Message Date
fc69790bd2 Code cleanup 2025-12-18 09:27:37 -05:00
6d87851117 Code cleanup 2025-12-16 18:23:21 -05:00
5c5f4d7d8f maintenance 2025-12-05 09:22:45 -05:00
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
8 changed files with 38 additions and 14 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,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

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

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

View File

@@ -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.9"; // 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,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();

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
@@ -84,8 +83,8 @@ bool SocketServer::isOkay(void)
} }
/// @brief This is the listener. It will wait for incoming connections. /// @brief This is the listener. It will wait for incoming connections.
/// When an incoming connection is received it will create a SocketConnectionReceiver object and call it's threadFunction to handle further interactions /// When an incoming connection is received it will create a SocketConnectionReceiver object and call it's threadFunction
/// such as transmitting a file. /// to handle further interactions such as transmitting a file.
void SocketServer::listen(void) void SocketServer::listen(void)
{ {
while(isOkay()) while(isOkay())

View File

@@ -6,7 +6,7 @@
#include <sstp/clientsocketsender.hpp> #include <sstp/clientsocketsender.hpp>
/// @brief [0]=program [1]=SERVERMODE [2]={port} /// @brief [0]=program [1]=SERVERMODE [2]={port}
/// @Note Currently this method will never return. The application is terminate with CTRL-C. Ideally, we would exit is some cleaner fashion /// @Note Currently this method will never return. The application is terminated with CTRL-C. Ideally, we would exit in some cleaner fashion
/// perhaps by implementing a CTRL-C hook and then destroying the SocketServer properly by calling it's destructor. See SocketServer::~SocketServer() /// perhaps by implementing a CTRL-C hook and then destroying the SocketServer properly by calling it's destructor. See SocketServer::~SocketServer()
/// @param commands /// @param commands
void SSTP::handleServer(Block<String>& commands) void SSTP::handleServer(Block<String>& commands)

View File

@@ -10,7 +10,7 @@ class SSTP
{ {
public: public:
SSTP(); SSTP();
~SSTP(); virtual ~SSTP();
void handleServer(Block<String>& arguments); void handleServer(Block<String>& arguments);
void handleClient(Block<String>& arguments); void handleClient(Block<String>& arguments);
private: private: