23static constexpr uint16_t MAX_HANDSHAKE_SIZE = 128;
27static constexpr uint16_t MAX_MESSAGE_SIZE = 8192;
29static constexpr uint16_t MAX_MESSAGE_SIZE = 32768;
34static constexpr size_t MAX_MESSAGES_PER_BATCH = 34;
36class ProtoWriteBuffer;
39static constexpr size_t CLIENT_INFO_NAME_MAX_LEN = 32;
95 const char *
get_peername_to(std::span<char, socket::SOCKADDR_STR_LEN> buf)
const;
112 int err = this->
socket_->close();
118 int err = this->
socket_->shutdown(how);
121 if (how == SHUT_RDWR) {
141 if (!is_log_message) {
178 std::vector<uint8_t>().swap(this->
rx_buf_);
185 std::unique_ptr<uint8_t[]>
data;
205 template<
typename StateEnum>
207 const std::string &info, StateEnum &
state, StateEnum failed_state);
232 std::array<std::unique_ptr<SendBuffer>, API_MAX_SEND_QUEUE>
tx_buf_;
255 int val = enable ? 1 : 0;
256 this->socket_->setsockopt(IPPROTO_TCP, TCP_NODELAY, &
val,
sizeof(
int));
const char * get_client_name() const
APIError handle_socket_read_result_(ssize_t received)
std::vector< uint8_t > rx_buf_
APIError write_raw_(const struct iovec *iov, int iovcnt, socket::Socket *socket, std::vector< uint8_t > &tx_buf, const std::string &info, StateEnum &state, StateEnum failed_state)
virtual APIError read_packet(ReadPacketBuffer *buffer)=0
std::array< std::unique_ptr< SendBuffer >, API_MAX_SEND_QUEUE > tx_buf_
bool is_socket_ready() const
void buffer_data_from_iov_(const struct iovec *iov, int iovcnt, uint16_t total_write_len, uint16_t offset)
uint8_t frame_header_padding() const
int getpeername(struct sockaddr *addr, socklen_t *addrlen)
virtual APIError write_protobuf_messages(ProtoWriteBuffer buffer, std::span< const MessageInfo > messages)=0
APIError shutdown(int how)
APIError handle_socket_write_error_()
uint8_t frame_header_padding_
virtual APIError init()=0
APIFrameHelper(std::unique_ptr< socket::Socket > socket)
const char * get_peername_to(std::span< char, socket::SOCKADDR_STR_LEN > buf) const
APIError try_send_tx_buf_()
std::unique_ptr< socket::Socket > socket_
uint8_t frame_footer_size() const
char client_name_[CLIENT_INFO_NAME_MAX_LEN]
uint8_t frame_footer_size_
void set_client_name(const char *name, size_t len)
virtual APIError write_protobuf_packet(uint8_t type, ProtoWriteBuffer buffer)=0
APIError write_raw_(const struct iovec *iov, int iovcnt, uint16_t total_write_len)
static constexpr int8_t NODELAY_ON
void set_nodelay_for_message(bool is_log_message)
bool can_write_without_blocking()
static constexpr int8_t LOG_NAGLE_COUNT
void set_nodelay_raw_(bool enable)
virtual ~APIFrameHelper()=default
const LogString * api_error_to_logstr(APIError err)
@ HANDSHAKESTATE_READ_FAILED
@ HANDSHAKESTATE_BAD_STATE
@ HANDSHAKESTATE_SPLIT_FAILED
@ BAD_HANDSHAKE_PACKET_LEN
@ BAD_HANDSHAKE_ERROR_BYTE
@ HANDSHAKESTATE_SETUP_FAILED
@ CIPHERSTATE_ENCRYPT_FAILED
@ CIPHERSTATE_DECRYPT_FAILED
@ HANDSHAKESTATE_WRITE_FAILED
uint16_t remaining() const
const uint8_t * current_data() const
std::unique_ptr< uint8_t[]> data
MessageInfo(uint8_t type, uint16_t off, uint16_t size)