1.2
This commit is contained in:
parent
299490ca5f
commit
0f01d375db
13 changed files with 347 additions and 262 deletions
44
src/Socket.h
44
src/Socket.h
|
|
@ -8,8 +8,10 @@
|
|||
#ifndef SOCKET_H_
|
||||
#define SOCKET_H_
|
||||
|
||||
#include <map>
|
||||
#include <boost/asio.hpp>
|
||||
#include "Packet.h"
|
||||
#include "Filter.h"
|
||||
#include "Types.h"
|
||||
|
||||
#define SRC_PORT 29809
|
||||
|
|
@ -17,30 +19,32 @@
|
|||
|
||||
#define MAX_LENGTH 1024
|
||||
|
||||
typedef std::function<int(Packet)> Listener;
|
||||
typedef std::pair<Filter, Listener> ListenerPair;
|
||||
|
||||
class Socket {
|
||||
public:
|
||||
Socket(boost::asio::io_service&);
|
||||
virtual ~Socket() {
|
||||
}
|
||||
void init(short, short);
|
||||
void send(Packet);
|
||||
void listen();
|
||||
void setHostIp(ipAddr);
|
||||
std::function<int(Packet)> callback = [](Packet a) {
|
||||
return 0;
|
||||
};
|
||||
Socket(boost::asio::io_service&);
|
||||
virtual ~Socket();
|
||||
void init(short, short);
|
||||
void clear();
|
||||
void send(Packet);
|
||||
void setHostIp(ipAddr);
|
||||
void listen(Listener l, Filter f = Filter());
|
||||
|
||||
private:
|
||||
boost::asio::ip::udp::socket send_socket_;
|
||||
boost::asio::ip::udp::socket receive_socket_;
|
||||
boost::asio::ip::udp::endpoint broadcast_endpoint_;
|
||||
boost::asio::ip::udp::endpoint remote_endpoint_;
|
||||
boost::asio::ip::udp::endpoint wildcard_endpoint_;
|
||||
boost::asio::ip::udp::endpoint local_endpoint_;
|
||||
boost::asio::deadline_timer timer;
|
||||
bytes data = bytes(MAX_LENGTH);
|
||||
ipAddr local_ip;
|
||||
int initialized = 0;
|
||||
void receive();
|
||||
void settimeout();
|
||||
boost::asio::ip::udp::socket send_socket_;
|
||||
boost::asio::ip::udp::socket receive_socket_;
|
||||
boost::asio::ip::udp::endpoint broadcast_endpoint_;
|
||||
boost::asio::ip::udp::endpoint remote_endpoint_;
|
||||
boost::asio::ip::udp::endpoint wildcard_endpoint_;
|
||||
boost::asio::ip::udp::endpoint local_endpoint_;
|
||||
boost::asio::deadline_timer timer;
|
||||
bytes data = bytes(MAX_LENGTH);
|
||||
ipAddr local_ip;
|
||||
std::map<Filter, Listener> callback = { };
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue