forgot what i did

This commit is contained in:
malloc 2018-03-13 17:33:54 -05:00
parent 61bec9ce48
commit c1e1b1b105
9 changed files with 29 additions and 14 deletions

View file

@ -0,0 +1 @@

View file

@ -0,0 +1 @@

View file

@ -0,0 +1 @@

View file

@ -0,0 +1 @@

View file

@ -28,5 +28,7 @@ int main(int argc, char **argv) {
std::cout << got << std::endl;
}*/
return 0;
}

View file

@ -4,16 +4,24 @@
/* BEGIN INTRACONNECTION CODE */
/******************************/
sosc::IntraConnection::IntraConnection() {
sosc::IntraClient::IntraClient() {
this->client_open = false;
}
sosc::IntraConnection::IntraConnection(TcpClient client) {
bool sosc::IntraClient::Open(std::string host, uint16_t port) {
if(!this->client.Open(host, port))
return false;
this->client_open = true;
return true;
}
void sosc::IntraClient::Open(TcpClient client) {
this->client = client;
this->client_open = true;
}
int sosc::IntraConnection::Receive(Packet* packet, bool block) {
int sosc::IntraClient::Receive(Packet* packet, bool block) {
if(!this->client_open)
return PCK_ERR;
@ -36,14 +44,14 @@ int sosc::IntraConnection::Receive(Packet* packet, bool block) {
return PCK_OK;
}
bool sosc::IntraConnection::Send(const Packet& packet) {
bool sosc::IntraClient::Send(const Packet& packet) {
if(!this->client_open)
return false;
return this->client.Send(packet.ToString()) == 0;
}
sosc::IntraConnection::~IntraConnection() {
sosc::IntraClient::~IntraClient() {
this->Close();
}
@ -64,13 +72,13 @@ bool sosc::IntraServer::Listen(uint16_t port) {
return this->server.Listen(port);
}
int sosc::IntraServer::Accept(IntraConnection* client) {
int sosc::IntraServer::Accept(IntraClient* client) {
if(!this->server_open)
return -1;
TcpClient new_client;
if(this->server.Accept(&new_client) == 0) {
*client = IntraConnection(new_client);
client->Open(new_client);
return 0;
} else
return -1;

View file

@ -5,9 +5,10 @@
#include "packet.hpp"
namespace sosc {
class IntraConnection {
class IntraClient {
public:
IntraConnection();
IntraClient();
bool Open(std::string host, uint16_t port);
int Receive(Packet* packet, bool block = false);
bool Send(const Packet& packet);
@ -21,9 +22,9 @@ public:
this->client.Close();
}
~IntraConnection();
~IntraClient();
private:
IntraConnection(TcpClient client);
void Open(TcpClient client);
bool client_open;
TcpClient client;
@ -37,7 +38,7 @@ public:
IntraServer();
bool Listen(uint16_t port);
int Accept(IntraConnection* client);
int Accept(IntraClient* client);
inline bool IsOpen() const {
return this->server_open;

View file

@ -23,7 +23,7 @@ public:
~ScapeConnection();
private:
ScapeConnection(TcpClient client);
void Open(TcpClient client);
bool client_open;
TcpClient client;

View file

@ -43,7 +43,7 @@ namespace sosc {
class TcpClient {
public:
TcpClient();
bool Open(std::string host, std::uint16_t port);
bool Open(std::string host, uint16_t port);
int Receive(std::string* str, int flags = 0);
int Send(const std::string& str);