68 lines
1.5 KiB
C++
68 lines
1.5 KiB
C++
#pragma once
|
|
|
|
/**
|
|
* \file Connexion.h
|
|
* \brief File containing the blitz::network::Connexion class
|
|
*/
|
|
|
|
#include "TCPSocket.h"
|
|
#include "blitz/protocol/PacketDispatcher.h"
|
|
#include "blitz/protocol/PacketHandler.h"
|
|
#include "blitz/protocol/PacketFactory.h"
|
|
|
|
namespace blitz {
|
|
namespace network {
|
|
|
|
using TCPStream = sp::io::Stream<sp::io::TcpTag, protocol::PacketDispatcher, protocol::PacketFactory, sp::option::ZlibCompress>;
|
|
|
|
/**
|
|
* \class Connexion
|
|
* \brief Represents a network connexion
|
|
*/
|
|
class Connexion : public protocol::PacketHandler, public TCPStream {
|
|
public:
|
|
/**
|
|
* \brief Constructs with an empty socket
|
|
*/
|
|
Connexion() {}
|
|
|
|
/**
|
|
* \brief Constructs with an already connected socket
|
|
*/
|
|
Connexion(TCPSocket&& socket);
|
|
|
|
/**
|
|
* \brief Move constructor
|
|
*/
|
|
Connexion(Connexion&& move);
|
|
|
|
/**
|
|
* \brief Closes the connexion
|
|
*/
|
|
void CloseConnection();
|
|
|
|
/**
|
|
* \brief Returns the TCPSocket::Status of the internal socket
|
|
*/
|
|
TCPSocket::Status GetSocketStatus() const {
|
|
return m_Interface.GetStatus();
|
|
}
|
|
|
|
virtual bool UpdateSocket();
|
|
|
|
/**
|
|
* \brief Tries to connect the socket at the specified address and port
|
|
* \return Whether this action was succesfull
|
|
*/
|
|
bool Connect(const std::string& address, std::uint16_t port);
|
|
|
|
/**
|
|
* \brief Sends the protocol::Packet over the network to the remote
|
|
* \param packet The protocol::Packet to send
|
|
*/
|
|
void SendPacket(const protocol::Packet& packet);
|
|
};
|
|
|
|
} // namespace network
|
|
} // namespace blitz
|