You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
821 B
45 lines
821 B
|
7 years ago
|
#pragma once
|
||
|
|
|
||
|
|
#include <deque>
|
||
|
5 years ago
|
#include <exception>
|
||
|
|
#include <vector>
|
||
|
|
#include <cstdint>
|
||
|
7 years ago
|
|
||
|
5 years ago
|
namespace devilution {
|
||
|
7 years ago
|
namespace net {
|
||
|
|
|
||
|
5 years ago
|
typedef std::vector<unsigned char> buffer_t;
|
||
|
|
|
||
|
|
class frame_queue_exception : public std::exception {
|
||
|
6 years ago
|
public:
|
||
|
|
const char *what() const throw() override
|
||
|
|
{
|
||
|
|
return "Incorrect frame size";
|
||
|
|
}
|
||
|
7 years ago
|
};
|
||
|
|
|
||
|
|
typedef uint32_t framesize_t;
|
||
|
|
|
||
|
|
class frame_queue {
|
||
|
|
public:
|
||
|
|
constexpr static framesize_t max_frame_size = 0xFFFF;
|
||
|
|
|
||
|
|
private:
|
||
|
|
framesize_t current_size = 0;
|
||
|
|
std::deque<buffer_t> buffer_deque;
|
||
|
|
framesize_t nextsize = 0;
|
||
|
|
|
||
|
|
framesize_t size();
|
||
|
|
buffer_t read(framesize_t s);
|
||
|
|
|
||
|
|
public:
|
||
|
|
bool packet_ready();
|
||
|
|
buffer_t read_packet();
|
||
|
|
void write(buffer_t buf);
|
||
|
|
|
||
|
|
static buffer_t make_frame(buffer_t packetbuf);
|
||
|
|
};
|
||
|
|
|
||
|
|
} // namespace net
|
||
|
5 years ago
|
} // namespace devilution
|