75 lines
2.4 KiB
C++
75 lines
2.4 KiB
C++
#ifndef CMVR_ES_QUIC_EDGE_QUIC_TRANSPORT_H
|
|
#define CMVR_ES_QUIC_EDGE_QUIC_TRANSPORT_H
|
|
|
|
#include <chrono>
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <memory>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "cmvr/config/quic_edge_config/quic_edge_config.pb.h"
|
|
#include "service/quic_edge/include/quic_edge_types.h"
|
|
|
|
namespace cmvr::quic_edge {
|
|
|
|
enum class TransportSendResult {
|
|
QUEUED,
|
|
WOULD_BLOCK,
|
|
DISCONNECTED,
|
|
ERROR,
|
|
};
|
|
|
|
enum class TransportReceiveResult {
|
|
DATA,
|
|
TIMEOUT,
|
|
DISCONNECTED,
|
|
ERROR,
|
|
};
|
|
|
|
class QuicTransport {
|
|
public:
|
|
virtual ~QuicTransport() = default;
|
|
|
|
virtual bool connect(const config::QuicEdgeConfig& config,
|
|
std::chrono::milliseconds timeout,
|
|
std::string* error) = 0;
|
|
virtual void disconnect() = 0;
|
|
virtual bool isConnected() const = 0;
|
|
virtual std::size_t maximumDatagramBytes() const = 0;
|
|
virtual std::size_t maximumDatagramBatchPackets() const = 0;
|
|
|
|
// QUEUED means ownership was accepted. WOULD_BLOCK and synchronous ERROR
|
|
// mean no bytes were accepted, so the caller may safely retry the complete
|
|
// framed message. DISCONNECTED means the connection is no longer usable.
|
|
virtual TransportSendResult sendControl(
|
|
std::vector<std::uint8_t> framed_message,
|
|
std::string* error) = 0;
|
|
|
|
// Returns one raw byte chunk from the reliable control stream. QUIC stream
|
|
// callback boundaries are not message boundaries; callers must feed all
|
|
// DATA chunks into their framing decoder in order.
|
|
//
|
|
// The default implementation reports DISCONNECTED so existing transports
|
|
// that only support sending remain source-compatible.
|
|
virtual TransportReceiveResult receiveControl(
|
|
std::vector<std::uint8_t>* chunk,
|
|
std::chrono::milliseconds timeout,
|
|
std::string* error);
|
|
|
|
// Local admission is atomic for the complete batch. A native QUIC API may
|
|
// still fail after accepting earlier fragments; in that case the transport
|
|
// must reset the connection so the receiver discards the partial session.
|
|
virtual TransportSendResult sendDatagramBatch(
|
|
std::vector<DatagramPacket> packets,
|
|
std::string* error) = 0;
|
|
};
|
|
|
|
bool hasCompiledMsQuicSupport();
|
|
std::unique_ptr<QuicTransport> createDefaultQuicTransport(
|
|
std::size_t send_queue_depth);
|
|
|
|
} // namespace cmvr::quic_edge
|
|
|
|
#endif // CMVR_ES_QUIC_EDGE_QUIC_TRANSPORT_H
|