]> git.proxmox.com Git - ceph.git/blob - ceph/src/crimson/net/SocketConnection.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / crimson / net / SocketConnection.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2017 Red Hat, Inc
7 *
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
12 *
13 */
14
15 #pragma once
16
17 #include <seastar/core/sharded.hh>
18
19 #include "msg/Policy.h"
20 #include "crimson/common/throttle.h"
21 #include "crimson/net/Connection.h"
22 #include "crimson/net/Socket.h"
23
24 namespace crimson::net {
25
26 class Protocol;
27 class SocketMessenger;
28 class SocketConnection;
29 using SocketConnectionRef = seastar::shared_ptr<SocketConnection>;
30
31 class SocketConnection : public Connection {
32 SocketMessenger& messenger;
33 std::unique_ptr<Protocol> protocol;
34
35 ceph::net::Policy<crimson::common::Throttle> policy;
36
37 /// the seq num of the last transmitted message
38 seq_num_t out_seq = 0;
39 /// the seq num of the last received message
40 seq_num_t in_seq = 0;
41 /// update the seq num of last received message
42 /// @returns true if the @c seq is valid, and @c in_seq is updated,
43 /// false otherwise.
44 bool update_rx_seq(seq_num_t seq);
45
46 // messages to be resent after connection gets reset
47 std::deque<MessageRef> out_q;
48 std::deque<MessageRef> pending_q;
49 // messages sent, but not yet acked by peer
50 std::deque<MessageRef> sent;
51
52 seastar::shard_id shard_id() const;
53
54 public:
55 SocketConnection(SocketMessenger& messenger,
56 ChainedDispatchers& dispatchers,
57 bool is_msgr2);
58 ~SocketConnection() override;
59
60 Messenger* get_messenger() const override;
61
62 bool is_connected() const override;
63
64 #ifdef UNIT_TESTS_BUILT
65 bool is_closed_clean() const override;
66
67 bool is_closed() const override;
68
69 bool peer_wins() const override;
70 #else
71 bool peer_wins() const;
72 #endif
73
74 seastar::future<> send(MessageRef msg) override;
75
76 seastar::future<> keepalive() override;
77
78 void mark_down() override;
79
80 void print(ostream& out) const override;
81
82 /// start a handshake from the client's perspective,
83 /// only call when SocketConnection first construct
84 void start_connect(const entity_addr_t& peer_addr,
85 const entity_name_t& peer_name);
86 /// start a handshake from the server's perspective,
87 /// only call when SocketConnection first construct
88 void start_accept(SocketRef&& socket,
89 const entity_addr_t& peer_addr);
90
91 seastar::future<> close_clean(bool dispatch_reset);
92
93 bool is_server_side() const {
94 return policy.server;
95 }
96
97 bool is_lossy() const {
98 return policy.lossy;
99 }
100
101 friend class Protocol;
102 friend class ProtocolV1;
103 friend class ProtocolV2;
104 };
105
106 } // namespace crimson::net