Ocean
PackagedTCPServer.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_TCP_SERVER_H
9 #define FACEBOOK_NETWORK_PACKAGED_TCP_SERVER_H
10 
11 #include "ocean/network/Network.h"
14 
15 namespace Ocean
16 {
17 
18 namespace Network
19 {
20 
21 /**
22  * This class implements a TCP server with internal package handling
23  * @ingroup network
24  */
25 class OCEAN_NETWORK_EXPORT PackagedTCPServer :
26  virtual public TCPServer,
27  virtual protected PackagedSocket
28 {
29  protected:
30 
31  /**
32  * Definition of a container
33  */
35  {
36  public:
37 
38  /// The queue holding all memory blocks recently received and not yet process.
40 
41  /// The memory block to be filled.
43 
44  /// The memory block for the package header.
46  };
47 
48  /**
49  * Definition of an unordered map mapping connection ids to ConnectionMemory objects.
50  */
51  typedef std::unordered_map<ConnectionId, ConnectionMemory> ConnectionMemoryMap;
52 
53  public:
54 
55  /**
56  * Creates a new TCP server.
57  */
58  PackagedTCPServer() = default;
59 
60  /**
61  * Destructs a TCP server.
62  */
63  ~PackagedTCPServer() override = default;
64 
65  protected:
66 
67  /**
68  * Internal event function to send data.
69  * @see ConnectionOrientedServer::onSend().
70  */
71  size_t onSend(const ConnectionId connectionId, const void* data, const size_t size) override;
72 
73  /**
74  * Internal event function for received data.
75  * @see ConnectionOrientedServer::onReceived().
76  */
77  void onReceived(const ConnectionId connectionId, const void* data, const size_t size) override;
78 
79  protected:
80 
81  /// The map mapping connection ids to ConnectionMemory objects.
83 };
84 
85 }
86 
87 }
88 
89 #endif // FACEBOOK_NETWORK_PACKAGED_TCP_SERVER_H
unsigned int ConnectionId
Definition of a connection id.
Definition: ConnectionOrientedServer.h:34
This class implements a memory block.
Definition: PackagedSocket.h:38
This class is the base class for all packaged sockets.
Definition: PackagedSocket.h:31
std::queue< MemoryBlock > MemoryBlockQueue
Definition of a queue holding memory blocks.
Definition: PackagedSocket.h:133
Definition of a container.
Definition: PackagedTCPServer.h:35
MemoryBlock currentMemory_
The memory block to be filled.
Definition: PackagedTCPServer.h:42
MemoryBlockQueue memoryQueue_
The queue holding all memory blocks recently received and not yet process.
Definition: PackagedTCPServer.h:39
MemoryBlock currentPackageHeaderMemory_
The memory block for the package header.
Definition: PackagedTCPServer.h:45
This class implements a TCP server with internal package handling.
Definition: PackagedTCPServer.h:28
ConnectionMemoryMap connectionMemoryMap_
The map mapping connection ids to ConnectionMemory objects.
Definition: PackagedTCPServer.h:82
~PackagedTCPServer() override=default
Destructs a TCP server.
void onReceived(const ConnectionId connectionId, const void *data, const size_t size) override
Internal event function for received data.
PackagedTCPServer()=default
Creates a new TCP server.
std::unordered_map< ConnectionId, ConnectionMemory > ConnectionMemoryMap
Definition of an unordered map mapping connection ids to ConnectionMemory objects.
Definition: PackagedTCPServer.h:51
size_t onSend(const ConnectionId connectionId, const void *data, const size_t size) override
Internal event function to send data.
This class implements a TCP server.
Definition: TCPServer.h:25
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15