]> git.proxmox.com Git - ceph.git/blame - ceph/src/crimson/net/SocketConnection.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / crimson / net / SocketConnection.h
CommitLineData
11fdf7f2
TL
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
11fdf7f2
TL
17#include <seastar/core/sharded.hh>
18
19#include "msg/Policy.h"
f67539c2 20#include "crimson/common/throttle.h"
9f95a23c
TL
21#include "crimson/net/Connection.h"
22#include "crimson/net/Socket.h"
11fdf7f2 23
9f95a23c 24namespace crimson::net {
11fdf7f2 25
9f95a23c 26class Protocol;
11fdf7f2
TL
27class SocketMessenger;
28class SocketConnection;
29using SocketConnectionRef = seastar::shared_ptr<SocketConnection>;
30
31class SocketConnection : public Connection {
32 SocketMessenger& messenger;
9f95a23c 33 std::unique_ptr<Protocol> protocol;
11fdf7f2 34
f67539c2 35 ceph::net::Policy<crimson::common::Throttle> policy;
9f95a23c 36
11fdf7f2
TL
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
11fdf7f2 46 // messages to be resent after connection gets reset
9f95a23c
TL
47 std::deque<MessageRef> out_q;
48 std::deque<MessageRef> pending_q;
11fdf7f2 49 // messages sent, but not yet acked by peer
9f95a23c 50 std::deque<MessageRef> sent;
11fdf7f2 51
9f95a23c 52 seastar::shard_id shard_id() const;
11fdf7f2
TL
53
54 public:
55 SocketConnection(SocketMessenger& messenger,
f67539c2 56 ChainedDispatchers& dispatchers,
9f95a23c
TL
57 bool is_msgr2);
58 ~SocketConnection() override;
11fdf7f2
TL
59
60 Messenger* get_messenger() const override;
61
9f95a23c 62 bool is_connected() const override;
11fdf7f2 63
9f95a23c 64#ifdef UNIT_TESTS_BUILT
f67539c2
TL
65 bool is_closed_clean() const override;
66
9f95a23c
TL
67 bool is_closed() const override;
68
69 bool peer_wins() const override;
70#else
71 bool peer_wins() const;
72#endif
11fdf7f2
TL
73
74 seastar::future<> send(MessageRef msg) override;
75
76 seastar::future<> keepalive() override;
77
f67539c2 78 void mark_down() override;
11fdf7f2 79
11fdf7f2
TL
80 void print(ostream& out) const override;
81
11fdf7f2
TL
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,
f67539c2 85 const entity_name_t& peer_name);
11fdf7f2
TL
86 /// start a handshake from the server's perspective,
87 /// only call when SocketConnection first construct
9f95a23c 88 void start_accept(SocketRef&& socket,
11fdf7f2
TL
89 const entity_addr_t& peer_addr);
90
f67539c2
TL
91 seastar::future<> close_clean(bool dispatch_reset);
92
11fdf7f2
TL
93 bool is_server_side() const {
94 return policy.server;
95 }
9f95a23c 96
11fdf7f2
TL
97 bool is_lossy() const {
98 return policy.lossy;
99 }
100
9f95a23c
TL
101 friend class Protocol;
102 friend class ProtocolV1;
103 friend class ProtocolV2;
11fdf7f2
TL
104};
105
9f95a23c 106} // namespace crimson::net