MCPcopy Create free account
hub / github.com/TelegramMessenger/cocoon / send

Method send

net/TcpConnection.cpp:142–167  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

140}
141
142void TcpConnection::send(td::BufferSlice data) {
143 LOG(DEBUG) << "tcp: sending packet of size " << data.size();
144 auto data_size = td::narrow_cast<td::uint32>(data.size());
145 if (data_size < 4 || data_size > (1 << 24)) {
146 LOG(WARNING) << "tcp: bad packet size " << data_size;
147 fail(td::Status::Error(ton::ErrorCode::protoviolation, "invalid packet length"));
148 return;
149 }
150
151 td::BufferSlice d{data.size() + 8};
152 auto S = d.as_slice();
153
154 S.copy_from(td::Slice(reinterpret_cast<const td::uint8 *>(&data_size), 4));
155 S.remove_prefix(4);
156 S.copy_from(td::Slice(reinterpret_cast<const td::uint8 *>(&out_seqno_), 4));
157 S.remove_prefix(4);
158 S.copy_from(data.as_slice());
159
160 if (socket_pipe_) {
161 socket_pipe_.output_buffer().append(std::move(d));
162 } else {
163 simple_pipe_.output_buffer().append(std::move(d));
164 }
165 out_seqno_++;
166 loop();
167}
168
169void TcpConnection::send_packet(td::BufferSlice data) {
170 send(create_serialize_tl_object<cocoon_api::tcp_packet>(std::move(data)));

Callers

nothing calls this directly

Calls 1

as_sliceMethod · 0.80

Tested by

no test coverage detected