Files
EVEngine/src/modules/network/Channel.h
T
西风逍遥游 4377e062dd feat: zeroerr parameter validation + Doxygen API documentation
Squashed onto current main. Adds src/engine/common/Assert.h (EV_PARAM_CHECK / EV_ASSERT backed by zeroerr), an EVENGINE_ENABLE_ASSERTS option (non-Debug builds strip ZEROERR_NO_ASSERT unless enabled), parameter checks at key entry points, Doxygen comments across headers, Doxyfile + make docs / CMake docs targets, and Windows setup + code conventions in AGENTS.md.
2026-08-19 09:01:12 +08:00

52 lines
1.4 KiB
C++

#pragma once
#include <cstdint>
#include <string>
#include <vector>
namespace eve::data {
class ByteData;
}
namespace eve::network {
class TcpSocket;
class Network;
/**
* @brief Length-prefixed (big-endian uint32) message framing over a TcpSocket.
* sendMsg() writes one framed message; feed() consumes bytes and emits received
* frames as "chmsg" events on the main thread via the Event module.
*/
class Channel {
public:
/** @brief Creates a channel over an existing socket (socket must be non-null). */
explicit Channel(TcpSocket* socket);
~Channel();
/**
* @brief Sends one framed message.
* @param data Payload bytes (must be non-null; size capped at kMaxFrameSize).
* @return True when the frame was handed to the socket.
*/
bool sendMsg(eve::data::ByteData* data);
/** @brief Sends a string payload as one framed message (empty strings are rejected). */
bool sendMsgString(std::string s);
/** @brief The underlying TCP socket, or nullptr. */
TcpSocket* getSocket() const { return socket_; }
/**
* @brief Feeds received bytes into the frame parser.
* Called on the main thread from Network::pump / the emitCompletion path.
*/
void feed(const std::vector<char>& bytes);
private:
TcpSocket* socket_ = nullptr;
std::vector<char> buffer_;
uint32_t pendingLen_ = 0;
bool hasLen_ = false;
};
} // namespace eve::network