Apply formating to all files. CLeanup
This commit is contained in:
parent
43e374f269
commit
744c01c5d0
928 changed files with 14515 additions and 21480 deletions
|
|
@ -1,9 +1,6 @@
|
|||
|
||||
#include "ConnectionCommon.hpp"
|
||||
|
||||
static tp::ModuleManifest* sModuleDependencies[] = {
|
||||
&tp::gModuleStrings,
|
||||
nullptr
|
||||
};
|
||||
static tp::ModuleManifest* sModuleDependencies[] = { &tp::gModuleStrings, nullptr };
|
||||
|
||||
tp::ModuleManifest tp::gModuleConnection = ModuleManifest("Storage", nullptr, nullptr, sModuleDependencies);
|
||||
|
|
@ -25,16 +25,11 @@ bool LocalConnection::connect(const Location& location, const Type& connectionIn
|
|||
auto handle = new LocalConnectionContext();
|
||||
|
||||
switch (connectionInfo.getType()) {
|
||||
case Type::READ:
|
||||
handle->open(location.getLocation().read(), true);
|
||||
break;
|
||||
case Type::READ: handle->open(location.getLocation().read(), true); break;
|
||||
|
||||
case Type::WRITE:
|
||||
handle->open(location.getLocation().read(), false);
|
||||
break;
|
||||
case Type::WRITE: handle->open(location.getLocation().read(), false); break;
|
||||
|
||||
default:
|
||||
break;
|
||||
default: break;
|
||||
};
|
||||
|
||||
if (!handle->isOpen()) {
|
||||
|
|
|
|||
|
|
@ -14,9 +14,7 @@ ualni tp::LocalConnectionContext::size() {
|
|||
return out;
|
||||
}
|
||||
|
||||
LocalConnectionContext::LocalConnectionContext() {
|
||||
stream = new std::fstream();
|
||||
}
|
||||
LocalConnectionContext::LocalConnectionContext() { stream = new std::fstream(); }
|
||||
|
||||
LocalConnectionContext::~LocalConnectionContext() {
|
||||
auto strm = (std::fstream*) stream;
|
||||
|
|
@ -50,8 +48,6 @@ void LocalConnectionContext::write(const int1* in, ualni size) {
|
|||
|
||||
void LocalConnectionContext::open(const char* path, bool read) {
|
||||
auto strm = (std::fstream*) stream;
|
||||
if (read)
|
||||
strm->open(path, std::ios::in | std::ios::binary | std::ios::app);
|
||||
else
|
||||
strm->open(path, std::ios::out | std::ios::binary | std::ios::trunc);
|
||||
if (read) strm->open(path, std::ios::in | std::ios::binary | std::ios::app);
|
||||
else strm->open(path, std::ios::out | std::ios::binary | std::ios::trunc);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
namespace tp {
|
||||
class LocalConnectionContext {
|
||||
void* stream;
|
||||
|
||||
public:
|
||||
LocalConnectionContext();
|
||||
~LocalConnectionContext();
|
||||
|
|
|
|||
|
|
@ -13,7 +13,8 @@ class tp::ServerContext {
|
|||
asio::ip::tcp::acceptor socket;
|
||||
typedef asio::ip::tcp::socket Socket;
|
||||
|
||||
ServerContext() : socket(context) {}
|
||||
ServerContext() :
|
||||
socket(context) {}
|
||||
|
||||
~ServerContext() {
|
||||
context.stop();
|
||||
|
|
@ -28,7 +29,8 @@ class tp::ClientContext {
|
|||
asio::ip::tcp::socket socket;
|
||||
|
||||
public:
|
||||
ClientContext() : socket(context) {}
|
||||
ClientContext() :
|
||||
socket(context) {}
|
||||
|
||||
~ClientContext() {
|
||||
context.stop();
|
||||
|
|
@ -38,11 +40,9 @@ public:
|
|||
|
||||
// --------------------------------------------------------------------------------------- //
|
||||
|
||||
Server::Server() {
|
||||
mContext = new ServerContext();
|
||||
}
|
||||
Server::Server() { mContext = new ServerContext(); }
|
||||
|
||||
Server::~Server() {
|
||||
Server::~Server() {
|
||||
delete mContext;
|
||||
assert(0);
|
||||
}
|
||||
|
|
@ -57,20 +57,20 @@ void Server::start(ualni port) {
|
|||
Server::Socket Server::accept() {
|
||||
auto clientSocket = new asio::ip::tcp::socket(mContext->context);
|
||||
mContext->socket.accept(*clientSocket);
|
||||
std::cout << "New client accepted "<< std::endl;
|
||||
std::cout << "New client accepted " << std::endl;
|
||||
return clientSocket;
|
||||
}
|
||||
|
||||
int1* Server::read(Socket client) {
|
||||
short messageSize;
|
||||
if (asio::read(*(ServerContext::Socket*)client, asio::buffer(&messageSize, 2)) == -1) {
|
||||
if (asio::read(*(ServerContext::Socket*) client, asio::buffer(&messageSize, 2)) == -1) {
|
||||
std::cerr << "Failed to read from socket" << std::endl;
|
||||
((ServerContext::Socket*)client)->close();
|
||||
((ServerContext::Socket*) client)->close();
|
||||
return nullptr;
|
||||
}
|
||||
auto message = new char[messageSize + 1];
|
||||
message[messageSize] = '\0';
|
||||
if (asio::read(*(ServerContext::Socket*)client, asio::buffer(message, messageSize)) == -1) {
|
||||
if (asio::read(*(ServerContext::Socket*) client, asio::buffer(message, messageSize)) == -1) {
|
||||
std::cerr << "Failed to read from socket" << std::endl;
|
||||
memcpy(message, "Client wanna say something but i cant read", 100);
|
||||
}
|
||||
|
|
@ -79,19 +79,17 @@ int1* Server::read(Socket client) {
|
|||
|
||||
void Server::write(Socket client, const char* message) {
|
||||
auto messageSize = (short) strlen(message);
|
||||
if (asio::write(*(ServerContext::Socket*)client, asio::buffer(&messageSize, 2)) == -1) {
|
||||
if (asio::write(*(ServerContext::Socket*) client, asio::buffer(&messageSize, 2)) == -1) {
|
||||
std::cerr << "Failed to write to socket" << std::endl;
|
||||
}
|
||||
if (asio::write(*(ServerContext::Socket*)client, asio::buffer(message, messageSize)) == -1) {
|
||||
if (asio::write(*(ServerContext::Socket*) client, asio::buffer(message, messageSize)) == -1) {
|
||||
std::cerr << "Failed to write to socket" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------- //
|
||||
|
||||
Client::Client() {
|
||||
mContext = new ClientContext();
|
||||
}
|
||||
Client::Client() { mContext = new ClientContext(); }
|
||||
|
||||
Client::~Client() {
|
||||
delete mContext;
|
||||
|
|
@ -118,7 +116,7 @@ char* Client::read() {
|
|||
return message;
|
||||
}
|
||||
|
||||
void Client::write( const char* message ) {
|
||||
void Client::write(const char* message) {
|
||||
auto messageSize = (short) strlen(message);
|
||||
if (asio::write(mContext->socket, asio::buffer(&messageSize, 2)) == -1) {
|
||||
std::cerr << "Failed to write to socket" << std::endl;
|
||||
|
|
@ -127,4 +125,3 @@ void Client::write( const char* message ) {
|
|||
std::cerr << "Failed to write to socket" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,8 +45,10 @@ namespace tp {
|
|||
|
||||
public:
|
||||
Type() = default;
|
||||
explicit Type(bool read) : mHandleType((State) read) {}
|
||||
explicit Type(State handleType) : mHandleType(handleType) {}
|
||||
explicit Type(bool read) :
|
||||
mHandleType((State) read) {}
|
||||
explicit Type(State handleType) :
|
||||
mHandleType(handleType) {}
|
||||
[[nodiscard]] State getType() const { return mHandleType; }
|
||||
[[nodiscard]] bool isRead() const { return mHandleType == READ; }
|
||||
[[nodiscard]] bool isWrite() const { return mHandleType == WRITE; }
|
||||
|
|
|
|||
|
|
@ -9,18 +9,19 @@ namespace tp {
|
|||
public:
|
||||
class Location {
|
||||
String mLocation;
|
||||
|
||||
public:
|
||||
Location() : mLocation("tmp") {};
|
||||
explicit Location(const String& location) : mLocation(location) {}
|
||||
Location() :
|
||||
mLocation("tmp"){};
|
||||
explicit Location(const String& location) :
|
||||
mLocation(location) {}
|
||||
void setLocation(const String& location) { mLocation = location; }
|
||||
[[nodiscard]] const String& getLocation() const { return mLocation; }
|
||||
[[nodiscard]] bool exists() const;
|
||||
};
|
||||
|
||||
public:
|
||||
LocalConnection() {
|
||||
MODULE_SANITY_CHECK(gModuleConnection)
|
||||
};
|
||||
LocalConnection(){ MODULE_SANITY_CHECK(gModuleConnection) };
|
||||
|
||||
virtual ~LocalConnection() {
|
||||
if (mStatus.isOpened()) LocalConnection::disconnect();
|
||||
|
|
|
|||
|
|
@ -11,14 +11,13 @@ namespace tp {
|
|||
public:
|
||||
class Location {
|
||||
ualni mId = 0;
|
||||
|
||||
public:
|
||||
Location() = default;
|
||||
};
|
||||
|
||||
public:
|
||||
RemoteConnection() {
|
||||
MODULE_SANITY_CHECK(gModuleConnection)
|
||||
};
|
||||
RemoteConnection(){ MODULE_SANITY_CHECK(gModuleConnection) };
|
||||
|
||||
virtual ~RemoteConnection() {
|
||||
if (mStatus.isOpened()) RemoteConnection::disconnect();
|
||||
|
|
|
|||
|
|
@ -30,6 +30,4 @@ TEST_DEF_STATIC(Simple) {
|
|||
}
|
||||
}
|
||||
|
||||
TEST_DEF(LocalConnection) {
|
||||
testSimple();
|
||||
}
|
||||
TEST_DEF(LocalConnection) { testSimple(); }
|
||||
Loading…
Add table
Add a link
Reference in a new issue