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