something

This commit is contained in:
malloc 2018-03-12 17:33:42 -05:00
parent 2f3ef43cf5
commit 61bec9ce48
4 changed files with 90 additions and 8 deletions

View file

@ -4,6 +4,10 @@
/* BEGIN INTRACONNECTION CODE */
/******************************/
sosc::IntraConnection::IntraConnection() {
this->client_open = false;
}
sosc::IntraConnection::IntraConnection(TcpClient client) {
this->client = client;
this->client_open = true;
@ -36,7 +40,11 @@ bool sosc::IntraConnection::Send(const Packet& packet) {
if(!this->client_open)
return false;
return this->client.Send(packet.ToString()) == 0;
}
sosc::IntraConnection::~IntraConnection() {
this->Close();
}
/****************************/
@ -45,6 +53,33 @@ bool sosc::IntraConnection::Send(const Packet& packet) {
/* BEGIN INTRASERVER CODE */
/****************************/
sosc::IntraServer::IntraServer() {
this->server_open = false;
}
bool sosc::IntraServer::Listen(uint16_t port) {
if(this->server_open)
return false;
return this->server.Listen(port);
}
int sosc::IntraServer::Accept(IntraConnection* client) {
if(!this->server_open)
return -1;
TcpClient new_client;
if(this->server.Accept(&new_client) == 0) {
*client = IntraConnection(new_client);
return 0;
} else
return -1;
}
sosc::IntraServer::~IntraServer() {
this->Close();
}
/****************************/
/* END INTRASERVER CODE */
/****************************/

View file

@ -7,6 +7,8 @@
namespace sosc {
class IntraConnection {
public:
IntraConnection();
int Receive(Packet* packet, bool block = false);
bool Send(const Packet& packet);
@ -14,7 +16,11 @@ public:
return this->client_open;
}
void Close();
inline void Close() {
this->client_open = false;
this->client.Close();
}
~IntraConnection();
private:
IntraConnection(TcpClient client);
@ -28,14 +34,20 @@ private:
class IntraServer {
public:
IntraServer();
bool Listen(uint16_t port);
int Accept(IntraConnection *client);
int Accept(IntraConnection* client);
inline bool IsOpen() const {
return this->server_open;
}
void Close();
inline void Close() {
this->server_open = false;
this->server.Close();
}
~IntraServer();
private:
bool server_open;

View file

@ -26,14 +26,14 @@ public:
void DeleteRegion(uint8_t index);
void DeleteRegions(uint8_t start, uint8_t length);
inline void Clear() const {
inline void Clear() {
this->regions.clear();
}
int Parse(const std::string& data, std::string* extra = nullptr);
bool Check(int region_count, ...);
inline void SetId(uint8_t id) const {
inline void SetId(uint8_t id) {
this->id = id;
}

View file

@ -7,16 +7,51 @@
namespace sosc {
class ScapeConnection {
public:
ScapeConnection();
int Receive(Packet* packet, bool block = false);
bool Send(const Packet& packet);
inline bool IsOpen() const {
return this->client_open;
}
inline void Close() {
this->client_open = false;
this->client.Close();
}
~ScapeConnection();
private:
sosc::TcpClient client;
ScapeConnection(TcpClient client);
bool client_open;
TcpClient client;
std::string buffer;
friend class ScapeServer;
};
class ScapeServer {
public:
ScapeServer();
bool Listen(uint16_t port);
int Accept(ScapeConnection* client);
inline bool IsOpen() const {
return this->server_open;
}
inline void Close() {
this->server_open = false;
this->server.Close();
}
~ScapeServer();
private:
sosc::TcpServer server;
bool server_open;
TcpServer server;
};
}