Ocean
ConnectionlessClient.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_CONNECTIONLESS_CLIENT_H
9 #define FACEBOOK_NETWORK_CONNECTIONLESS_CLIENT_H
10 
11 #include "ocean/network/Network.h"
12 #include "ocean/network/Address4.h"
13 #include "ocean/network/Client.h"
14 #include "ocean/network/Port.h"
15 
16 namespace Ocean
17 {
18 
19 namespace Network
20 {
21 
22 /**
23  * This class is the base class for all connectionless clients.
24  * @ingroup network
25  */
26 class OCEAN_NETWORK_EXPORT ConnectionlessClient : virtual public Client
27 {
28  public:
29 
30  /**
31  * Sends data to a specified recipient.
32  * @param address Recipient address
33  * @param port Recipient port
34  * @param data The data to send, can be nullptr if 'size == 0'
35  * @param size The size of the data to send in bytes, with range [0, infinity)
36  * @return SR_SUCCEEDED, if succeeded
37  */
38  SocketResult send(const Address4& address, const Port& port, const void* data, const size_t size);
39 
40  /**
41  * Sends a message to a specified recipient.
42  * @param address Recipient address
43  * @param port Recipient port
44  * @param message The message to send, must be valid
45  * @return SR_SUCCEEDED, if succeeded
46  */
47  inline SocketResult send(const Address4& address, const Port& port, const std::string& message);
48 
49  protected:
50 
51  /**
52  * Creates a new connectionless client object.
53  */
55 };
56 
57 inline ConnectionlessClient::SocketResult ConnectionlessClient::send(const Address4& address, const Port& port,const std::string& message)
58 {
59  ocean_assert(strlen(message.c_str()) == message.length() && message.c_str()[message.length()] == '\0');
60  return send(address, port, message.c_str(), message.length() + 1);
61 }
62 
63 }
64 
65 }
66 
67 #endif // FACEBOOK_NETWORK_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 connectionless clients.
Definition: ConnectionlessClient.h:27
SocketResult send(const Address4 &address, const Port &port, const void *data, const size_t size)
Sends data to a specified recipient.
ConnectionlessClient()
Creates a new connectionless client object.
This class wraps a port number with 16 bits.
Definition: Port.h:26
Address4 address() const
Returns the own address of this socket.
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