something
This commit is contained in:
parent
2f3ef43cf5
commit
61bec9ce48
4 changed files with 90 additions and 8 deletions
|
@ -4,6 +4,10 @@
|
||||||
/* BEGIN INTRACONNECTION CODE */
|
/* BEGIN INTRACONNECTION CODE */
|
||||||
/******************************/
|
/******************************/
|
||||||
|
|
||||||
|
sosc::IntraConnection::IntraConnection() {
|
||||||
|
this->client_open = false;
|
||||||
|
}
|
||||||
|
|
||||||
sosc::IntraConnection::IntraConnection(TcpClient client) {
|
sosc::IntraConnection::IntraConnection(TcpClient client) {
|
||||||
this->client = client;
|
this->client = client;
|
||||||
this->client_open = true;
|
this->client_open = true;
|
||||||
|
@ -36,7 +40,11 @@ bool sosc::IntraConnection::Send(const Packet& packet) {
|
||||||
if(!this->client_open)
|
if(!this->client_open)
|
||||||
return false;
|
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 */
|
/* 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 */
|
/* END INTRASERVER CODE */
|
||||||
/****************************/
|
/****************************/
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
namespace sosc {
|
namespace sosc {
|
||||||
class IntraConnection {
|
class IntraConnection {
|
||||||
public:
|
public:
|
||||||
|
IntraConnection();
|
||||||
|
|
||||||
int Receive(Packet* packet, bool block = false);
|
int Receive(Packet* packet, bool block = false);
|
||||||
bool Send(const Packet& packet);
|
bool Send(const Packet& packet);
|
||||||
|
|
||||||
|
@ -14,7 +16,11 @@ public:
|
||||||
return this->client_open;
|
return this->client_open;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Close();
|
inline void Close() {
|
||||||
|
this->client_open = false;
|
||||||
|
this->client.Close();
|
||||||
|
}
|
||||||
|
|
||||||
~IntraConnection();
|
~IntraConnection();
|
||||||
private:
|
private:
|
||||||
IntraConnection(TcpClient client);
|
IntraConnection(TcpClient client);
|
||||||
|
@ -28,6 +34,8 @@ private:
|
||||||
|
|
||||||
class IntraServer {
|
class IntraServer {
|
||||||
public:
|
public:
|
||||||
|
IntraServer();
|
||||||
|
|
||||||
bool Listen(uint16_t port);
|
bool Listen(uint16_t port);
|
||||||
int Accept(IntraConnection* client);
|
int Accept(IntraConnection* client);
|
||||||
|
|
||||||
|
@ -35,7 +43,11 @@ public:
|
||||||
return this->server_open;
|
return this->server_open;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Close();
|
inline void Close() {
|
||||||
|
this->server_open = false;
|
||||||
|
this->server.Close();
|
||||||
|
}
|
||||||
|
|
||||||
~IntraServer();
|
~IntraServer();
|
||||||
private:
|
private:
|
||||||
bool server_open;
|
bool server_open;
|
||||||
|
|
|
@ -26,14 +26,14 @@ public:
|
||||||
|
|
||||||
void DeleteRegion(uint8_t index);
|
void DeleteRegion(uint8_t index);
|
||||||
void DeleteRegions(uint8_t start, uint8_t length);
|
void DeleteRegions(uint8_t start, uint8_t length);
|
||||||
inline void Clear() const {
|
inline void Clear() {
|
||||||
this->regions.clear();
|
this->regions.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
int Parse(const std::string& data, std::string* extra = nullptr);
|
int Parse(const std::string& data, std::string* extra = nullptr);
|
||||||
bool Check(int region_count, ...);
|
bool Check(int region_count, ...);
|
||||||
|
|
||||||
inline void SetId(uint8_t id) const {
|
inline void SetId(uint8_t id) {
|
||||||
this->id = id;
|
this->id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,16 +7,51 @@
|
||||||
namespace sosc {
|
namespace sosc {
|
||||||
class ScapeConnection {
|
class ScapeConnection {
|
||||||
public:
|
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:
|
private:
|
||||||
sosc::TcpClient client;
|
ScapeConnection(TcpClient client);
|
||||||
|
|
||||||
|
bool client_open;
|
||||||
|
TcpClient client;
|
||||||
|
std::string buffer;
|
||||||
|
|
||||||
|
friend class ScapeServer;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ScapeServer {
|
class ScapeServer {
|
||||||
public:
|
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:
|
private:
|
||||||
sosc::TcpServer server;
|
bool server_open;
|
||||||
|
TcpServer server;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue