1
0
mirror of https://github.com/solemnwarning/directplay-lite synced 2024-12-30 16:45:37 +01:00
directplay-lite/src/SendQueue.hpp
Daniel Collins c63945facd Initial prototype of network I/O and session enumeration.
The threading model used for processing messages here will need
redesigning; we can't allow the application to block the event loop
when processing a message in case it calls something which won't
return until a message is processed.

Final model will probably use a pool of workers which will handle I/O
one-at-a-time, blocking and allowing other threads to deal with the
I/O when in the application message callback.
2018-09-11 22:09:27 +01:00

61 lines
1.2 KiB
C++

#ifndef DPLITE_SENDQUEUE_HPP
#define DPLITE_SENDQUEUE_HPP
#include <winsock2.h>
#include <list>
#include <set>
#include <stdlib.h>
#include <utility>
#include <vector>
class SendQueue
{
public:
enum SendPriority {
SEND_PRI_LOW = 1,
SEND_PRI_MEDIUM = 2,
SEND_PRI_HIGH = 4,
};
class Buffer {
private:
std::vector<unsigned char> data;
struct sockaddr_storage dest_addr;
int dest_addr_len;
protected:
Buffer(const void *data, size_t data_size, const struct sockaddr *dest_addr = NULL, int dest_addr_len = 0);
public:
virtual ~Buffer();
std::pair<const void*, size_t> get_data();
std::pair<const struct sockaddr*, int> get_dest_addr();
virtual void complete(HRESULT result) = 0;
};
private:
std::list<Buffer*> low_queue;
std::list<Buffer*> medium_queue;
std::list<Buffer*> high_queue;
Buffer *current;
public:
SendQueue(): current(NULL) {}
/* No copy c'tor. */
SendQueue(const SendQueue &src) = delete;
void send(SendPriority priority, Buffer *buffer);
Buffer *get_next();
void complete(Buffer *buffer, HRESULT result);
};
#endif /* !DPLITE_SENDQUEUE_HPP */