From 1abe57aad12ae24eff237bdf5e3570773f2c19a2 Mon Sep 17 00:00:00 2001 From: malloc Date: Thu, 8 Mar 2018 17:02:59 -0600 Subject: [PATCH] we'll make a protocol today that looks rich --- protocol.md | 15 ++++++++------- server/src/sock/gamesock.cpp | 2 -- server/src/sock/gamesock.hpp | 22 ---------------------- server/src/sock/tcpsock_win.cpp | 9 +++++++-- 4 files changed, 15 insertions(+), 33 deletions(-) delete mode 100644 server/src/sock/gamesock.cpp delete mode 100644 server/src/sock/gamesock.hpp diff --git a/protocol.md b/protocol.md index a840520..0b6559f 100644 --- a/protocol.md +++ b/protocol.md @@ -10,15 +10,16 @@ All references to the 'byte' in this document refers to individual 8-bit octets, Because the body of the packet is a sequence of many different regions of byte data that is not delimited, it is necessary for the header of the packet to determine boundaries for the regions of data. -* The first four bytes will always be 0xF0, 0x9F, 0xA6, 0x91. If this is not set properly, the endpoint must close the connection. -* The fifth byte is the packet id, the meanings of which are defined in the [_Packet IDs_](#packet-ids) section. -* The sixth byte is the number of byte regions in the packet. -* The bytes following the sixth byte are a list of binary length segments, each of which correspond to the number of bytes in its respective region. They each follow this format: +* The first two bytes will always be 0xB0 and 0X0B. If this is not set properly, the endpoint must close the connection. +* The next four bytes are the total length of the entire packet, including the whole header. +* The seventh byte is the packet id, the meanings of which are defined in the [_Packet IDs_](#packet-ids) section. +* The eighth byte is the number of byte regions in the packet. +* The bytes following the eighth byte are a list of binary length segments, each of which correspond to the number of bytes in its respective region. They each follow this format: * If length is less than 254, the length of the region is stored in a single byte. - * If length is greater than or equal to 254 but less than 65,536, the first byte of the lenght segment should be 254 and the following two bytes is the length of the region. - * If length is greater than or equal to 65,536, the first byte of the length segment should be 255 and the following four bytes is the length of the region. + * If length is greater than or equal to 254 but less than 65,536, the first byte of the length segment will be 254 and the following two bytes is the length of the region. + * If length is greater than or equal to 65,536, the first byte of the length segment will be 255 and the following four bytes is the length of the region. -The number of length segments should be equal to the number of byte regions as defined in the second byte. The length of any single section may not exceed (2^32)-1 bytes. +The number of length segments must equal the number of byte regions as defined in the second byte. The combined length of the regions must not exceed 2^32-n where n is the length of the header. ## Body diff --git a/server/src/sock/gamesock.cpp b/server/src/sock/gamesock.cpp deleted file mode 100644 index 938dfe3..0000000 --- a/server/src/sock/gamesock.cpp +++ /dev/null @@ -1,2 +0,0 @@ -#include "gamesock.hpp" - diff --git a/server/src/sock/gamesock.hpp b/server/src/sock/gamesock.hpp deleted file mode 100644 index 97075ae..0000000 --- a/server/src/sock/gamesock.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef SOSC_GAMESOCK_H -#define SOSC_GAMESOCK_H - -#include "tcpsock.hpp" - -namespace sosc { -class GameConnection { -public: - -private: - sosc::TcpClient client; -}; - -class GameServer { -public: - -private: - -}; -} - -#endif diff --git a/server/src/sock/tcpsock_win.cpp b/server/src/sock/tcpsock_win.cpp index 1cbf5cd..89e41fe 100644 --- a/server/src/sock/tcpsock_win.cpp +++ b/server/src/sock/tcpsock_win.cpp @@ -80,13 +80,18 @@ void sosc::TcpClient::Open this->ip.Parse(buffer); } -int sosc::TcpClient::Receive(std::string* str, bool append) { +int sosc::TcpClient::Receive(std::string* str, int flags) { if(!this->sock_open) return -1; + bool append = (flags & SOSC_TCP_APPEND) != 0, + block = (flags & SOSC_TCP_BLOCK) != 0; + int total_length = 0; bool first_recv = true; - while(this->IsDataReady()) { + while(block ? (first_recv ? true : this->IsDataReady()) + : this->IsDataReady()) + { int length = recv(this->sock, this->buffer, SOSC_TCP_BUFLEN, 0); if(length <= 0) { this->Close();