]>
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/net/Connection.h"
21 #include "crimson/net/Socket.h"
22 #include "crimson/thread/Throttle.h"
24 namespace crimson::net
{
28 class SocketMessenger
;
29 class SocketConnection
;
30 using SocketConnectionRef
= seastar::shared_ptr
<SocketConnection
>;
32 class SocketConnection
: public Connection
{
33 SocketMessenger
& messenger
;
34 std::unique_ptr
<Protocol
> protocol
;
36 // if acceptor side, ephemeral_port is different from peer_addr.get_port();
37 // if connector side, ephemeral_port is different from my_addr.get_port().
43 side_t side
= side_t::none
;
44 uint16_t ephemeral_port
= 0;
45 void set_ephemeral_port(uint16_t port
, side_t _side
) {
46 ephemeral_port
= port
;
50 ceph::net::Policy
<crimson::thread::Throttle
> policy
;
52 /// the seq num of the last transmitted message
53 seq_num_t out_seq
= 0;
54 /// the seq num of the last received message
56 /// update the seq num of last received message
57 /// @returns true if the @c seq is valid, and @c in_seq is updated,
59 bool update_rx_seq(seq_num_t seq
);
61 // messages to be resent after connection gets reset
62 std::deque
<MessageRef
> out_q
;
63 std::deque
<MessageRef
> pending_q
;
64 // messages sent, but not yet acked by peer
65 std::deque
<MessageRef
> sent
;
67 seastar::shard_id
shard_id() const;
70 SocketConnection(SocketMessenger
& messenger
,
71 Dispatcher
& dispatcher
,
73 ~SocketConnection() override
;
75 Messenger
* get_messenger() const override
;
77 bool is_connected() const override
;
79 #ifdef UNIT_TESTS_BUILT
80 bool is_closed() const override
;
82 bool peer_wins() const override
;
84 bool peer_wins() const;
87 seastar::future
<> send(MessageRef msg
) override
;
89 seastar::future
<> keepalive() override
;
91 seastar::future
<> close() override
;
93 void print(ostream
& out
) const override
;
95 /// start a handshake from the client's perspective,
96 /// only call when SocketConnection first construct
97 void start_connect(const entity_addr_t
& peer_addr
,
98 const entity_type_t
& peer_type
);
99 /// start a handshake from the server's perspective,
100 /// only call when SocketConnection first construct
101 void start_accept(SocketRef
&& socket
,
102 const entity_addr_t
& peer_addr
);
104 bool is_server_side() const {
105 return policy
.server
;
108 bool is_lossy() const {
112 friend class Protocol
;
113 friend class ProtocolV1
;
114 friend class ProtocolV2
;
117 } // namespace crimson::net