Loading...
Searching...
No Matches
async_replica_client.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#pragma once
21
22#include <boost/asio.hpp>
23
26#include "platform/proto/replica_info.pb.h"
27
28namespace resdb {
29
31 public:
32 AsyncReplicaClient(boost::asio::io_service* io_service, const std::string& ip,
33 int port, bool is_use_long_conn = false);
34 virtual ~AsyncReplicaClient();
35
36 virtual int SendMessage(const std::string& data);
37
38 private:
39 void ReConnect();
40 void OnSendNewMessage();
41 void OnSendMessage();
42 void OnSend();
43
44 private:
46 std::unique_ptr<NetChannel> client_;
47 boost::asio::ip::tcp::socket socket_;
48 boost::asio::ip::tcp::endpoint endpoint_;
49 std::mutex mutex_;
50 std::atomic<bool> in_process_;
51
52 // ===== for async send =====
53 std::unique_ptr<std::string> pending_data_;
54
55 size_t data_size_ = 0; // the size of the data needed to be sent.
56 size_t sending_data_idx_ = 0; // the current pos to be sent in data_ptr.
57 size_t sending_data_size_ = 0; // the size needed to be sent.
58 const char* sending_data_ptr_ = nullptr; // point to the data.
59
60 int status_ = 0; // sending status.
61};
62
63} // namespace resdb
std::string data
virtual int SendMessage(const std::string &data)