Ocean
Loading...
Searching...
No Matches
PackagedConnectionlessClient.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef FACEBOOK_NETWORK_PACKAGED_CONNECTIONLESS_CLIENT_H
9#define FACEBOOK_NETWORK_PACKAGED_CONNECTIONLESS_CLIENT_H
10
15#include "ocean/network/Port.h"
16
17namespace Ocean
18{
19
20namespace Network
21{
22
23
24/**
25 * This class is the base class for all packaged connectionless clients.
26 * @ingroup network
27 */
28class OCEAN_NETWORK_EXPORT PackagedConnectionlessClient :
29 virtual public Client,
30 virtual public PackagedSocket
31{
32 public:
33
34 /**
35 * Sends data to a specified recipient.
36 * @param address Recipient address
37 * @param port Recipient port
38 * @param data The data to send, can be nullptr if 'size == 0'
39 * @param size The size of the data to send in bytes, with range [0, infinity)
40 * @return SR_SUCCEEDED, if succeeded
41 */
42 SocketResult send(const Address4& address, const Port& port, const void* data, const size_t size);
43
44 /**
45 * Sends a message to a specified recipient.
46 * @param address Recipient address
47 * @param port Recipient port
48 * @param message The message to send, must be valid
49 * @return SR_SUCCEEDED, if succeeded
50 */
51 inline SocketResult send(const Address4& address, const Port& port, const std::string& message);
52
53 /**
54 * Returns the maximal size of a single package for this client.
55 * @return Maximal package size in bytes.
56 */
57 inline size_t maximalPackageSize() const;
58
59 protected:
60
61 /**
62 * Creates a new packaged connectionless client object.
63 */
65
66 /**
67 * Destructs a packaged connectionless client object.
68 */
70
71 protected:
72
73 /// Client message counter.
74 MessageId messageCounter_ = 0u;
75
76 /// Maximal package size of this connectionless socket (including the header).
77 size_t maximalPackageSize_ = 0;
78
79 /// Intermediate buffer storing individual parts of a large message.
81};
82
83inline PackagedConnectionlessClient::SocketResult PackagedConnectionlessClient::send(const Address4& address, const Port& port, const std::string& message)
84{
85 ocean_assert(strlen(message.c_str()) == message.length() && message.c_str()[message.length()] == '\0');
86 return send(address, port, message.c_str(), message.length() + 1);
87}
88
93
94}
95
96}
97
98#endif // FACEBOOK_NETWORK_PACKAGED_CONNECTIONLESS_CLIENT_H
This class wraps an address number with 32 bits.
Definition Address4.h:26
This class is the base class for all clients.
Definition Client.h:25
This class is the base class for all packaged connectionless clients.
Definition PackagedConnectionlessClient.h:31
~PackagedConnectionlessClient() override
Destructs a packaged connectionless client object.
size_t maximalPackageSize() const
Returns the maximal size of a single package for this client.
Definition PackagedConnectionlessClient.h:89
PackagedConnectionlessClient()
Creates a new packaged connectionless client object.
Buffer clientPackageBuffer_
Intermediate buffer storing individual parts of a large message.
Definition PackagedConnectionlessClient.h:80
SocketResult send(const Address4 &address, const Port &port, const void *data, const size_t size)
Sends data to a specified recipient.
size_t maximalPackageSize_
Maximal package size of this connectionless socket (including the header).
Definition PackagedConnectionlessClient.h:77
This class is the base class for all packaged sockets.
Definition PackagedSocket.h:31
uint32_t MessageId
Definition of a message id.
Definition PackagedSocket.h:192
This class wraps a port number with 16 bits.
Definition Port.h:26
Address4 address() const
Returns the own address of this socket.
std::vector< uint8_t > Buffer
Definition of a vector holding 8 bit values.
Definition Socket.h:76
SocketResult
Definition of individual result values.
Definition Socket.h:62
Port port() const
Returns the own port of this socket.
The namespace covering the entire Ocean framework.
Definition Accessor.h:15