benign cysts in the gynomastica
This commit is contained in:
parent
94e02c37bf
commit
2f3ef43cf5
4 changed files with 110 additions and 5 deletions
|
@ -1,2 +1,50 @@
|
||||||
#include "intrasock.hpp"
|
#include "intrasock.hpp"
|
||||||
|
|
||||||
|
/******************************/
|
||||||
|
/* BEGIN INTRACONNECTION CODE */
|
||||||
|
/******************************/
|
||||||
|
|
||||||
|
sosc::IntraConnection::IntraConnection(TcpClient client) {
|
||||||
|
this->client = client;
|
||||||
|
this->client_open = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int sosc::IntraConnection::Receive(Packet* packet, bool block) {
|
||||||
|
if(!this->client_open)
|
||||||
|
return PCK_ERR;
|
||||||
|
|
||||||
|
int status;
|
||||||
|
bool first_recv = true;
|
||||||
|
while((status = packet->Parse(this->buffer, &this->buffer)) != PCK_OK) {
|
||||||
|
if(status == PCK_ERR)
|
||||||
|
return PCK_ERR;
|
||||||
|
if(!block && !first_recv)
|
||||||
|
return PCK_MORE;
|
||||||
|
|
||||||
|
status = this->client.Receive
|
||||||
|
(&this->buffer, SOSC_TCP_APPEND | (block ? SOSC_TCP_BLOCK : 0));
|
||||||
|
|
||||||
|
if(status == -1)
|
||||||
|
return PCK_ERR;
|
||||||
|
first_recv = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return PCK_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool sosc::IntraConnection::Send(const Packet& packet) {
|
||||||
|
if(!this->client_open)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************/
|
||||||
|
/* END INTRACONNECTION CODE */
|
||||||
|
/****************************/
|
||||||
|
/* BEGIN INTRASERVER CODE */
|
||||||
|
/****************************/
|
||||||
|
|
||||||
|
/****************************/
|
||||||
|
/* END INTRASERVER CODE */
|
||||||
|
/****************************/
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define SOSC_INTSOCK_H
|
#define SOSC_INTSOCK_H
|
||||||
|
|
||||||
#include "tcpsock.hpp"
|
#include "tcpsock.hpp"
|
||||||
|
#include "packet.hpp"
|
||||||
|
|
||||||
namespace sosc {
|
namespace sosc {
|
||||||
class IntraConnection {
|
class IntraConnection {
|
||||||
|
@ -9,11 +10,16 @@ public:
|
||||||
int Receive(Packet* packet, bool block = false);
|
int Receive(Packet* packet, bool block = false);
|
||||||
bool Send(const Packet& packet);
|
bool Send(const Packet& packet);
|
||||||
|
|
||||||
|
inline bool IsOpen() const {
|
||||||
|
return this->client_open;
|
||||||
|
}
|
||||||
|
|
||||||
void Close();
|
void Close();
|
||||||
~IntraConnection();
|
~IntraConnection();
|
||||||
private:
|
private:
|
||||||
IntraConnection(TcpClient client);
|
IntraConnection(TcpClient client);
|
||||||
|
|
||||||
|
bool client_open;
|
||||||
TcpClient client;
|
TcpClient client;
|
||||||
std::string buffer;
|
std::string buffer;
|
||||||
|
|
||||||
|
@ -22,9 +28,18 @@ private:
|
||||||
|
|
||||||
class IntraServer {
|
class IntraServer {
|
||||||
public:
|
public:
|
||||||
|
bool Listen(uint16_t port);
|
||||||
|
int Accept(IntraConnection *client);
|
||||||
|
|
||||||
|
inline bool IsOpen() const {
|
||||||
|
return this->server_open;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Close();
|
||||||
|
~IntraServer();
|
||||||
private:
|
private:
|
||||||
|
bool server_open;
|
||||||
|
TcpServer server;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "packet.hpp"
|
#include "packet.hpp"
|
||||||
|
|
||||||
bool sosc::Packet::AddRegion(std::string data) {
|
bool sosc::Packet::AddRegion(std::string data) {
|
||||||
if(this->regions.size() == 256)
|
if(this->regions.size() >= 256)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
this->regions.push_back(data);
|
this->regions.push_back(data);
|
||||||
|
@ -12,7 +12,43 @@ bool sosc::Packet::AddRegions(std::vector<std::string> data) {
|
||||||
if(this->regions.size() + data.size() > 256)
|
if(this->regions.size() + data.size() > 256)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
for(auto i = data.begin(); i != data.end(); ++i)
|
||||||
|
this->regions.push_back(*i);
|
||||||
|
}
|
||||||
|
|
||||||
|
void sosc::Packet::SetRegion(uint8_t index, std::string data) {
|
||||||
|
if(index >= this->regions.size())
|
||||||
|
this->regions.resize(index + 1);
|
||||||
|
|
||||||
|
this->regions[index] = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sosc::Packet::SetRegions
|
||||||
|
(uint8_t start, std::vector<std::string> data)
|
||||||
|
{
|
||||||
|
if(start + data.size() > 256)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(start + data.size() > this->regions.size())
|
||||||
|
this->regions.resize(start + data.size());
|
||||||
|
|
||||||
|
for(int i = 0; i < data.size(); ++i)
|
||||||
|
this->regions[start + i] = data[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
void sosc::Packet::DeleteRegion(uint8_t index) {
|
||||||
|
if(index >= this->regions.size())
|
||||||
|
return;
|
||||||
|
|
||||||
|
this->regions.erase(this->regions.begin() + index);
|
||||||
|
}
|
||||||
|
|
||||||
|
void sosc::Packet::DeleteRegions(uint8_t start, uint8_t length) {
|
||||||
|
if(start + length > 256)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for(int i = 0; i < length; ++i)
|
||||||
|
this->regions.erase(this->regions.begin() + start);
|
||||||
}
|
}
|
||||||
|
|
||||||
int sosc::Packet::Parse(const std::string& data, std::string* extra) {
|
int sosc::Packet::Parse(const std::string& data, std::string* extra) {
|
||||||
|
@ -74,8 +110,10 @@ int sosc::Packet::Parse(const std::string& data, std::string* extra) {
|
||||||
ptr += region_lengths[i];
|
ptr += region_lengths[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(length > expected_length)
|
if(length > expected_length && extra != nullptr)
|
||||||
*extra = data.substr(expected_length);
|
*extra = data.substr(expected_length);
|
||||||
|
else
|
||||||
|
*extra = "";
|
||||||
|
|
||||||
return PCK_OK;
|
return PCK_OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ public:
|
||||||
bool AddRegion(std::string data);
|
bool AddRegion(std::string data);
|
||||||
bool AddRegions(std::vector<std::string> data);
|
bool AddRegions(std::vector<std::string> data);
|
||||||
|
|
||||||
void SetRegion(uint8_t index);
|
void SetRegion(uint8_t index, std::string data);
|
||||||
void SetRegions(uint8_t start, std::vector<std::string> data);
|
void SetRegions(uint8_t start, std::vector<std::string> data);
|
||||||
|
|
||||||
void DeleteRegion(uint8_t index);
|
void DeleteRegion(uint8_t index);
|
||||||
|
@ -41,10 +41,14 @@ public:
|
||||||
return this->id;
|
return this->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline int RegionCount() const {
|
||||||
|
return this->regions.size();
|
||||||
|
}
|
||||||
|
|
||||||
inline std::string operator []
|
inline std::string operator []
|
||||||
(const std::vector<std::string>::size_type index) const
|
(const std::vector<std::string>::size_type index) const
|
||||||
{
|
{
|
||||||
return regions[index];
|
return this->regions[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ToString() const;
|
std::string ToString() const;
|
||||||
|
|
Loading…
Reference in a new issue