Code cleanup.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
#include <sstp/clientsocketsender.hpp>
|
#include <sstp/clientsocketsender.hpp>
|
||||||
|
|
||||||
/// @Brief This is to provide a definition for SmartPointer
|
/// @brief This is to provide a definition for SmartPointer
|
||||||
ClientSocketSender::ClientSocketSender()
|
ClientSocketSender::ClientSocketSender()
|
||||||
: mIPAddress(""), mPort(0)
|
: mIPAddress(""), mPort(0)
|
||||||
{
|
{
|
||||||
@@ -35,10 +35,10 @@ ClientSocketSender::ClientSocketSender(String ipAddress, int port)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// @brief Close the connection on destruction
|
/// @brief Close the connection on destruction
|
||||||
ClientSocketSender::~ClientSocketSender()
|
ClientSocketSender::~ClientSocketSender()
|
||||||
{
|
{
|
||||||
|
std::cout << "~ClientSocketSender" << std::endl;
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,11 +46,10 @@ ClientSocketSender::~ClientSocketSender()
|
|||||||
/// @param
|
/// @param
|
||||||
void ClientSocketSender::close(void)
|
void ClientSocketSender::close(void)
|
||||||
{
|
{
|
||||||
if(-1!=mSocket)
|
if(-1==mSocket)return;
|
||||||
{
|
std::cout << "ClientSocketSender::close, closing socket" << std::endl;
|
||||||
::close(mSocket);
|
::close(mSocket);
|
||||||
mSocket=-1;
|
mSocket=-1;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Send the specified file through the connection
|
/// @brief Send the specified file through the connection
|
||||||
@@ -89,6 +88,9 @@ bool ClientSocketSender::sendFile(String &pathFileName)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief Send PCKT with length of packet
|
||||||
|
/// @param bytesToSend
|
||||||
|
/// @return
|
||||||
bool ClientSocketSender::sendPacketIndicator(DWORD bytesToSend)
|
bool ClientSocketSender::sendPacketIndicator(DWORD bytesToSend)
|
||||||
{
|
{
|
||||||
if(!isOkay())return false;
|
if(!isOkay())return false;
|
||||||
@@ -99,6 +101,10 @@ bool ClientSocketSender::sendPacketIndicator(DWORD bytesToSend)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief Send PUT with filename and file length
|
||||||
|
/// @param fileName
|
||||||
|
/// @param fileLength
|
||||||
|
/// @return
|
||||||
bool ClientSocketSender::sendPutIndicator(String fileName,DWORD fileLength)
|
bool ClientSocketSender::sendPutIndicator(String fileName,DWORD fileLength)
|
||||||
{
|
{
|
||||||
if(!isOkay())return false;
|
if(!isOkay())return false;
|
||||||
@@ -113,6 +119,9 @@ bool ClientSocketSender::sendPutIndicator(String fileName,DWORD fileLength)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief Send QUIT
|
||||||
|
/// @param
|
||||||
|
/// @return
|
||||||
bool ClientSocketSender::sendQuit(void)
|
bool ClientSocketSender::sendQuit(void)
|
||||||
{
|
{
|
||||||
if(!isOkay())return false;
|
if(!isOkay())return false;
|
||||||
@@ -121,6 +130,10 @@ bool ClientSocketSender::sendQuit(void)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief items in buffer with length bytesToSend
|
||||||
|
/// @param buffer The buffer to send
|
||||||
|
/// @param bytesToSend The number of bytes to send
|
||||||
|
/// @return
|
||||||
bool ClientSocketSender::sendPacket(Array<char> &buffer,DWORD bytesToSend)
|
bool ClientSocketSender::sendPacket(Array<char> &buffer,DWORD bytesToSend)
|
||||||
{
|
{
|
||||||
if(!isOkay())return false;
|
if(!isOkay())return false;
|
||||||
|
|||||||
@@ -33,8 +33,8 @@ class SSTP
|
|||||||
void handleServer(Block<String>& arguments);
|
void handleServer(Block<String>& arguments);
|
||||||
void handleClient(Block<String>& arguments);
|
void handleClient(Block<String>& arguments);
|
||||||
private:
|
private:
|
||||||
SmartPointer<SocketServer> mSocketServer;
|
SmartPointer<SocketServer> mSocketServer;
|
||||||
SmartPointer<ClientSocketSender> mClientSocketSender;
|
SmartPointer<ClientSocketSender> mClientSocketSender;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline
|
inline
|
||||||
@@ -65,8 +65,9 @@ void SSTP::handleServer(Block<String>& commands)
|
|||||||
}
|
}
|
||||||
int port = commands[2].toInt();
|
int port = commands[2].toInt();
|
||||||
std::cout << commands[1] << ":" << commands[2] << std::endl;
|
std::cout << commands[1] << ":" << commands[2] << std::endl;
|
||||||
SocketServer socketServer(commands[2].toInt());
|
mSocketServer = ::new SocketServer(commands[2].toInt());
|
||||||
socketServer.listen();
|
mSocketServer.disposition(PointerDisposition::Delete);
|
||||||
|
mSocketServer->listen();
|
||||||
std::cout << "Done, total took " << Utility::formatNumber(profiler.end()) << "(ms)" << std::endl;
|
std::cout << "Done, total took " << Utility::formatNumber(profiler.end()) << "(ms)" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,6 +84,7 @@ void SSTP::handleClient(Block<String>& arguments)
|
|||||||
}
|
}
|
||||||
mClientSocketSender.destroy();
|
mClientSocketSender.destroy();
|
||||||
mClientSocketSender = new ClientSocketSender(arguments[2],arguments[3].toInt());
|
mClientSocketSender = new ClientSocketSender(arguments[2],arguments[3].toInt());
|
||||||
|
mClientSocketSender.disposition(PointerDisposition::Delete);
|
||||||
bool returnCode = mClientSocketSender->sendFile(arguments[4]);
|
bool returnCode = mClientSocketSender->sendFile(arguments[4]);
|
||||||
if(!returnCode)
|
if(!returnCode)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -32,8 +32,6 @@ SocketServer::SocketServer(int port)
|
|||||||
// bind socket to network address and port
|
// bind socket to network address and port
|
||||||
mInternalSocketAddress.sin_family = AF_INET;
|
mInternalSocketAddress.sin_family = AF_INET;
|
||||||
mInternalSocketAddress.sin_addr.s_addr=INADDR_ANY;
|
mInternalSocketAddress.sin_addr.s_addr=INADDR_ANY;
|
||||||
|
|
||||||
|
|
||||||
mInternalSocketAddress.sin_port = htons(mListenPort);
|
mInternalSocketAddress.sin_port = htons(mListenPort);
|
||||||
result = ::bind(mSocketFileDescriptor,(struct sockaddr*)&mInternalSocketAddress,sizeof(mInternalSocketAddress));
|
result = ::bind(mSocketFileDescriptor,(struct sockaddr*)&mInternalSocketAddress,sizeof(mInternalSocketAddress));
|
||||||
if(result)
|
if(result)
|
||||||
@@ -47,9 +45,14 @@ SocketServer::SocketServer(int port)
|
|||||||
/// @brief Close down the listener
|
/// @brief Close down the listener
|
||||||
SocketServer::~SocketServer()
|
SocketServer::~SocketServer()
|
||||||
{
|
{
|
||||||
|
std::cout << "~SocketServer" << std::endl;
|
||||||
|
std::cout << "shutdownConnectionReceivers" << std::endl;
|
||||||
shutdownConnectionReceivers();
|
shutdownConnectionReceivers();
|
||||||
|
std::cout << "join" << std::endl;
|
||||||
join(); // Then join all socket threads
|
join(); // Then join all socket threads
|
||||||
|
std::cout << "close" << std::endl;
|
||||||
close(); // close the listener socket
|
close(); // close the listener socket
|
||||||
|
std::cout << "~SocketServer, done" << std::endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,9 +113,6 @@ void SocketServer::listen(void)
|
|||||||
pSocketConnectionReceiver = ::new SocketConnectionReceiver(socket, internalSocketAddress);
|
pSocketConnectionReceiver = ::new SocketConnectionReceiver(socket, internalSocketAddress);
|
||||||
pSocketConnectionReceiver.disposition(PointerDisposition::Delete);
|
pSocketConnectionReceiver.disposition(PointerDisposition::Delete);
|
||||||
mExecutionThreads.push_back(std::thread(&SocketConnectionReceiver::threadFunction, *pSocketConnectionReceiver, 0));
|
mExecutionThreads.push_back(std::thread(&SocketConnectionReceiver::threadFunction, *pSocketConnectionReceiver, 0));
|
||||||
|
|
||||||
// SocketConnectionReceiver socketConnectionReceiver(socket, internalSocketAddress);
|
|
||||||
// mExecutionThreads.push_back(std::thread(&SocketConnectionReceiver::threadFunction, &socketConnectionReceiver, 0));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,9 +120,8 @@ void SocketServer::listen(void)
|
|||||||
/// @param
|
/// @param
|
||||||
void SocketServer::close(void)
|
void SocketServer::close(void)
|
||||||
{
|
{
|
||||||
if(-1!=mSocketFileDescriptor)
|
if(-1==mSocketFileDescriptor)return;
|
||||||
{
|
std::cout << "SocketServer::close, closing socket" << std::endl;
|
||||||
::close(mSocketFileDescriptor);
|
::close(mSocketFileDescriptor);
|
||||||
mSocketFileDescriptor=-1;
|
mSocketFileDescriptor=-1;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user