]>
git.proxmox.com Git - ceph.git/blob - 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
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2017 Red Hat, Inc
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.
17 #include <seastar/core/sharded.hh>
19 #include "msg/Policy.h"
20 #include "crimson/common/throttle.h"
21 #include "crimson/net/Connection.h"
22 #include "crimson/net/Socket.h"
24 namespace crimson::net
{
27 class SocketMessenger
;
28 class SocketConnection
;
29 using SocketConnectionRef
= seastar::shared_ptr
<SocketConnection
>;
31 class SocketConnection
: public Connection
{
32 SocketMessenger
& messenger
;
33 std::unique_ptr
<Protocol
> protocol
;
35 ceph::net::Policy
<crimson::common::Throttle
> policy
;
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
41 /// update the seq num of last received message
42 /// @returns true if the @c seq is valid, and @c in_seq is updated,
44 bool update_rx_seq(seq_num_t seq
);
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
;
52 seastar::shard_id
shard_id() const;
55 SocketConnection(SocketMessenger
& messenger
,
56 ChainedDispatchers
& dispatchers
,
58 ~SocketConnection() override
;
60 Messenger
* get_messenger() const override
;
62 bool is_connected() const override
;
64 #ifdef UNIT_TESTS_BUILT
65 bool is_closed_clean() const override
;
67 bool is_closed() const override
;
69 bool peer_wins() const override
;
71 bool peer_wins() const;
74 seastar::future
<> send(MessageRef msg
) override
;
76 seastar::future
<> keepalive() override
;
78 void mark_down() override
;
80 void print(ostream
& out
) const override
;
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
);
91 seastar::future
<> close_clean(bool dispatch_reset
);
93 bool is_server_side() const {
97 bool is_lossy() const {
101 friend class Protocol
;
102 friend class ProtocolV1
;
103 friend class ProtocolV2
;
106 } // namespace crimson::net