Coverage Report

Created: 2026-10-28 07:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/Fast-DDS/src/cpp/rtps/transport/TCPSenderResource.hpp
Line
Count
Source
1
// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
#ifndef __TRANSPORT_TCPSENDERRESOURCE_HPP__
16
#define __TRANSPORT_TCPSENDERRESOURCE_HPP__
17
18
#include <fastdds/rtps/common/LocatorsIterator.hpp>
19
#include <fastdds/rtps/transport/SenderResource.hpp>
20
21
#include <rtps/transport/ChainingSenderResource.hpp>
22
#include <rtps/transport/TCPChannelResource.h>
23
#include <rtps/transport/TCPTransportInterface.h>
24
25
namespace eprosima {
26
namespace fastdds {
27
namespace rtps {
28
29
class TCPSenderResource : public SenderResource
30
{
31
public:
32
33
    TCPSenderResource(
34
            TCPTransportInterface& transport,
35
            Locator_t& locator,
36
            const std::shared_ptr<TCPChannelResource>& channel = {})
37
0
        : SenderResource(transport.kind())
38
0
        , locator_(locator)
39
0
        , channel_(channel)
40
0
    {
41
        // Implementation functions are bound to the right transport parameters
42
0
        clean_up = [this, &transport]()
43
0
                {
44
0
                    transport.SenderResourceHasBeenClosed(locator_);
45
0
                };
46
47
0
        send_lambda_ = [this, &transport](
48
0
            const std::vector<NetworkBuffer>& buffers,
49
0
            uint32_t total_bytes,
50
0
            LocatorsIterator* destination_locators_begin,
51
0
            LocatorsIterator* destination_locators_end,
52
0
            const std::chrono::steady_clock::time_point&,
53
0
            int32_t transport_priority) -> bool
54
0
                {
55
0
                    return transport.send(buffers, total_bytes, locator_, destination_locators_begin,
56
0
                                   destination_locators_end, transport_priority);
57
0
                };
58
0
    }
59
60
    virtual ~TCPSenderResource()
61
0
    {
62
0
        if (clean_up)
63
0
        {
64
0
            clean_up();
65
0
        }
66
0
    }
67
68
    Locator_t& locator()
69
0
    {
70
0
        return locator_;
71
0
    }
72
73
    const std::weak_ptr<TCPChannelResource>& channel() const
74
0
    {
75
0
        return channel_;
76
0
    }
77
78
    static TCPSenderResource* cast(
79
            const TransportInterface& transport,
80
            SenderResource* sender_resource)
81
0
    {
82
0
        TCPSenderResource* returned_resource = nullptr;
83
84
0
        if (sender_resource->kind() == transport.kind())
85
0
        {
86
0
            returned_resource = dynamic_cast<TCPSenderResource*>(sender_resource);
87
88
            //! May be chained
89
0
            if (!returned_resource)
90
0
            {
91
0
                auto chaining_sender = dynamic_cast<ChainingSenderResource*>(sender_resource);
92
93
0
                if (chaining_sender)
94
0
                {
95
0
                    returned_resource = dynamic_cast<TCPSenderResource*>(chaining_sender->lower_sender_cast());
96
0
                }
97
0
            }
98
0
        }
99
100
0
        return returned_resource;
101
0
    }
102
103
private:
104
105
    TCPSenderResource() = delete;
106
107
    TCPSenderResource(
108
            const SenderResource&) = delete;
109
110
    TCPSenderResource& operator =(
111
            const SenderResource&) = delete;
112
113
    Locator_t locator_;
114
115
    // Identity of the TCP channel at creation time, used to detect a reconnected channel sharing the same locator.
116
    std::weak_ptr<TCPChannelResource> channel_;
117
};
118
119
} // namespace rtps
120
} // namespace fastdds
121
} // namespace eprosima
122
123
#endif // __TRANSPORT_UDPSENDERRESOURCE_HPP__