Skip to content

Commit

Permalink
delete chuncked api
Browse files Browse the repository at this point in the history
  • Loading branch information
helintongh committed Nov 1, 2023
1 parent d90680f commit d94980c
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 60 deletions.
50 changes: 0 additions & 50 deletions include/cinatra/coro_http_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,56 +384,6 @@ class coro_http_client : public std::enable_shared_from_this<coro_http_client> {
co_return data;
}

async_simple::coro::Lazy<resp_data> async_send_ws_chuncked(
std::string msg, uint64_t max_part_size, bool need_mask = true,
opcode op = opcode::text) {
resp_data data{};

websocket ws{};
if (op == opcode::close) {
msg = ws.format_close_payload(close_code::normal, msg.data(), msg.size());
}

std::string total_data = ws.encode_frame(msg, op, need_mask);
bool is_first_part = true;
total_data.append(msg);
size_t msg_length = total_data.length();
int msg_offset = 0;

while (msg_length > 0) {
std::cout << msg_length << std::endl;
if (msg_length > max_part_size) {
std::string part(total_data.data() + msg_offset, max_part_size);
std::vector<asio::const_buffer> buffers{
asio::buffer(part.data(), max_part_size)};
auto [ec, _] = co_await async_write(buffers);
if (ec) {
data.net_err = ec;
data.status = 404;
co_return data;
}
msg_length -= max_part_size;
msg_offset += max_part_size;
}
else {
std::string last_part(total_data.data() + msg_offset, msg_length);
std::vector<asio::const_buffer> buffers{
asio::buffer(last_part.data(), last_part.size())};
auto [ec, _] = co_await async_write(buffers);
if (ec) {
data.net_err = ec;
data.status = 404;
co_return data;
}

msg_offset += msg_length;
msg_length = 0;
}
}
data.eof = true;
co_return data;
}

async_simple::coro::Lazy<resp_data> async_send_ws_close(
std::string msg = "") {
return async_send_ws(std::move(msg), false, opcode::close);
Expand Down
10 changes: 0 additions & 10 deletions lang/coro_http_client_introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -477,16 +477,6 @@ async_simple::coro::Lazy<resp_data> async_send_ws(std::string msg,
async_simple::coro::Lazy<resp_data> async_send_ws_multiple(std::string msg,
bool need_mask = true,
opcode op = opcode::text);

/// 分段形式发送websocket 数据
/// \param msg 要发送的websocket 数据
/// \param max_part_size 每段发送的数据最大大小
/// \param need_mask 是否需要对数据进行mask,默认会mask
/// \param op opcode 一般为text、binary或 close 等类型
async_simple::coro::Lazy<resp_data> async_send_ws_chuncked(std::string msg,
uint64_t max_part_size,
bool need_mask = true,
opcode op = opcode::text);
```
websocket 例子:
Expand Down

0 comments on commit d94980c

Please sign in to comment.